| 1 | package be.nikiroo.jvcard.tui; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import com.googlecode.lanterna.TerminalSize; |
| 6 | import com.googlecode.lanterna.TextColor; |
| 7 | import com.googlecode.lanterna.gui2.DefaultWindowManager; |
| 8 | import com.googlecode.lanterna.gui2.EmptySpace; |
| 9 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; |
| 10 | import com.googlecode.lanterna.gui2.Window; |
| 11 | import com.googlecode.lanterna.screen.Screen; |
| 12 | import com.googlecode.lanterna.screen.TerminalScreen; |
| 13 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; |
| 14 | import com.googlecode.lanterna.terminal.ResizeListener; |
| 15 | import com.googlecode.lanterna.terminal.Terminal; |
| 16 | |
| 17 | /* |
| 18 | * |
| 19 | * Change in Lanterna 3.0.0-beta2 (issue and fix reported to GitHub): |
| 20 | * |
| 21 | * java.lang.StringIndexOutOfBoundsException: String index out of range: 83 |
| 22 | * at java.lang.String.charAt(String.java:686) |
| 23 | * at com.googlecode.lanterna.TerminalTextUtils.getWordWrappedText(TerminalTextUtils.java:237) |
| 24 | * |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | public class TuiLauncher { |
| 29 | public static void start(Boolean textMode, Window win) throws IOException { |
| 30 | Terminal terminal = null; |
| 31 | |
| 32 | DefaultTerminalFactory factory = new DefaultTerminalFactory(); |
| 33 | if (textMode == null) { |
| 34 | terminal = factory.createTerminal(); |
| 35 | } else if (textMode) { |
| 36 | factory.setForceTextTerminal(true); |
| 37 | terminal = factory.createTerminal(); |
| 38 | } else { |
| 39 | terminal = factory.createTerminalEmulator(); |
| 40 | } |
| 41 | |
| 42 | if (win instanceof MainWindow) { |
| 43 | MainWindow mwin = (MainWindow) win; |
| 44 | mwin.refresh(terminal.getTerminalSize()); |
| 45 | terminal.addResizeListener(new ResizeListener() { |
| 46 | @Override |
| 47 | public void onResized(Terminal terminal, TerminalSize newSize) { |
| 48 | mwin.refresh(newSize); |
| 49 | } |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | Screen screen = new TerminalScreen(terminal); |
| 54 | screen.startScreen(); |
| 55 | |
| 56 | // Create gui and start gui |
| 57 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, |
| 58 | new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); |
| 59 | gui.addWindowAndWait(win); |
| 60 | |
| 61 | screen.stopScreen(); |
| 62 | } |
| 63 | } |