├── .gitattributes ├── jitpack.yml ├── RELEASE.txt ├── .gitignore ├── docs ├── examples │ └── gui │ │ ├── screenshots │ │ ├── buttons.png │ │ ├── labels.png │ │ ├── menus.png │ │ ├── panels.png │ │ ├── tables.png │ │ ├── combo_box.png │ │ ├── calculator.png │ │ ├── check_boxes.png │ │ ├── dir_dialogs.png │ │ ├── file_dialogs.png │ │ ├── hello_world.png │ │ ├── radio_boxes.png │ │ ├── text_boxes.png │ │ ├── action_list_box.png │ │ ├── message_dialogs.png │ │ ├── action_list_dialogs.png │ │ ├── combo_box_activated.png │ │ ├── text_input_dialogs.png │ │ └── multiline_input_dialogs.png │ │ ├── labels.md │ │ ├── action_list_box.md │ │ ├── buttons.md │ │ ├── radio_boxes.md │ │ ├── component_sizing.md │ │ ├── check_boxes.md │ │ ├── tables.md │ │ ├── file_dialogs.md │ │ ├── dir_dialogs.md │ │ ├── combo_boxes.md │ │ ├── windows.md │ │ ├── action_list_dialogs.md │ │ ├── panels.md │ │ ├── message_dialogs.md │ │ ├── text_boxes.md │ │ ├── hello_world.md │ │ ├── text_input_dialogs.md │ │ └── layout_managers.md ├── GUIGuideMisc.md ├── GUIGuideDialogs.md ├── GUIGuideComponents.md ├── using-gui.md ├── Screenshots.md ├── Maven.md └── GUIGuideStartTheGUI.md ├── src ├── main │ ├── resources │ │ └── multilang │ │ │ ├── lanterna-ui_zh_CN.properties │ │ │ ├── lanterna-ui_zh_TW.properties │ │ │ ├── lanterna-ui_ja.properties │ │ │ ├── lanterna-ui.properties │ │ │ ├── lanterna-ui_da.properties │ │ │ ├── lanterna-ui_nb.properties │ │ │ ├── lanterna-ui_nn.properties │ │ │ ├── lanterna-ui_no.properties │ │ │ ├── lanterna-ui_fi.properties │ │ │ ├── lanterna-ui_sv.properties │ │ │ ├── lanterna-ui_de.properties │ │ │ ├── lanterna-ui_es.properties │ │ │ └── lanterna-ui_fr.properties │ ├── java │ │ └── com │ │ │ └── googlecode │ │ │ └── lanterna │ │ │ ├── gui2 │ │ │ ├── LayoutData.java │ │ │ ├── Direction.java │ │ │ ├── TextGUIThreadFactory.java │ │ │ ├── dialogs │ │ │ │ ├── TextInputDialogResultValidator.java │ │ │ │ ├── MessageDialogButton.java │ │ │ │ └── DialogWindow.java │ │ │ ├── InteractableRenderer.java │ │ │ ├── BasicWindow.java │ │ │ ├── Composite.java │ │ │ ├── InputFilter.java │ │ │ ├── EmptyWindowDecorationRenderer.java │ │ │ ├── TextGUIElement.java │ │ │ ├── WindowListenerAdapter.java │ │ │ ├── WindowPostRenderer.java │ │ │ ├── table │ │ │ │ ├── DefaultTableHeaderRenderer.java │ │ │ │ ├── TableCellBorderStyle.java │ │ │ │ ├── TableHeaderRenderer.java │ │ │ │ └── TableCellRenderer.java │ │ │ ├── WindowListener.java │ │ │ ├── GUIBackdrop.java │ │ │ ├── Border.java │ │ │ ├── AbsoluteLayout.java │ │ │ ├── ComponentRenderer.java │ │ │ └── TODO.txt │ │ │ ├── terminal │ │ │ ├── win32 │ │ │ │ ├── Wincon.java │ │ │ │ └── WindowsConsoleOutputStream.java │ │ │ ├── swing │ │ │ │ ├── TerminalEmulatorAutoCloseTrigger.java │ │ │ │ └── TerminalInputMethodRequests.java │ │ │ ├── TerminalFactory.java │ │ │ ├── IOSafeExtendedTerminal.java │ │ │ ├── ansi │ │ │ │ ├── UnixTerminalSizeQuerier.java │ │ │ │ └── FixedTerminalSizeProvider.java │ │ │ ├── TerminalResizeListener.java │ │ │ └── virtual │ │ │ │ └── VirtualTerminalListener.java │ │ │ ├── input │ │ │ ├── MouseActionType.java │ │ │ ├── AltAndCharacterPattern.java │ │ │ ├── ScreenInfoAction.java │ │ │ ├── KeyDecodingProfile.java │ │ │ ├── NormalCharacterPattern.java │ │ │ ├── CtrlAndCharacterPattern.java │ │ │ └── InputProvider.java │ │ │ ├── graphics │ │ │ ├── ThemedTextGraphics.java │ │ │ ├── ShapeRenderer.java │ │ │ ├── ThemeStyle.java │ │ │ └── Scrollable.java │ │ │ ├── bundle │ │ │ └── LocalizedUIBundle.java │ │ │ └── screen │ │ │ ├── ScreenTranslator.java │ │ │ ├── WrapBehaviour.java │ │ │ └── ScreenTextGraphics.java │ └── java9 │ │ └── module-info.java ├── test │ └── java │ │ └── com │ │ └── googlecode │ │ └── lanterna │ │ ├── issue │ │ ├── Issue254.java │ │ ├── Issue385.java │ │ ├── Issue361.java │ │ ├── Issue376.java │ │ ├── Issue359.java │ │ ├── Issue313.java │ │ ├── Issue334.java │ │ ├── Issue312.java │ │ ├── Issue358.java │ │ ├── Issue78.java │ │ ├── Issue305.java │ │ ├── Issue387.java │ │ ├── Issue460.java │ │ ├── Issue374.java │ │ ├── Issue446.java │ │ ├── Issue249.java │ │ ├── Issue392.java │ │ ├── Issue95.java │ │ ├── Issue150.java │ │ ├── Issue274.java │ │ └── IssueX.java │ │ ├── TextColorTest.java │ │ ├── terminal │ │ ├── UnicodeTest.java │ │ ├── EmojiTest.java │ │ ├── EnqTest.java │ │ ├── RawTerminalTest.java │ │ ├── ResetAllTest.java │ │ ├── BlinkTest.java │ │ ├── InitialSizeTest.java │ │ └── NewSwingTerminalTest.form │ │ ├── TestAllCodes.java │ │ ├── TextCharacterTest.java │ │ ├── Environment.java │ │ ├── TestShellCommand.java │ │ ├── graphics │ │ └── RedundantThemeDeclarationsTest.java │ │ ├── gui2 │ │ ├── WindowManagerTest.java │ │ └── MultiButtonTest.java │ │ ├── bundle │ │ └── DefaultThemeTest.java │ │ ├── TestUtils.java │ │ └── TestACS.java └── examples │ └── java │ └── com │ └── googlecode │ └── lanterna │ └── examples │ ├── OutputString.java │ ├── OutputChar.java │ └── DrawRectangle.java ├── licenseheader.txt └── native-integration ├── pom.xml └── src └── main └── java └── com └── googlecode └── lanterna └── terminal └── Wincon.java /.gitattributes: -------------------------------------------------------------------------------- 1 | *.java eol=lf 2 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk9 3 | -------------------------------------------------------------------------------- /RELEASE.txt: -------------------------------------------------------------------------------- 1 | mvn release:clean release:prepare -Prelease 2 | mvn release:perform -Prelease 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | .idea/ 5 | nb-configuration.xml 6 | target/ 7 | *.iml 8 | -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/buttons.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/labels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/labels.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/menus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/menus.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/panels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/panels.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/tables.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/combo_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/combo_box.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/calculator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/calculator.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/check_boxes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/check_boxes.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/dir_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/dir_dialogs.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/file_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/file_dialogs.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/hello_world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/hello_world.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/radio_boxes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/radio_boxes.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/text_boxes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/text_boxes.png -------------------------------------------------------------------------------- /docs/GUIGuideMisc.md: -------------------------------------------------------------------------------- 1 | # Misc 2 | **WARNING: This page has not yet been updated to Lanterna 3 and is out-of-date** 3 | * Multi-threading 4 | * Themes -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/action_list_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/action_list_box.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/message_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/message_dialogs.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/action_list_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/action_list_dialogs.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/combo_box_activated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/combo_box_activated.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/text_input_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/text_input_dialogs.png -------------------------------------------------------------------------------- /docs/examples/gui/screenshots/multiline_input_dialogs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabe02/lanterna/HEAD/docs/examples/gui/screenshots/multiline_input_dialogs.png -------------------------------------------------------------------------------- /docs/GUIGuideDialogs.md: -------------------------------------------------------------------------------- 1 | # Built-in dialogs 2 | **WARNING: This page has not yet been updated to Lanterna 3 and is out-of-date** 3 | * ActionListDialog 4 | * ListSelectDialog 5 | * MessageBox 6 | * TextInputDialog 7 | * WaitingDialog -------------------------------------------------------------------------------- /docs/GUIGuideComponents.md: -------------------------------------------------------------------------------- 1 | # Components 2 | **WARNING: This page has not yet been updated to Lanterna 3 and is out-of-date** 3 | * ActionListBox 4 | * Button 5 | * CheckBox 6 | * CheckBoxList 7 | * Label 8 | * Panel 9 | * PasswordBox 10 | * Table 11 | * TextBox -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_zh_CN.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=确定 2 | short.label.cancel=取消 3 | short.label.yes=是 4 | short.label.no=否 5 | short.label.close=关闭 6 | short.label.abort=中止 7 | short.label.ignore=忽略 8 | short.label.retry=重试 9 | short.label.continue=继续 10 | short.label.open=打开 11 | short.label.save=保存 -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_zh_TW.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=確定 2 | short.label.cancel=取消 3 | short.label.yes=是 4 | short.label.no=否 5 | short.label.close=關閉 6 | short.label.abort=中止 7 | short.label.ignore=忽略 8 | short.label.retry=重試 9 | short.label.continue=繼續 10 | short.label.open=打開 11 | short.label.save=保存 -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_ja.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=キャンセル 3 | short.label.yes=はい 4 | short.label.no=いいえ 5 | short.label.close=閉じる 6 | short.label.abort=中断 7 | short.label.ignore=無視 8 | short.label.retry=再試行 9 | short.label.continue=続ける 10 | short.label.open=オープン 11 | short.label.save=保存 -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Cancel 3 | short.label.yes=Yes 4 | short.label.no=No 5 | short.label.close=Close 6 | short.label.abort=Abort 7 | short.label.ignore=Ignore 8 | short.label.retry=Retry 9 | short.label.continue=Continue 10 | short.label.open=Open 11 | short.label.save=Save -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_da.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Annullér 3 | short.label.yes=Ja 4 | short.label.no=Nej 5 | short.label.close=Luk 6 | short.label.abort=Afbryd 7 | short.label.ignore=Ignorér 8 | short.label.retry=Prøv igen 9 | short.label.continue=Fortsæt 10 | short.label.open=Åbn 11 | short.label.save=Gem -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_nb.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Avbryt 3 | short.label.yes=Ja 4 | short.label.no=Nei 5 | short.label.close=Lukk 6 | short.label.abort=Avbryt 7 | short.label.ignore=Ignorer 8 | short.label.retry=Prøv igjen 9 | short.label.continue=Fortsett 10 | short.label.open=Åpne 11 | short.label.save=Lagre -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_nn.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Avbryt 3 | short.label.yes=Ja 4 | short.label.no=Nei 5 | short.label.close=Lukk 6 | short.label.abort=Avbryt 7 | short.label.ignore=Ignorer 8 | short.label.retry=Prøv igjen 9 | short.label.continue=Fortsett 10 | short.label.open=Åpne 11 | short.label.save=Lagre -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_no.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Avbryt 3 | short.label.yes=Ja 4 | short.label.no=Nei 5 | short.label.close=Lukk 6 | short.label.abort=Avbryt 7 | short.label.ignore=Ignorer 8 | short.label.retry=Prøv igjen 9 | short.label.continue=Fortsett 10 | short.label.open=Åpne 11 | short.label.save=Lagre -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_fi.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Peru 3 | short.label.yes=Kyllä 4 | short.label.no=Ei 5 | short.label.close=Sulje 6 | short.label.abort=Keskeytä 7 | short.label.ignore=Ohita 8 | short.label.retry=Yritä uudelleen 9 | short.label.continue=Jatka 10 | short.label.open=Avaa 11 | short.label.save=Tallenna -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_sv.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=OK 2 | short.label.cancel=Avbryt 3 | short.label.yes=Ja 4 | short.label.no=Nej 5 | short.label.close=Stäng 6 | short.label.abort=Avbryt 7 | short.label.ignore=Ignorera 8 | short.label.retry=Försök igen 9 | short.label.continue=Fortsätt 10 | short.label.open=Öppna 11 | short.label.save=Spara -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_de.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=Ok 2 | short.label.cancel=Abbrechen 3 | short.label.yes=Ja 4 | short.label.no=Nein 5 | short.label.close=Schließen 6 | short.label.abort=Beenden 7 | short.label.ignore=Ignorieren 8 | short.label.retry=Wiederholen 9 | short.label.continue=Weiter 10 | short.label.open=Öffnen 11 | short.label.save=Speichern -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_es.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=Aceptar 2 | short.label.cancel=Cancelar 3 | short.label.yes=S\u00ed 4 | short.label.no=No 5 | short.label.close=Cerrar 6 | short.label.abort=Abortar 7 | short.label.ignore=Ignorar 8 | short.label.retry=Reintentar 9 | short.label.continue=Continuar 10 | short.label.open=Abrir 11 | short.label.save=Salvar -------------------------------------------------------------------------------- /src/main/resources/multilang/lanterna-ui_fr.properties: -------------------------------------------------------------------------------- 1 | short.label.ok=Ok 2 | short.label.cancel=Annuler 3 | short.label.yes=Oui 4 | short.label.no=Non 5 | short.label.close=Fermer 6 | short.label.abort=Abandonner 7 | short.label.ignore=Ignorer 8 | short.label.retry=Réessayer 9 | short.label.continue=Continuer 10 | short.label.open=Ouvrir 11 | short.label.save=Enregistrer -------------------------------------------------------------------------------- /docs/using-gui.md: -------------------------------------------------------------------------------- 1 | # Text GUI 2 | _Please note: You should read the [Buffered screen API](using-screen.md) guide before you start reading this guide_ 3 | 4 | The guide on how to use the GUI is a bit too long for one page so it's been split up: 5 | * [Start the GUI](GUIGuideStartTheGUI.md) 6 | * [Basic windows](GUIGuideWindows.md) 7 | * [Components](GUIGuideComponents.md) 8 | * [Built-in dialogs](GUIGuideDialogs.md) 9 | * [Misc](GUIGuideMisc.md) -------------------------------------------------------------------------------- /docs/examples/gui/labels.md: -------------------------------------------------------------------------------- 1 | Labels 2 | --- 3 | 4 | Labels, as you may expect, are simple labels. 5 | 6 | To create a simple label: 7 | 8 | ``` 9 | Label label = new Label("Here is a label"); 10 | ``` 11 | 12 | As with many other components, you can add a `Label` to a `Panel` after instantiation: 13 | 14 | ``` 15 | Panel panel = new Panel(); 16 | new Label("Surname").addTo(panel); 17 | ``` 18 | 19 | ### Screenshot 20 | 21 | ![](screenshots/labels.png) -------------------------------------------------------------------------------- /docs/Screenshots.md: -------------------------------------------------------------------------------- 1 | Windows 10 running Lanterna in the Swing terminal emulator: 2 | ![http://mabe02.github.io/lanterna/resources/screenshots/win10-screenshot.png](http://mabe02.github.io/lanterna/resources/screenshots/win10-screenshot.png) 3 | 4 | Xubuntu running Lanterna in the Swing terminal emulator: 5 | TBD 6 | 7 | Mac OS X running Lanterna in the Swing terminal emulator: 8 | TBD 9 | 10 | Xubuntu running Lanterna in the Swing terminal emulator: 11 | TBD 12 | 13 | Xubuntu running Lanterna in the Swing terminal emulator: 14 | TBD -------------------------------------------------------------------------------- /docs/examples/gui/action_list_box.md: -------------------------------------------------------------------------------- 1 | Action List Box 2 | --- 3 | 4 | An action list box stores a list of actions the user can made. Each action runs within its own thread. 5 | 6 | To create an action list: 7 | 8 | ``` 9 | TerminalSize size = new TerminalSize(14, 10); 10 | ActionListBox actionListBox = new ActionListBox(size); 11 | ``` 12 | 13 | To add an action to the `ActionListBox`: 14 | 15 | ``` 16 | actionListBox.addItem(itemText, new Runnable() { 17 | @Override 18 | public void run() { 19 | // Code to run when action activated 20 | } 21 | }); 22 | ``` 23 | 24 | ### Screenshot 25 | 26 | ![](screenshots/action_list_box.png) -------------------------------------------------------------------------------- /docs/examples/gui/buttons.md: -------------------------------------------------------------------------------- 1 | Buttons 2 | --- 3 | 4 | Buttons have a label and a callback. 5 | 6 | To create a simple button, with no callback: 7 | 8 | ``` 9 | Button button = new Button("Enter"); 10 | ``` 11 | 12 | You can also create a button with a callback: 13 | 14 | ``` 15 | Button button = new Button("Enter", new Runnable() { 16 | @Override 17 | public void run() { 18 | // Actions go here 19 | } 20 | }); 21 | ``` 22 | 23 | As you can see, the callback runs in its own thread. 24 | 25 | Pressing the `Enter` key on the keyboard when the button is highlighted will trigger the callback. 26 | 27 | ### Screenshot 28 | 29 | ![](screenshots/buttons.png) -------------------------------------------------------------------------------- /docs/examples/gui/radio_boxes.md: -------------------------------------------------------------------------------- 1 | Radio Boxes 2 | --- 3 | 4 | Radio boxes allow users to select a single item from a list of predetermined values. 5 | 6 | To create a radio box list: 7 | 8 | ``` 9 | TerminalSize size = new TerminalSize(14, 10); 10 | RadioBoxList radioBoxList = new RadioBoxList(size); 11 | ``` 12 | To add radioboxes to a list: 13 | 14 | ``` 15 | radioBoxList.addItem("item 1"); 16 | radioBoxList.addItem("item 2"); 17 | radioBoxList.addItem("item 3"); 18 | ``` 19 | 20 | To get the currently checked item: 21 | 22 | ``` 23 | String checkedItems = radioBoxList.getCheckedItem(); 24 | ``` 25 | 26 | ### Screenshot 27 | 28 | ![](screenshots/radio_boxes.png) 29 | 30 | -------------------------------------------------------------------------------- /docs/examples/gui/component_sizing.md: -------------------------------------------------------------------------------- 1 | Component Sizing 2 | --- 3 | 4 | Throughout the GUI layer, the `TerminalSize` class is used to represent how many rows and columns a given component takes up on screen. 5 | 6 | For example, to set the on screen size of a `Panel`, call the `setPreferredSize` method and pass in a new `TerminalSize`: 7 | 8 | ``` 9 | Panel panel = new Panel(); 10 | panel.setPreferredSize(new TerminalSize(40, 2)); 11 | ``` 12 | 13 | You can also pass a `TerminalSize` object into the constructor of many GUI components, for example, the `TextBox` component: 14 | 15 | ``` 16 | // Creates a textbox 40 columns long, 1 row high 17 | TextBox textBox = new TextBox(new TerminalSize(40, 1)) 18 | 19 | ``` -------------------------------------------------------------------------------- /docs/examples/gui/check_boxes.md: -------------------------------------------------------------------------------- 1 | Check Boxes 2 | --- 3 | 4 | Check boxes allow users to select multiple items at once. Check boxes appear in a list. To create a `CheckBox`: 5 | 6 | ``` 7 | TerminalSize size = new TerminalSize(14, 10); 8 | CheckBoxList checkBoxList = new CheckBoxList(size); 9 | ``` 10 | 11 | To add checkboxes to a list: 12 | 13 | ``` 14 | checkBoxList.addItem("item 1"); 15 | checkBoxList.addItem("item 2"); 16 | checkBoxList.addItem("item 3"); 17 | ``` 18 | 19 | To get a list of selected items: 20 | 21 | ``` 22 | List checkedItems = checkBoxList.getCheckedItems(); 23 | ``` 24 | 25 | You can also check if a particular index is checked: 26 | 27 | ``` 28 | boolean result = checkBoxList.isChecked(2); 29 | ``` 30 | 31 | ### Screenshot 32 | 33 | ![](screenshots/check_boxes.png) -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue254.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.screen.Screen; 4 | import com.googlecode.lanterna.screen.TerminalScreen; 5 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 6 | import com.googlecode.lanterna.terminal.Terminal; 7 | 8 | import java.io.IOException; 9 | 10 | public class Issue254 { 11 | public static void main(String[] args) throws IOException { 12 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 13 | Screen screen = new TerminalScreen(terminal); 14 | screen.startScreen(); 15 | 16 | // Now resize the window to the smallest possible size allowed by the window manager 17 | // Then quickly make it bigger by grabbing the bottom right corner 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /licenseheader.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TextColorTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna; 2 | 3 | import org.junit.Test; 4 | 5 | import java.awt.*; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class TextColorTest { 10 | @Test 11 | public void testFromAWTColor() { 12 | TextColor.RGB rgb = TextColor.RGB.fromAWTColor(Color.BLUE); 13 | assertEquals(0, rgb.getRed()); 14 | assertEquals(0, rgb.getGreen()); 15 | assertEquals(255, rgb.getBlue()); 16 | rgb = TextColor.RGB.fromAWTColor(Color.RED); 17 | assertEquals(255, rgb.getRed()); 18 | assertEquals(0, rgb.getGreen()); 19 | assertEquals(0, rgb.getBlue()); 20 | rgb = TextColor.RGB.fromAWTColor(Color.GREEN); 21 | assertEquals(0, rgb.getRed()); 22 | assertEquals(255, rgb.getGreen()); 23 | assertEquals(0, rgb.getBlue()); 24 | } 25 | } -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/UnicodeTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.terminal; 2 | 3 | import com.googlecode.lanterna.TestTerminalFactory; 4 | import com.googlecode.lanterna.TextCharacter; 5 | import com.googlecode.lanterna.screen.Screen; 6 | import com.googlecode.lanterna.screen.TerminalScreen; 7 | 8 | import java.io.IOException; 9 | 10 | public class UnicodeTest { 11 | public static void main(String[] args) throws IOException, InterruptedException { 12 | Terminal terminal = new TestTerminalFactory(args).createTerminal(); 13 | Screen screen = new TerminalScreen(terminal); 14 | screen.startScreen(); 15 | screen.newTextGraphics().putString(4, 2, "Hello!"); 16 | screen.setCharacter(4, 2, TextCharacter.fromString("·")[0]); 17 | screen.refresh(); 18 | Thread.sleep(5000); 19 | screen.stopScreen(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/examples/java/com/googlecode/lanterna/examples/OutputString.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.examples; 2 | 3 | import java.io.IOException; 4 | 5 | import com.googlecode.lanterna.graphics.TextGraphics; 6 | import com.googlecode.lanterna.screen.Screen; 7 | import com.googlecode.lanterna.screen.TerminalScreen; 8 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 9 | import com.googlecode.lanterna.terminal.Terminal; 10 | 11 | 12 | public class OutputString { 13 | 14 | public static void main(String[] args) throws IOException { 15 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 16 | Screen screen = new TerminalScreen(terminal); 17 | 18 | String s = "Hello World!"; 19 | TextGraphics tGraphics = screen.newTextGraphics(); 20 | 21 | screen.startScreen(); 22 | screen.clear(); 23 | 24 | tGraphics.putString(10, 10, s); 25 | screen.refresh(); 26 | 27 | screen.readInput(); 28 | screen.stopScreen(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/EmojiTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.terminal; 2 | 3 | import com.googlecode.lanterna.TestTerminalFactory; 4 | 5 | import java.io.IOException; 6 | 7 | public class EmojiTest { 8 | public static void main(String[] args) throws IOException { 9 | System.out.println("\uD83E\uDD26\uD83C\uDFFC\u200D".codePoints().count()); 10 | System.out.println("\uD83C\uDF55"); 11 | System.out.println("\uD83C"); 12 | System.out.println(Character.isSurrogate("\uD83C".charAt(0))); 13 | System.out.println("\uD83C\uDF55".length()); 14 | System.out.println("あ".codePoints().count()); 15 | System.out.println("บุ".codePoints().count()); 16 | System.out.println("บุ".toCharArray().length); 17 | System.out.print("\\u" + Integer.toHexString("บุ".toCharArray()[0])); 18 | System.out.println("\\u" + Integer.toHexString("บุ".toCharArray()[1])); 19 | System.out.println("\uD83C\uDF55".codePoints().count()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/examples/java/com/googlecode/lanterna/examples/OutputChar.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.examples; 2 | 3 | import java.io.IOException; 4 | 5 | import com.googlecode.lanterna.TextCharacter; 6 | import com.googlecode.lanterna.screen.Screen; 7 | import com.googlecode.lanterna.screen.TerminalScreen; 8 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 9 | import com.googlecode.lanterna.terminal.Terminal; 10 | 11 | 12 | /** 13 | * Creates a terminal and prints a '*' to the (10,10) position. 14 | * Waits for a keypress then exit. 15 | * 16 | * @author Peter Borkuti 17 | * 18 | */ 19 | public class OutputChar { 20 | 21 | public static void main(String[] args) throws IOException { 22 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 23 | Screen screen = new TerminalScreen(terminal); 24 | 25 | screen.startScreen(); 26 | screen.clear(); 27 | 28 | screen.setCharacter(10, 10, new TextCharacter('*')); 29 | screen.refresh(); 30 | 31 | screen.readInput(); 32 | screen.stopScreen(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue385.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.BasicWindow; 4 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 5 | import com.googlecode.lanterna.gui2.Window; 6 | import com.googlecode.lanterna.gui2.WindowBasedTextGUI; 7 | import com.googlecode.lanterna.screen.Screen; 8 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 9 | 10 | import java.util.Collections; 11 | 12 | public class Issue385 { 13 | public static void main(String[] args) throws Exception { 14 | 15 | DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory(); 16 | Screen screen = terminalFactory.createScreen(); 17 | screen.startScreen(); 18 | 19 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 20 | 21 | final Window window = new BasicWindow("My Root Window"); 22 | window.setHints(Collections.singletonList(Window.Hint.FULL_SCREEN)); 23 | 24 | textGUI.addWindowAndWait(window); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue361.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author Andrey Zelyaev(zella), slightly modified by Andreas(avl42) 3 | */ 4 | package com.googlecode.lanterna.issue; 5 | 6 | import com.googlecode.lanterna.gui2.*; 7 | import com.googlecode.lanterna.screen.*; 8 | import com.googlecode.lanterna.terminal.*; 9 | 10 | import java.util.Collections; 11 | 12 | public class Issue361 { 13 | 14 | public static void main(String[] args) throws Exception { 15 | 16 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 17 | Screen screen = new TerminalScreen(terminal); 18 | screen.startScreen(); 19 | 20 | BasicWindow window1 = new BasicWindow(); 21 | window1.setHints(Collections.singletonList(Window.Hint.CENTERED)); 22 | 23 | BasicWindow window2 = new BasicWindow(); 24 | window2.setHints(Collections.emptyList()); 25 | 26 | // Create gui and start gui 27 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 28 | gui.addWindow(window2); 29 | gui.addWindowAndWait(window1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue376.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.*; 4 | import com.googlecode.lanterna.screen.Screen; 5 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 6 | 7 | import java.io.IOException; 8 | 9 | public class Issue376 { 10 | public static void main(String... args) throws IOException { 11 | Screen screen = new DefaultTerminalFactory().createScreen(); 12 | screen.startScreen(); 13 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 14 | Window window = new LabelWithTabWindow(); 15 | gui.addWindow(window); 16 | gui.waitForWindowToClose(window); 17 | screen.stopScreen(); 18 | } 19 | 20 | private static class LabelWithTabWindow extends AbstractWindow { 21 | LabelWithTabWindow() { 22 | Panel panel = new Panel(); 23 | panel.addComponent(new Label("A label without tab")); 24 | panel.addComponent(new Label("\tAnd one with tab")); 25 | setComponent(panel); 26 | } 27 | } 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/LayoutData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * Empty interface to use for values that can be used as a layout meta-data on components. 23 | * @author martin 24 | */ 25 | public interface LayoutData { 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/win32/Wincon.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.terminal.win32; 2 | 3 | import com.sun.jna.Native; 4 | import com.sun.jna.platform.win32.WinDef.LPVOID; 5 | import com.sun.jna.platform.win32.WinNT.HANDLE; 6 | import com.sun.jna.ptr.IntByReference; 7 | import com.sun.jna.win32.StdCallLibrary; 8 | import com.sun.jna.win32.W32APIOptions; 9 | 10 | public interface Wincon extends StdCallLibrary, com.sun.jna.platform.win32.Wincon { 11 | 12 | Wincon INSTANCE = Native.load("kernel32", Wincon.class, W32APIOptions.UNICODE_OPTIONS); 13 | 14 | int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; 15 | int DISABLE_NEWLINE_AUTO_RETURN = 0x0008; 16 | int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200; 17 | 18 | boolean GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, WinDef.CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); 19 | 20 | boolean ReadConsoleInput(HANDLE hConsoleInput, WinDef.INPUT_RECORD[] lpBuffer, int nLength, IntByReference lpNumberOfEventsRead); 21 | 22 | boolean WriteConsole(HANDLE hConsoleOutput, String lpBuffer, int nNumberOfCharsToWrite, IntByReference lpNumberOfCharsWritten, LPVOID lpReserved); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/EnqTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | /** 22 | * 23 | * @author martin 24 | */ 25 | public class EnqTest { 26 | public static void main(String[] args) { 27 | System.out.write(5); 28 | System.out.flush(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/examples/gui/tables.md: -------------------------------------------------------------------------------- 1 | Tables 2 | --- 3 | 4 | To create a `Table`: 5 | 6 | ``` 7 | Table table = new Table("Column 1", "Column 2", "Column 3"); 8 | ``` 9 | 10 | The above line will create a table with three headers. 11 | 12 | All `Table`s have a connected `TableModel`. The `TableModel` is used to access the data within the table, add rows, add columns, etc. 13 | 14 | To add a row: 15 | 16 | ``` 17 | table.getTableModel().addRow("1", "2", "3"); 18 | ``` 19 | 20 | When adding a row, the number of arguments must match the number of columns. 21 | 22 | You can add a select action, which will run when a row is selected and the `Enter` key is pressed: 23 | 24 | ``` 25 | table.setSelectAction(new Runnable() { 26 | @Override 27 | public void run() { 28 | List data = table.getTableModel().getRow(table.getSelectedRow()); 29 | for(int i = 0; i < data.size(); i++) { 30 | System.out.println(data.get(i)); 31 | } 32 | } 33 | }); 34 | ``` 35 | 36 | The code above will print out each value in the row to the console when a row is selected and the `Enter` key is pressed. 37 | 38 | ### Screenshot 39 | 40 | ![](screenshots/tables.png) 41 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue359.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author Valentin(linouxis9), modified by Andreas(avl42) 3 | */ 4 | package com.googlecode.lanterna.issue; 5 | 6 | import com.googlecode.lanterna.gui2.*; 7 | import com.googlecode.lanterna.screen.*; 8 | import com.googlecode.lanterna.terminal.*; 9 | 10 | import java.io.IOException; 11 | 12 | public class Issue359 { 13 | public static void main(String[] args) { 14 | try { 15 | Screen screen = new DefaultTerminalFactory().createScreen(); 16 | screen.startScreen(); 17 | 18 | Window window = new BasicWindow(); 19 | Button button = new Button("Hello"); 20 | 21 | // Replacing a Component by itself just Border-wrapped 22 | // caused a NullPointerException lateron from within 23 | // the call to gui.addWindowAndWait(window); 24 | window.setComponent(button); 25 | window.setComponent(button.withBorder(Borders.singleLine("Border"))); 26 | 27 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 28 | gui.addWindowAndWait(window); 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/examples/gui/file_dialogs.md: -------------------------------------------------------------------------------- 1 | File Dialogs 2 | --- 3 | 4 | File dialogs are pop-up windows that allow users to choose files from the user's system. 5 | 6 | To create an file dialog, as with all dialogs, you'll need to create and pass in a `WindowBasedTextGUI`: 7 | 8 | ``` 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Setup WindowBasedTextGUI for dialogs 15 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 16 | ``` 17 | 18 | In the following example, a file dialog is shown to the user when the button is clicked. When the user selects and submits a file, the full file path of the selected file is returned and stored in the variable `input`: 19 | 20 | ``` 21 | panel.addComponent(new Button("Test", new Runnable() { 22 | @Override 23 | public void run() { 24 | String input = new FileDialogBuilder() 25 | .setTitle("Open File") 26 | .setDescription("Choose a file") 27 | .setActionLabel("Open") 28 | .build() 29 | .showDialog(textGUI); 30 | } 31 | })); 32 | ``` 33 | 34 | ### Screenshot 35 | 36 | ![](screenshots/file_dialogs.png) -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue313.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.TextColor; 4 | import com.googlecode.lanterna.gui2.BasicWindow; 5 | import com.googlecode.lanterna.gui2.DefaultWindowManager; 6 | import com.googlecode.lanterna.gui2.EmptySpace; 7 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 8 | import com.googlecode.lanterna.screen.Screen; 9 | import com.googlecode.lanterna.screen.TerminalScreen; 10 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 11 | import com.googlecode.lanterna.terminal.Terminal; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * Created by Martin on 2017-07-09. 17 | */ 18 | public class Issue313 { 19 | public static void main(String[] args) throws IOException { 20 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 21 | Screen screen = new TerminalScreen(terminal); 22 | screen.startScreen(); 23 | 24 | BasicWindow window = new BasicWindow(); 25 | window.setTitle("Hello World"); 26 | 27 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 28 | gui.addWindowAndWait(window); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/examples/java/com/googlecode/lanterna/examples/DrawRectangle.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.examples; 2 | 3 | import java.io.IOException; 4 | 5 | import com.googlecode.lanterna.TerminalPosition; 6 | import com.googlecode.lanterna.TerminalSize; 7 | import com.googlecode.lanterna.graphics.TextGraphics; 8 | import com.googlecode.lanterna.screen.Screen; 9 | import com.googlecode.lanterna.screen.TerminalScreen; 10 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 11 | import com.googlecode.lanterna.terminal.Terminal; 12 | 13 | 14 | /** 15 | * Creates a TerminalScreen and a TextGraphics from it and writes a rectangle 16 | * from the character '*' 17 | * 18 | * @author Peter Borkuti 19 | * 20 | */ 21 | public class DrawRectangle { 22 | 23 | public static void main(String[] args) throws IOException { 24 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 25 | Screen screen = new TerminalScreen(terminal); 26 | 27 | TextGraphics tGraphics = screen.newTextGraphics(); 28 | 29 | screen.startScreen(); 30 | screen.clear(); 31 | 32 | tGraphics.drawRectangle( 33 | new TerminalPosition(3,3), new TerminalSize(10,10), '*'); 34 | screen.refresh(); 35 | 36 | screen.readInput(); 37 | screen.stopScreen(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /docs/examples/gui/dir_dialogs.md: -------------------------------------------------------------------------------- 1 | Directory Dialogs 2 | --- 3 | 4 | Directory dialogs are pop-up windows that allow users to choose directories from the user's system. 5 | 6 | To create a directory dialog, as with all dialogs, you'll need to create and pass in a `WindowBasedTextGUI`: 7 | 8 | ```java 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Setup WindowBasedTextGUI for dialogs 15 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 16 | ``` 17 | 18 | In the following example, a direcotry dialog is shown to the user when the button is clicked. 19 | When the user selects and submits a directory, the full file path of the selected directory 20 | is returned and stored in the variable `input` and printed to stdout: 21 | 22 | ```java 23 | panel.addComponent(new Button("Test", new Runnable() { 24 | @Override 25 | public void run() { 26 | File input = new DirectoryDialogBuilder() 27 | .setTitle("Select directory") 28 | .setDescription("Choose a directory") 29 | .setActionLabel("Select") 30 | .build() 31 | .showDialog(textGUI); 32 | System.out.println(input); 33 | } 34 | })); 35 | ``` 36 | 37 | ### Screenshot 38 | 39 | ![](screenshots/dir_dialogs.png) -------------------------------------------------------------------------------- /docs/examples/gui/combo_boxes.md: -------------------------------------------------------------------------------- 1 | Combo boxes 2 | --- 3 | 4 | To create a new combo box: 5 | 6 | ``` 7 | ComboBox comboBox = new ComboBox(); 8 | ``` 9 | 10 | To add items to a `ComboBox`, call `addItem()`: 11 | 12 | ``` 13 | comboBox.addItem("item 1"); 14 | comboBox.addItem("item 2"); 15 | comboBox.addItem("item 3"); 16 | ``` 17 | 18 | To get the currently selected index: 19 | 20 | ``` 21 | // Returns an integer value 22 | comboBox.getSelectedIndex(); 23 | ``` 24 | 25 | To mark the combo box as read-only: 26 | 27 | ``` 28 | ComboBox comboBox = new ComboBox().setReadOnly(false); 29 | ``` 30 | 31 | `setReadOnly` returns the instance of the combo box just created. This is so that methods can be chained together. 32 | 33 | As with all components, you can set the preferred size via `setPreferredSize`: 34 | 35 | ``` 36 | comboBox.setPreferredSize(new TerminalSize(15, 1)); 37 | ``` 38 | 39 | This will set the width of the combo box to be 15 characters wide. You can also change the height of the combo box if you so wish. 40 | 41 | When the user highlights the combo box and presses the `Enter` key on the keyboard, the list of selectable items will show. 42 | 43 | ### Screenshots 44 | 45 | #### Non-activated: 46 | 47 | ![](screenshots/combo_box.png) 48 | 49 | #### Activated: 50 | 51 | ![](screenshots/combo_box_activated.png) -------------------------------------------------------------------------------- /native-integration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.googlecode.lanterna 7 | lanterna-native-integration 8 | 3.0.0-SNAPSHOT 9 | 10 | 11 | 12 | com.googlecode.lanterna 13 | lanterna 14 | 3.0.0 15 | 16 | 17 | net.java.dev.jna 18 | jna 19 | 4.4.0 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.apache.maven.plugins 27 | maven-compiler-plugin 28 | 29 | 1.6 30 | 1.6 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/MouseActionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | /** 22 | * Enum type for the different kinds of mouse actions supported 23 | */ 24 | public enum MouseActionType { 25 | CLICK_DOWN, 26 | CLICK_RELEASE, 27 | SCROLL_UP, 28 | SCROLL_DOWN, 29 | /** 30 | * Moving the mouse cursor on the screen while holding a button down 31 | */ 32 | DRAG, 33 | /** 34 | * Moving the mouse cursor on the screen without holding any buttons down 35 | */ 36 | MOVE, 37 | ; 38 | } 39 | -------------------------------------------------------------------------------- /docs/examples/gui/windows.md: -------------------------------------------------------------------------------- 1 | Windows 2 | --- 3 | 4 | Windows are there to hold your components. 5 | 6 | To create a basic window: 7 | 8 | ``` 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Create window to hold the panel 15 | BasicWindow window = new BasicWindow(); 16 | 17 | // Create gui and start gui 18 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 19 | gui.addWindowAndWait(window); 20 | ``` 21 | 22 | This will create a basic window, ready for you to fill with components: 23 | 24 | What if you wanted to create a full screen window? No problem: 25 | 26 | ``` 27 | BasicWindow window = new BasicWindow(); 28 | window.setHints(Arrays.asList(Window.Hint.FULL_SCREEN)); 29 | ``` 30 | 31 | You can combine many hints together, to customise how your window should look: 32 | 33 | ``` 34 | // Full screen without the border 35 | BasicWindow window = new BasicWindow(); 36 | window.setHints(Arrays.asList(Window.Hint.FULL_SCREEN, Window.Hint.NO_DECORATIONS)); 37 | ``` 38 | 39 | How about a center screen window? 40 | 41 | ``` 42 | BasicWindow window = new BasicWindow(); 43 | window.setHints(Arrays.asList(Window.Hint.CENTERED)); 44 | ``` 45 | 46 | Experiment with a number of `Hint`s to get the `Window` you want. -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue334.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.TextColor; 4 | import com.googlecode.lanterna.gui2.*; 5 | import com.googlecode.lanterna.screen.Screen; 6 | import com.googlecode.lanterna.screen.TerminalScreen; 7 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 8 | import com.googlecode.lanterna.terminal.Terminal; 9 | 10 | import java.io.IOException; 11 | 12 | public class Issue334 { 13 | public static void main(String[] args) throws IOException { 14 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 15 | Screen screen = new TerminalScreen(terminal); 16 | screen.startScreen(); 17 | 18 | // Create panel to hold components 19 | Panel panel = new Panel(); 20 | panel.setLayoutManager(new GridLayout(1)); 21 | panel.addComponent(new Label("")); 22 | 23 | // Create gui and start gui 24 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 25 | 26 | // Create window to hold the panel 27 | final BasicWindow window = new BasicWindow(); 28 | window.setComponent(Panels.vertical(panel)); 29 | window.setCloseWindowWithEscape(true); 30 | 31 | gui.addWindowAndWait(window); 32 | screen.stopScreen(); 33 | terminal.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/Direction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * Enum for distinguishing between horizontal and vertical directions. Used in {@code LinearLayout} and 23 | * {@code Separator}. 24 | * @author Martin 25 | */ 26 | public enum Direction { 27 | /** 28 | * Horizontal direction, meaning something is moving along the x-axis (or column-axis) 29 | */ 30 | HORIZONTAL, //See? I can spell it! 31 | /** 32 | * Vertical directory, meaning something is moving along the y-axis (or row-axis) 33 | */ 34 | VERTICAL, 35 | ; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/graphics/ThemedTextGraphics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.graphics; 20 | 21 | /** 22 | * Expanded TextGraphics that adds methods to interact with themes 23 | * @author Martin 24 | */ 25 | public interface ThemedTextGraphics extends TextGraphics { 26 | /** 27 | * Takes a ThemeStyle as applies it to this TextGraphics. This will effectively set the foreground color, the 28 | * background color and all the SGRs. 29 | * @param themeStyle ThemeStyle to apply 30 | * @return Itself 31 | */ 32 | ThemedTextGraphics applyThemeStyle(ThemeStyle themeStyle); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/TextGUIThreadFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * Factory class for creating {@code TextGUIThread} objects. This is used by {@code TextGUI} implementations to assign 23 | * their local {@code TextGUIThread} reference 24 | */ 25 | public interface TextGUIThreadFactory { 26 | /** 27 | * Creates a new {@code TextGUIThread} objects 28 | * @param textGUI {@code TextGUI} this {@code TextGUIThread} should be associated with 29 | * @return The new {@code TextGUIThread} 30 | */ 31 | TextGUIThread createTextGUIThread(TextGUI textGUI); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/swing/TerminalEmulatorAutoCloseTrigger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal.swing; 20 | 21 | /** 22 | * This enum stored various ways the AWTTerminalFrame and SwingTerminalFrame can automatically close (hide and dispose) 23 | * themselves when a certain condition happens. 24 | */ 25 | public enum TerminalEmulatorAutoCloseTrigger { 26 | /** 27 | * Close the frame when exiting from private mode 28 | */ 29 | CLOSE_ON_EXIT_PRIVATE_MODE, 30 | /** 31 | * Close if the user presses ESC key on the keyboard 32 | */ 33 | CLOSE_ON_ESCAPE, 34 | ; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/dialogs/TextInputDialogResultValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.dialogs; 20 | 21 | /** 22 | * Interface to implement for custom validation of text input in a {@code TextInputDialog} 23 | * @author Martin 24 | */ 25 | public interface TextInputDialogResultValidator { 26 | /** 27 | * Tests the content in the text box if it is valid or not 28 | * @param content Current content of the text box 29 | * @return {@code null} if the content is valid, or an error message explaining what's wrong with the content 30 | * otherwise 31 | */ 32 | String validate(String content); 33 | } 34 | -------------------------------------------------------------------------------- /docs/examples/gui/action_list_dialogs.md: -------------------------------------------------------------------------------- 1 | Action List Dialogs 2 | --- 3 | 4 | Action list dialogs are pop-up windows that allow users to choose from a list of predetermined actions. 5 | 6 | To create an action list dialog, as with all dialogs, you'll need to create and pass in a `WindowBasedTextGUI`: 7 | 8 | ``` 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Setup WindowBasedTextGUI for dialogs 15 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 16 | ``` 17 | 18 | In the following example, an action list dialog box is shown to the user when the button is clicked. When a user activates an action in the list, the corresponding thread is ran. 19 | 20 | ``` 21 | new ActionListDialogBuilder() 22 | .setTitle("Action List Dialog") 23 | .setDescription("Choose an item") 24 | .addAction("First Item", new Runnable() { 25 | @Override 26 | public void run() { 27 | // Do 1st thing... 28 | } 29 | }) 30 | .addAction("Second Item", new Runnable() { 31 | @Override 32 | public void run() { 33 | // Do 2nd thing... 34 | } 35 | }) 36 | .addAction("Third Item", new Runnable() { 37 | @Override 38 | public void run() { 39 | // Do 3rd thing... 40 | } 41 | }) 42 | .build() 43 | .showDialog(textGUI); 44 | ``` 45 | 46 | ### Screenshot 47 | 48 | ![](screenshots/action_list_dialogs.png) -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue312.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.graphics.TextGraphics; 4 | import com.googlecode.lanterna.input.KeyStroke; 5 | import com.googlecode.lanterna.input.KeyType; 6 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 7 | import com.googlecode.lanterna.terminal.Terminal; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by Martin on 2017-07-09. 13 | */ 14 | public class Issue312 { 15 | public static void main(String[] args) throws IOException { 16 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 17 | TextGraphics textGraphics = terminal.newTextGraphics(); 18 | int row = 0; 19 | while(true) { 20 | KeyStroke keyStroke = terminal.pollInput(); 21 | if (keyStroke == null) { 22 | terminal.setCursorPosition(0, 0); 23 | textGraphics.putString(0, terminal.getCursorPosition().getRow(), " > "); 24 | terminal.flush(); 25 | keyStroke = terminal.readInput(); 26 | row = 1; 27 | terminal.clearScreen(); 28 | } 29 | if (keyStroke.getKeyType() == KeyType.ESCAPE || keyStroke.getKeyType() == KeyType.EOF) { 30 | break; 31 | } 32 | textGraphics.putString(0, row++, "Read KeyStroke: " + keyStroke + "\n"); 33 | terminal.flush(); 34 | } 35 | terminal.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/Maven.md: -------------------------------------------------------------------------------- 1 | # Using Maven # 2 | 3 | If you want to use the Lanterna library through [Apache Maven](http://maven.apache.org), it's very easy to do. Just put this dependency in your `pom.xml`: 4 | ```xml 5 | 6 | ... 7 | 8 | com.googlecode.lanterna 9 | lanterna 10 | 3.1.1 11 | 12 | ... 13 | 14 | ``` 15 | 16 | Adjust the version number as required (I'm probably not going to remember to update this page every time I make a release). Since the Sonatype OSS repository is synchronized with Maven Central, you don't need to add any extra repository definitions to your project or your Maven settings. 17 | 18 | ## Using snapshot releases ## 19 | If you want to try a snapshot release of Lanterna through Maven, you'll need to add the Sonatype OSS snapshot repository to you project `pom.xml` or your global Maven settings. I have not tested this, but according to [this](https://github.com/thucydides-webtests/thucydides/wiki/Getting-Started) site, you can add it to your user's `settings.xml` (or, probably easier, to your project `pom.xml`): 20 | ```xml 21 | 22 | ... 23 | 24 | sonatype-oss-snapshots 25 | https://oss.sonatype.org/content/repositories/snapshots 26 | 27 | ... 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue358.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.TextColor; 4 | import com.googlecode.lanterna.gui2.*; 5 | import com.googlecode.lanterna.screen.Screen; 6 | import com.googlecode.lanterna.screen.TerminalScreen; 7 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 8 | import com.googlecode.lanterna.terminal.Terminal; 9 | 10 | import java.io.IOException; 11 | 12 | public class Issue358 { 13 | public static void main(String[] args) throws IOException { 14 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 15 | Screen screen = new TerminalScreen(terminal); 16 | screen.startScreen(); 17 | MultiWindowTextGUI textGUI = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 18 | 19 | String title = "Issue358"; 20 | 21 | int nbColumns = 5; 22 | final Window window = new BasicWindow(title); 23 | 24 | final GridLayout layoutManager = new GridLayout(nbColumns); 25 | layoutManager.setVerticalSpacing(0); 26 | layoutManager.setHorizontalSpacing(1); 27 | final Panel contentPanel = new Panel(layoutManager); 28 | contentPanel.addComponent( 29 | new EmptySpace(TextColor.ANSI.CYAN).setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER, false, false,3, 1))); 30 | window.setComponent(contentPanel); 31 | textGUI.addWindowAndWait(window); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TestAllCodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna; 21 | 22 | /** 23 | * Prints the whole symbol table, this is debug stuff for UTF-8 to non-UTF-8 24 | * symbol character conversions... 25 | * @author Martin 26 | */ 27 | public class TestAllCodes { 28 | public static void main(String[] args) throws Exception 29 | { 30 | System.out.write(new byte[] { (byte)0x1B, 0x28, 0x30 }); 31 | for(int i = 0; i < 200; i++) { 32 | System.out.write((i + " = " + ((char)i) + "\n").getBytes()); 33 | } 34 | System.out.write(new byte[] { (byte)0x1B, 0x28, 0x42 }); 35 | //System.out.write(new byte[] { (byte)0x1B, (byte)0x21, (byte)0x40, 15 }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/examples/gui/panels.md: -------------------------------------------------------------------------------- 1 | Panels 2 | --- 3 | 4 | Panels are a way for you to split up your UI and components and group them into seperate sections, similar to JPanels in Swing. 5 | 6 | To create a `Panel`: 7 | 8 | ``` 9 | Panel panel = new Panel(); 10 | ``` 11 | 12 | To add a component to a `Panel`: 13 | 14 | ``` 15 | panel.addComponent(new Button("Enter")); 16 | ``` 17 | 18 | You can also nest `Panel`s: 19 | 20 | ``` 21 | BasicWindow window = new BasicWindow(); 22 | 23 | Panel mainPanel = new Panel(); 24 | mainPanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); 25 | 26 | Panel leftPanel = new Panel(); 27 | mainPanel.addComponent(leftPanel.withBorder(Borders.singleLine("Left Panel"))); 28 | 29 | Panel rightPanel = new Panel(); 30 | mainPanel.addComponent(rightPanel.withBorder(Borders.singleLine("Right Panel"))); 31 | 32 | window.setComponent(mainPanel.withBorder(Borders.singleLine("Main Panel"))); 33 | textGUI.addWindow(window); 34 | ``` 35 | 36 | In the example above, the "Main Panel" holds two seperate panels: the "Left Panel" and the "Right Panel". 37 | 38 | The left and right panels sit next to each other because a layout manager was provided: 39 | 40 | ``` 41 | mainPanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); 42 | ``` 43 | 44 | By default, the layout for `Panel`s is a default `LinearLayout` set to `VERTICAL`, meaning that when components are added, they will sit on top of each other rather than next to each other. More information on layout managers can be found in the layout manager section. 45 | 46 | ### Screenshot 47 | 48 | ![](screenshots/panels.png) -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TextCharacterTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class TextCharacterTest { 8 | 9 | @Test 10 | public void fromString() { 11 | assertEquals(6, TextCharacter.fromString("Hello!").length); 12 | assertEquals(5, TextCharacter.fromString("あいうえお").length); 13 | assertEquals(1, TextCharacter.fromString("\uD83C\uDF55").length); 14 | assertEquals(1, TextCharacter.fromString("\uD83E\uDD7A").length); 15 | // This is a weird compound character that should be printed as one, but is actually two char:s 16 | assertEquals(1, TextCharacter.fromString("บุ").length); 17 | 18 | // This should be one but Java is lagging behind a bit on Unicode emoji and interprets it as 2 19 | //assertEquals(1, TextCharacter.fromString("\uD83D\uDC4D\uD83C\uDFFF").length); 20 | } 21 | 22 | @Test 23 | public void emojisAreDoubleWidth() { 24 | assertTrue(TextCharacter.fromString("\uD83D\uDC69\uD83C\uDFFD")[0].isDoubleWidth()); 25 | assertTrue(TextCharacter.fromString("\uD83C\uDFE9")[0].isDoubleWidth()); 26 | assertTrue(TextCharacter.fromString("\uD83D\uDC96")[0].isDoubleWidth()); 27 | assertTrue(TextCharacter.fromString("❤\uFE0F")[0].isDoubleWidth()); 28 | assertTrue(TextCharacter.fromString("\uD83D\uDE0A")[0].isDoubleWidth()); 29 | assertTrue(TextCharacter.fromString("\uD83D\uDC40")[0].isDoubleWidth()); 30 | assertFalse(TextCharacter.fromString("M")[0].isDoubleWidth()); // Not emoji 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/InteractableRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | 23 | /** 24 | * Extended interface for component renderers used with interactable components. Because only the renderer knows what 25 | * the component looks like, the component itself cannot know where to place the text cursor, so this method is instead 26 | * delegated to this interface that extends the regular component renderer. 27 | * 28 | * @author Martin 29 | * @param Type of the component this {@code InteractableRenderer} is designed for 30 | */ 31 | public interface InteractableRenderer extends ComponentRenderer { 32 | TerminalPosition getCursorLocation(T component); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | module com.googlecode.lanterna { 20 | exports com.googlecode.lanterna; 21 | exports com.googlecode.lanterna.bundle; 22 | exports com.googlecode.lanterna.graphics; 23 | exports com.googlecode.lanterna.gui2; 24 | exports com.googlecode.lanterna.gui2.dialogs; 25 | exports com.googlecode.lanterna.gui2.table; 26 | exports com.googlecode.lanterna.gui2.menu; 27 | exports com.googlecode.lanterna.input; 28 | exports com.googlecode.lanterna.screen; 29 | exports com.googlecode.lanterna.terminal; 30 | exports com.googlecode.lanterna.terminal.ansi; 31 | exports com.googlecode.lanterna.terminal.swing; 32 | exports com.googlecode.lanterna.terminal.virtual; 33 | 34 | requires static java.desktop; 35 | requires static com.sun.jna; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/BasicWindow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * Simple AbstractWindow implementation that you can use as a building block when creating new windows without having 23 | * to create new classes. 24 | * 25 | * @author Martin 26 | */ 27 | public class BasicWindow extends AbstractWindow { 28 | 29 | /** 30 | * Default constructor, creates a new window with no title 31 | */ 32 | public BasicWindow() { 33 | super(); 34 | } 35 | 36 | /** 37 | * This constructor creates a window with a specific title, that is (probably) going to be displayed in the window 38 | * decoration 39 | * @param title Title of the window 40 | */ 41 | public BasicWindow(String title) { 42 | super(title); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue78.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.issue; 20 | 21 | import com.googlecode.lanterna.TestTerminalFactory; 22 | import com.googlecode.lanterna.screen.TerminalScreen; 23 | import com.googlecode.lanterna.terminal.Terminal; 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | * @author martin 29 | */ 30 | public class Issue78 { 31 | public static void main(String[] args) throws IOException { 32 | Terminal t = new TestTerminalFactory(args).createTerminal(); 33 | t.enterPrivateMode(); 34 | TerminalScreen s = new TerminalScreen(t); 35 | s.startScreen(); 36 | try { 37 | Thread.sleep(1000); 38 | } 39 | catch(InterruptedException e) {} 40 | s.stopScreen(); 41 | t.exitPrivateMode(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/Composite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * A Composite is a Container that contains only one (or zero) component. Normally it is a kind of decorator, like a 23 | * border, that wraps a single component for visualization purposes. 24 | * @author Martin 25 | */ 26 | public interface Composite { 27 | /** 28 | * Returns the component that this Composite is wrapping 29 | * @return Component the composite is wrapping 30 | */ 31 | Component getComponent(); 32 | 33 | /** 34 | * Sets the component which is inside this Composite. If you call this method with null, it removes the component 35 | * wrapped by this Composite. 36 | * @param component Component to wrap 37 | */ 38 | void setComponent(Component component); 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue305.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 4 | import com.googlecode.lanterna.terminal.Terminal; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | 10 | /** 11 | * Created by martin on 2017-04-15. 12 | */ 13 | public class Issue305 { 14 | /** 15 | * @param args the command line arguments 16 | */ 17 | public static void main(String[] args) throws IOException { 18 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 19 | System.out.println("Class: " + terminal.getClass()); 20 | 21 | terminal.close(); 22 | 23 | BufferedReader br = null; 24 | try { 25 | br = new BufferedReader(new InputStreamReader(System.in)); 26 | 27 | while (true) { 28 | 29 | System.out.print("Enter something: "); 30 | String input = br.readLine(); 31 | 32 | if ("q".equals(input)) { 33 | System.out.println("Exit!"); 34 | System.exit(0); 35 | } 36 | 37 | System.out.println("input : " + input); 38 | System.out.println("-----------\n"); 39 | } 40 | 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } finally { 44 | if (br != null) { 45 | try { 46 | br.close(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/bundle/LocalizedUIBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.bundle; 20 | 21 | import java.util.Locale; 22 | 23 | /** 24 | * This class permits to get easily localized strings about the UI. 25 | * @author silveryocha 26 | */ 27 | public class LocalizedUIBundle extends BundleLocator { 28 | 29 | private static final LocalizedUIBundle MY_BUNDLE = new LocalizedUIBundle("multilang.lanterna-ui"); 30 | 31 | public static String get(String key, String... parameters) { 32 | return get(Locale.getDefault(), key, parameters); 33 | } 34 | 35 | public static String get(Locale locale, String key, String... parameters) { 36 | return MY_BUNDLE.getBundleKeyValue(locale, key, (Object[])parameters); 37 | } 38 | 39 | private LocalizedUIBundle(final String bundleName) { 40 | super(bundleName); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/TerminalFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * This interface is for abstracting the creation of your Terminal object. The bundled implementation is 25 | * DefaultTerminalFactory, which will use a simple auto-detection mechanism for figuring out which terminal 26 | * implementation to create based on characteristics of the system the program is running on. 27 | *

28 | * @author martin 29 | */ 30 | @SuppressWarnings("WeakerAccess") 31 | public interface TerminalFactory { 32 | /** 33 | * Instantiates a Terminal according to the factory implementation. 34 | * @return Terminal implementation 35 | * @throws IOException If there was an I/O error with the underlying input/output system 36 | */ 37 | Terminal createTerminal() throws IOException; 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/Environment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.Properties; 25 | 26 | /** 27 | * 28 | * @author martin 29 | */ 30 | public class Environment 31 | { 32 | public static void main(String[] args) 33 | { 34 | Properties properties = System.getProperties(); 35 | @SuppressWarnings({ "unchecked", "rawtypes" }) 36 | ArrayList keys = new ArrayList(properties.keySet()); 37 | Collections.sort(keys); 38 | for(String key: keys) 39 | System.out.println(key + " = " + properties.getProperty(key)); 40 | 41 | keys = new ArrayList<>(System.getenv().keySet()); 42 | Collections.sort(keys); 43 | for(String key: keys) 44 | System.out.println(key + " = " + System.getenv(key)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/InputFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.input.KeyStroke; 22 | 23 | /** 24 | * This interface can be used to programmatically intercept input from the user and decide if the input should be passed 25 | * on to the interactable. It's also possible to fire custom actions for certain keystrokes. 26 | */ 27 | public interface InputFilter { 28 | /** 29 | * Called when the component is about to receive input from the user and decides if the input should be passed on to 30 | * the component or not 31 | * @param interactable Interactable that the input is directed to 32 | * @param keyStroke User input 33 | * @return {@code true} if the input should be passed on to the interactable, {@code false} otherwise 34 | */ 35 | boolean onInput(Interactable interactable, KeyStroke keyStroke); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/EmptyWindowDecorationRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | import com.googlecode.lanterna.TerminalSize; 23 | 24 | /** 25 | * Implementation of WindowDecorationRenderer that is doesn't render any window decorations 26 | * @author Martin 27 | */ 28 | public class EmptyWindowDecorationRenderer implements WindowDecorationRenderer { 29 | @Override 30 | public TextGUIGraphics draw(WindowBasedTextGUI textGUI, TextGUIGraphics graphics, Window window) { 31 | return graphics; 32 | } 33 | 34 | @Override 35 | public TerminalSize getDecoratedSize(Window window, TerminalSize contentAreaSize) { 36 | return contentAreaSize; 37 | } 38 | 39 | @Override 40 | public TerminalPosition getOffset(Window window) { 41 | return TerminalPosition.TOP_LEFT_CORNER; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/TextGUIElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | /** 22 | * This interface is the base part in the Lanterna Text GUI component hierarchy 23 | * @author Martin 24 | */ 25 | public interface TextGUIElement { 26 | /** 27 | * Draws the GUI element using the supplied TextGUIGraphics object. This is the main method to implement when you 28 | * want to create your own GUI components. 29 | * @param graphics Graphics object to use when drawing the component 30 | */ 31 | void draw(TextGUIGraphics graphics); 32 | 33 | /** 34 | * Checks if this element (or any of its child components, if any) has signaled that what it's currently displaying 35 | * is out of date and needs re-drawing. 36 | * @return {@code true} if the component is invalid and needs redrawing, {@code false} otherwise 37 | */ 38 | boolean isInvalid(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/AltAndCharacterPattern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Character pattern that matches characters pressed while ALT key is held down 25 | * 26 | * @author Martin, Andreas 27 | */ 28 | public class AltAndCharacterPattern implements CharacterPattern { 29 | 30 | @Override 31 | public Matching match(List seq) { 32 | int size = seq.size(); 33 | if (size > 2 || seq.get(0) != KeyDecodingProfile.ESC_CODE) { 34 | return null; // nope 35 | } 36 | if (size == 1) { 37 | return Matching.NOT_YET; // maybe later 38 | } 39 | if ( Character.isISOControl(seq.get(1)) ) { 40 | return null; // nope 41 | } 42 | KeyStroke ks = new KeyStroke(seq.get(1), false, true); 43 | return new Matching( ks ); // yep 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue387.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.TerminalSize; 4 | import com.googlecode.lanterna.gui2.*; 5 | import com.googlecode.lanterna.gui2.table.Table; 6 | import com.googlecode.lanterna.screen.Screen; 7 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 8 | 9 | import java.io.IOException; 10 | 11 | public class Issue387 { 12 | 13 | public static void main(String[] args) { 14 | try { 15 | Screen screen = new DefaultTerminalFactory().createScreen(); 16 | screen.startScreen(); 17 | 18 | Window window = new BasicWindow(); 19 | 20 | Table table = new Table<>("Column"); 21 | table.setVisibleRows(3); 22 | 23 | table.getTableModel().addRow("row 1"); 24 | table.getTableModel().addRow("row 2"); 25 | table.getTableModel().addRow("row 3"); 26 | table.getTableModel().addRow("row 4"); 27 | table.getTableModel().addRow("row 5"); 28 | table.getTableModel().addRow("row 6"); 29 | table.getTableModel().addRow("row 7"); 30 | 31 | Panel panel = new Panel(); 32 | panel.addComponent(new TextBox()); 33 | panel.addComponent(new EmptySpace(new TerminalSize(15, 1))); 34 | panel.addComponent(table); 35 | panel.addComponent(new EmptySpace(new TerminalSize(15, 1))); 36 | panel.addComponent(new TextBox()); 37 | 38 | window.setComponent(panel); 39 | 40 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 41 | gui.addWindowAndWait(window); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue460.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.BasicWindow; 4 | import com.googlecode.lanterna.gui2.Button; 5 | import com.googlecode.lanterna.gui2.GridLayout; 6 | import com.googlecode.lanterna.gui2.Label; 7 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 8 | import com.googlecode.lanterna.gui2.Panel; 9 | import com.googlecode.lanterna.screen.Screen; 10 | import com.googlecode.lanterna.screen.TerminalScreen; 11 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 12 | import com.googlecode.lanterna.terminal.Terminal; 13 | 14 | public class Issue460 { 15 | public static void main(String[] args) throws Exception { 16 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 17 | Screen screen = new TerminalScreen(terminal); 18 | screen.startScreen(); 19 | 20 | final BasicWindow window1 = new BasicWindow(); 21 | Panel contentPanel = new Panel(new GridLayout(1)); 22 | contentPanel.addComponent(new Label("VERTICAL"), GridLayout.createLayoutData( 23 | GridLayout.Alignment.CENTER, 24 | GridLayout.Alignment.CENTER, 25 | true, 26 | true, 27 | 1, 28 | 4 29 | )); 30 | contentPanel.addComponent(new Button("Close", new Runnable() { 31 | @Override 32 | public void run() { 33 | window1.close(); 34 | } 35 | }), GridLayout.createHorizontallyFilledLayoutData(2)); 36 | window1.setComponent(contentPanel); 37 | 38 | // Create gui and start gui 39 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 40 | gui.addWindowAndWait(window1); 41 | screen.stopScreen(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/IOSafeExtendedTerminal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | /** 22 | * Interface extending ExtendedTerminal that removes the IOException throw clause. 23 | * 24 | * @author Martin 25 | * @author Andreas 26 | */ 27 | public interface IOSafeExtendedTerminal extends IOSafeTerminal,ExtendedTerminal { 28 | 29 | @Override 30 | void setTerminalSize(int columns, int rows); 31 | 32 | @Override 33 | void setTitle(String title); 34 | 35 | @Override 36 | void pushTitle(); 37 | 38 | @Override 39 | void popTitle(); 40 | 41 | @Override 42 | void iconify(); 43 | 44 | @Override 45 | void deiconify(); 46 | 47 | @Override 48 | void maximize(); 49 | 50 | @Override 51 | void unmaximize(); 52 | 53 | @Override 54 | void setMouseCaptureMode(MouseCaptureMode mouseCaptureMode); 55 | 56 | @Override 57 | void scrollLines(int firstLine, int lastLine, int distance); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/graphics/ShapeRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.graphics; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | import com.googlecode.lanterna.TerminalSize; 23 | import com.googlecode.lanterna.TextCharacter; 24 | 25 | /** 26 | * This package private interface exposes methods for translating abstract lines, triangles and rectangles to discreet 27 | * points on a grid. 28 | * @author Martin 29 | */ 30 | interface ShapeRenderer { 31 | void drawLine(TerminalPosition p1, TerminalPosition p2, TextCharacter character); 32 | void drawTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, TextCharacter character); 33 | void drawRectangle(TerminalPosition topLeft, TerminalSize size, TextCharacter character); 34 | void fillTriangle(TerminalPosition p1, TerminalPosition p2, TerminalPosition p3, TextCharacter character); 35 | void fillRectangle(TerminalPosition topLeft, TerminalSize size, TextCharacter character); 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/RawTerminalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | import com.googlecode.lanterna.TestTerminalFactory; 22 | import java.io.IOException; 23 | 24 | /** 25 | * 26 | * @author Martin 27 | */ 28 | public class RawTerminalTest { 29 | 30 | public static void main(String[] args) throws InterruptedException, IOException { 31 | Terminal terminal = new TestTerminalFactory(args).createTerminal(); 32 | terminal.enterPrivateMode(); 33 | terminal.clearScreen(); 34 | terminal.setCursorPosition(10, 5); 35 | terminal.putCharacter('H'); 36 | terminal.putCharacter('e'); 37 | terminal.putCharacter('l'); 38 | terminal.putCharacter('l'); 39 | terminal.putCharacter('o'); 40 | terminal.putCharacter('!'); 41 | terminal.setCursorPosition(0, 0); 42 | terminal.flush(); 43 | 44 | Thread.sleep(5000); 45 | terminal.exitPrivateMode(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /docs/examples/gui/message_dialogs.md: -------------------------------------------------------------------------------- 1 | Message Dialogs 2 | --- 3 | 4 | Message dialogs are simply pop-up messages that are shown to the user and dismissed with the "Enter" key. 5 | 6 | To create a message dialog, as with all dialogs, you'll need to create and pass in a `WindowBasedTextGUI`: 7 | 8 | ``` 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Setup WindowBasedTextGUI for dialogs 15 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 16 | ``` 17 | 18 | In the following example, a message box is shown to the user when the button is clicked: 19 | 20 | ``` 21 | panel.addComponent(new Button("Test", new Runnable() { 22 | @Override 23 | public void run() { 24 | MessageDialog.showMessageDialog(textGUI, "test", "test"); 25 | } 26 | })); 27 | ``` 28 | 29 | As you can see, it's incredibly easy to create and show a message dialog: 30 | 31 | ``` 32 | MessageDialog.showMessageDialog(textGUI, "Message", "Here is a message dialog!"); 33 | ``` 34 | 35 | You can also use a `MessageDialogBuilder` to build up and show a message dialog: 36 | 37 | ``` 38 | new MessageDialogBuilder() 39 | .setTitle("Here is the title") 40 | .setText("Here is a message") 41 | .build() 42 | .showDialog(textGUI); 43 | ``` 44 | 45 | You can also change the button on the `MessageDialog`: 46 | 47 | ``` 48 | new MessageDialogBuilder() 49 | .setTitle("Here is the title") 50 | .setText("Here is a message") 51 | .addButton(MessageDialogButton.Close) 52 | .build() 53 | .showDialog(textGUI); 54 | ``` 55 | 56 | The following buttons are available: 57 | 58 | - OK 59 | - Cancel 60 | - Yes 61 | - No 62 | - Close 63 | - Abort 64 | - Ignore 65 | - Retry 66 | - Continue 67 | 68 | ### Screenshot 69 | 70 | ![](screenshots/message_dialogs.png) 71 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/ansi/UnixTerminalSizeQuerier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal.ansi; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | 23 | /** 24 | * This class allows you to override by what means Lanterna detects the size of 25 | * the terminal. You can implement this interface and pass it to the 26 | * UnixTerminal constructor in order to use it. 27 | * @author martin 28 | */ 29 | @SuppressWarnings("WeakerAccess") 30 | public interface UnixTerminalSizeQuerier { 31 | /** 32 | * Checks what the size of the terminal is, measured in number of rows and columns. The implementer of this 33 | * interface is expected to know which terminal we are querying for and have all it needs to figure out the size. 34 | * One way of implementing this could be to read of an external value or variable or calling IPCs or just return 35 | * a static size at all times. 36 | * @return Size of the terminal at this point in time 37 | */ 38 | TerminalSize queryTerminalSize(); 39 | } 40 | -------------------------------------------------------------------------------- /native-integration/src/main/java/com/googlecode/lanterna/terminal/Wincon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | import com.sun.jna.ptr.IntByReference; 22 | import com.sun.jna.win32.StdCallLibrary; 23 | 24 | /** 25 | * Interface to Wincon, module in Win32 that can operate on the terminal 26 | */ 27 | interface Wincon extends StdCallLibrary { 28 | int STD_INPUT_HANDLE = -10; 29 | int STD_OUTPUT_HANDLE = -11; 30 | 31 | // SetConsoleMode input values 32 | int ENABLE_PROCESSED_INPUT = 1; 33 | int ENABLE_LINE_INPUT = 2; 34 | int ENABLE_ECHO_INPUT = 4; 35 | 36 | // SetConsoleMode screen buffer values 37 | int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4; 38 | int DISABLE_NEWLINE_AUTO_RETURN = 8; 39 | 40 | WinDef.HANDLE GetStdHandle(int var1); 41 | boolean GetConsoleMode(WinDef.HANDLE var1, IntByReference var2); 42 | boolean SetConsoleMode(WinDef.HANDLE var1, int var2); 43 | boolean GetConsoleScreenBufferInfo(WinDef.HANDLE hConsoleOutput, WinDef.CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); 44 | } 45 | -------------------------------------------------------------------------------- /docs/examples/gui/text_boxes.md: -------------------------------------------------------------------------------- 1 | Text Boxes 2 | --- 3 | 4 | Text boxes allow users to enter information. To create a text box: 5 | 6 | ``` 7 | TextBox textBox = new TextBox(); 8 | ``` 9 | 10 | You can pass in the [size](component_sizing.md) of the textbox via the constructor: 11 | 12 | ``` 13 | // Creates a textbox 30 columns long, 1 column high 14 | new TextBox(new TerminalSize(30,1)); 15 | ``` 16 | 17 | If you want to create a multi-line textbox, simply increase the row size: 18 | 19 | ``` 20 | // Creates a textbox 30 columns long, 5 column high 21 | new TextBox(new TerminalSize(30,5)); 22 | ``` 23 | 24 | You can also add a border to the text box after instantiation: 25 | 26 | ``` 27 | new TextBox(new TerminalSize(10, 1)).withBorder(Borders.singleLine("Heading")); 28 | ``` 29 | 30 | You can also supply some default text for the text box: 31 | 32 | ``` 33 | new TextBox(new TerminalSize(10, 1), "Here is some default content!"); 34 | ``` 35 | 36 | You can limit what the user can type into the text box by adding a validation pattern via `setValidationPattern`. The following example only allows the user to enter a single number into the text box: 37 | 38 | ``` 39 | new TextBox().setValidationPattern(Pattern.compile("[0-9]")); 40 | ``` 41 | 42 | This will validate the users input on each key press and only allow a single number to be present in the textbox at any given time. 43 | 44 | Partial matchings are not allowed; the whole pattern must match, however, empty lines will always be allowed. When the user tries to modify the content of the `TextBox` in a way that does not match the pattern, the operation will be silently ignored. 45 | 46 | When setting the validation pattern on a given `TextBox`, the existing content will be validated. If the existing content does not match the provided pattern, a new `IllegalStateException` will be thrown. 47 | 48 | ### Screenshot 49 | 50 | ![](screenshots/text_boxes.png) 51 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/win32/WindowsConsoleOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.terminal.win32; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.EOFException; 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | import java.nio.charset.Charset; 8 | 9 | import com.sun.jna.platform.win32.WinNT.HANDLE; 10 | import com.sun.jna.ptr.IntByReference; 11 | 12 | public class WindowsConsoleOutputStream extends OutputStream { 13 | 14 | private final HANDLE hConsoleOutput; 15 | private final Charset decoderCharset; 16 | private final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 17 | 18 | public WindowsConsoleOutputStream(Charset decoder) { 19 | this(Wincon.INSTANCE.GetStdHandle(Wincon.STD_OUTPUT_HANDLE), decoder); 20 | } 21 | 22 | public WindowsConsoleOutputStream(HANDLE hConsoleOutput, Charset decoderCharset) { 23 | this.hConsoleOutput = hConsoleOutput; 24 | this.decoderCharset = decoderCharset; 25 | } 26 | 27 | public HANDLE getHandle() { 28 | return hConsoleOutput; 29 | } 30 | 31 | public Charset getDecoderCharset() { 32 | return decoderCharset; 33 | } 34 | 35 | 36 | @Override 37 | public synchronized void write(int b) { 38 | buffer.write(b); 39 | } 40 | 41 | @Override 42 | public synchronized void write(byte[] b, int off, int len) { 43 | buffer.write(b, off, len); 44 | } 45 | 46 | @Override 47 | public synchronized void flush() throws IOException { 48 | String characters = buffer.toString(decoderCharset.name()); 49 | buffer.reset(); 50 | 51 | IntByReference lpNumberOfCharsWritten = new IntByReference(); 52 | while (!characters.isEmpty()) { 53 | if (!Wincon.INSTANCE.WriteConsole(hConsoleOutput, characters, characters.length(), lpNumberOfCharsWritten, null)) { 54 | throw new EOFException(); 55 | } 56 | characters = characters.substring(lpNumberOfCharsWritten.getValue()); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/WindowListenerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | import com.googlecode.lanterna.TerminalSize; 23 | import com.googlecode.lanterna.input.KeyStroke; 24 | 25 | import java.util.concurrent.atomic.AtomicBoolean; 26 | 27 | /** 28 | * Adapter class for {@link WindowListener} to make it easier to create listeners without having to implement every 29 | * interface method. 30 | */ 31 | public class WindowListenerAdapter implements WindowListener { 32 | @Override 33 | public void onResized(Window window, TerminalSize oldSize, TerminalSize newSize) { 34 | } 35 | 36 | @Override 37 | public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) { 38 | } 39 | 40 | @Override 41 | public void onInput(Window basePane, KeyStroke keyStroke, AtomicBoolean deliverEvent) { 42 | } 43 | 44 | @Override 45 | public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/ScreenInfoAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | 23 | /** 24 | * ScreenInfoAction, a KeyStroke in disguise, this class contains the reported position of the screen cursor. 25 | */ 26 | public class ScreenInfoAction extends KeyStroke { 27 | private final TerminalPosition position; 28 | 29 | /** 30 | * Constructs a ScreenInfoAction based on a location on the screen 31 | * @param position the TerminalPosition reported from terminal 32 | */ 33 | public ScreenInfoAction(TerminalPosition position) { 34 | super(KeyType.CURSOR_LOCATION); 35 | this.position = position; 36 | } 37 | 38 | /** 39 | * The location of the mouse cursor when this event was generated. 40 | * @return Location of the mouse cursor 41 | */ 42 | public TerminalPosition getPosition() { 43 | return position; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "ScreenInfoAction{position=" + position + '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TestShellCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna; 21 | 22 | import java.io.*; 23 | 24 | /** 25 | * 26 | * @author Martin 27 | */ 28 | public class TestShellCommand { 29 | public static void main(String[] args) throws Exception 30 | { 31 | ProcessBuilder pb = new ProcessBuilder(args); 32 | Process process = pb.start(); 33 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 34 | InputStream stdout = process.getInputStream(); 35 | int readByte = stdout.read(); 36 | while(readByte >= 0) { 37 | baos.write(readByte); 38 | readByte = stdout.read(); 39 | } 40 | ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); 41 | BufferedReader reader = new BufferedReader(new InputStreamReader(bais)); 42 | StringBuilder builder = new StringBuilder(); 43 | while(reader.ready()) { 44 | builder.append(reader.readLine()); 45 | } 46 | reader.close(); 47 | System.out.println(builder.toString()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/KeyDecodingProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import java.util.Collection; 22 | 23 | /** 24 | * In order to convert a stream of characters into objects representing keystrokes, we need to apply logic on this 25 | * stream to detect special characters. In lanterna, this is done by using a set of character patterns which are matched 26 | * against the stream until we've found the best match. This interface represents a set of such patterns, a 'profile' 27 | * with is used when decoding the input. There is a default profile, DefaultKeyDecodingProfile, which will probably 28 | * do what you need but you can also extend and define your own patterns. 29 | * 30 | * @author Martin 31 | */ 32 | public interface KeyDecodingProfile { 33 | /** 34 | * Static constant for the ESC key 35 | */ 36 | char ESC_CODE = (char) 0x1b; 37 | 38 | /** 39 | * Returns a collection of character patterns that makes up this profile 40 | * @return Collection of patterns in this profile 41 | */ 42 | Collection getPatterns(); 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue374.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.*; 4 | import com.googlecode.lanterna.screen.Screen; 5 | import com.googlecode.lanterna.screen.TerminalScreen; 6 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 7 | import com.googlecode.lanterna.terminal.Terminal; 8 | 9 | import java.util.Collections; 10 | 11 | public class Issue374 { 12 | 13 | public static void main(String[] args) throws Exception { 14 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 15 | Screen screen = new TerminalScreen(terminal); 16 | screen.startScreen(); 17 | 18 | final BasicWindow window = new BasicWindow("FocusTraversalTest"); 19 | window.setHints(Collections.singletonList(Window.Hint.FULL_SCREEN)); 20 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 21 | 22 | Panel mainPanel = new Panel(new LinearLayout()); 23 | window.setComponent(mainPanel); 24 | 25 | Button disabledInBorder1 = new Button("disabledB1"); 26 | disabledInBorder1.setEnabled(false); 27 | mainPanel.addComponent(disabledInBorder1.withBorder(Borders.singleLine("border"))); 28 | 29 | Button first = new Button("enabled"); 30 | mainPanel.addComponent(first); 31 | 32 | Button disabled = new Button("disabled"); 33 | disabled.setEnabled(false); 34 | mainPanel.addComponent(disabled); 35 | 36 | Button disabledInBorder2 = new Button("disabledB2"); 37 | disabledInBorder2.setEnabled(false); 38 | mainPanel.addComponent(disabledInBorder2.withBorder(Borders.singleLine("border"))); 39 | 40 | Button anotherFocusable = new Button("focusable"); 41 | mainPanel.addComponent(anotherFocusable); 42 | 43 | mainPanel.addComponent(new Button("Button")); 44 | 45 | first.takeFocus(); 46 | gui.addWindowAndWait(window); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/WindowPostRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.graphics.ThemedTextGraphics; 22 | 23 | /** 24 | * Classes implementing this interface can be used along with DefaultWindowManagerTextGUI to put some extra processing 25 | * after a window has been rendered. This is used for making window shadows but can be used for anything. 26 | * @see WindowShadowRenderer 27 | * @author Martin 28 | */ 29 | public interface WindowPostRenderer { 30 | /** 31 | * Called by DefaultWindowTextGUI immediately after a Window has been rendered, to let you do post-processing. 32 | * You will have a TextGraphics object that can draw to the whole screen, so you need to inspect the window's 33 | * position and decorated size to figure out where the bounds are 34 | * @param textGraphics Graphics object you can use to draw with 35 | * @param textGUI TextGUI that we are in 36 | * @param window Window that was just rendered 37 | */ 38 | void postRender( 39 | ThemedTextGraphics textGraphics, 40 | TextGUI textGUI, 41 | Window window); 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue446.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.BasicWindow; 4 | import com.googlecode.lanterna.gui2.Button; 5 | import com.googlecode.lanterna.gui2.Direction; 6 | import com.googlecode.lanterna.gui2.LinearLayout; 7 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 8 | import com.googlecode.lanterna.gui2.Panel; 9 | import com.googlecode.lanterna.gui2.TextBox; 10 | import com.googlecode.lanterna.gui2.WindowBasedTextGUI; 11 | import com.googlecode.lanterna.gui2.menu.Menu; 12 | import com.googlecode.lanterna.gui2.menu.MenuBar; 13 | import com.googlecode.lanterna.gui2.menu.MenuItem; 14 | import com.googlecode.lanterna.screen.TerminalScreen; 15 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 16 | import com.googlecode.lanterna.terminal.Terminal; 17 | 18 | import java.io.IOException; 19 | 20 | public class Issue446 { 21 | 22 | public static void main(String[] args) throws IOException { 23 | DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory(); 24 | Terminal terminal = terminalFactory.createTerminal(); 25 | TerminalScreen screen = new TerminalScreen(terminal); 26 | screen.startScreen(); 27 | WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 28 | textGUI.addWindowAndWait(buildWindow()); 29 | } 30 | 31 | public static BasicWindow buildWindow() { 32 | MenuBar menuBar = new MenuBar(); 33 | menuBar.add(new Menu("Menu 1").add(new MenuItem("MenuItem 1.1"))); 34 | 35 | BasicWindow basicWindow = new BasicWindow(); 36 | 37 | TextBox textBox = new TextBox("A"); 38 | 39 | Panel mainPanel = new Panel(new LinearLayout(Direction.VERTICAL)); 40 | mainPanel.addComponent(textBox); 41 | mainPanel.addComponent(new Button("Quit", basicWindow::close)); 42 | 43 | basicWindow.setComponent(mainPanel); 44 | basicWindow.setMenuBar(menuBar); 45 | return basicWindow; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/graphics/RedundantThemeDeclarationsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.graphics; 20 | 21 | import com.googlecode.lanterna.bundle.LanternaThemes; 22 | import org.junit.Assert; 23 | import org.junit.Test; 24 | 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | public class RedundantThemeDeclarationsTest { 29 | @Test 30 | public void noThemeDeclarationsAreRedundant() { 31 | for(String theme: LanternaThemes.getRegisteredThemes()) { 32 | Theme registeredTheme = LanternaThemes.getRegisteredTheme(theme); 33 | List redundantDeclarations = ((PropertyTheme) registeredTheme).findRedundantDeclarations(); 34 | try { 35 | Assert.assertEquals(Collections.emptyList(), redundantDeclarations); 36 | } 37 | catch(AssertionError e) { 38 | System.out.println("Redundant definitions in theme '" + theme + "':"); 39 | for(String declaration: redundantDeclarations) { 40 | System.out.println(declaration); 41 | } 42 | throw e; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/ansi/FixedTerminalSizeProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna.terminal.ansi; 21 | 22 | import com.googlecode.lanterna.TerminalSize; 23 | 24 | /** 25 | * Using this terminal size provider, your terminal will be set to a fixed size and will never receive any resize 26 | * events. Of course if the physical terminal is resized, in reality it will have a different size, but the application 27 | * won't know about it. The size reported to the user is always the size attached to this object. 28 | * @author martin 29 | */ 30 | public class FixedTerminalSizeProvider implements UnixTerminalSizeQuerier { 31 | private final TerminalSize size; 32 | 33 | /** 34 | * Creating a {@code FixedTerminalSizeProvider} set to a particular size that it will always report whenever the 35 | * associated {@code Terminal} interface queries. 36 | * @param size Size the terminal should be statically initialized to 37 | */ 38 | public FixedTerminalSizeProvider(TerminalSize size) { 39 | this.size = size; 40 | } 41 | 42 | @Override 43 | public TerminalSize queryTerminalSize() { 44 | return size; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/table/DefaultTableHeaderRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.table; 20 | 21 | import com.googlecode.lanterna.TerminalTextUtils; 22 | import com.googlecode.lanterna.TerminalSize; 23 | import com.googlecode.lanterna.graphics.ThemeDefinition; 24 | import com.googlecode.lanterna.gui2.TextGUIGraphics; 25 | 26 | /** 27 | * Default implementation of {@code TableHeaderRenderer} 28 | * @author Martin 29 | */ 30 | public class DefaultTableHeaderRenderer implements TableHeaderRenderer { 31 | @Override 32 | public TerminalSize getPreferredSize(Table table, String label, int columnIndex) { 33 | if(label == null) { 34 | return TerminalSize.ZERO; 35 | } 36 | return new TerminalSize(TerminalTextUtils.getColumnWidth(label), 1); 37 | } 38 | 39 | @Override 40 | public void drawHeader(Table table, String label, int index, TextGUIGraphics textGUIGraphics) { 41 | ThemeDefinition themeDefinition = table.getThemeDefinition(); 42 | textGUIGraphics.applyThemeStyle(themeDefinition.getCustom("HEADER", themeDefinition.getNormal())); 43 | textGUIGraphics.putString(0, 0, label); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/WindowListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | import com.googlecode.lanterna.TerminalSize; 23 | 24 | /** 25 | * Extended {@link BasePaneListener} for {@link Window} that exposes additional events that are specific to windows 26 | */ 27 | public interface WindowListener extends BasePaneListener { 28 | /** 29 | * Called whenever the window's size has changed, no matter if it was done by the window manager or the user 30 | * @param window Window that was resized 31 | * @param oldSize Previous size of the window 32 | * @param newSize New size of the window 33 | */ 34 | void onResized(Window window, TerminalSize oldSize, TerminalSize newSize); 35 | 36 | /** 37 | * Called whenever the window's position has changed, no matter if it was done by the window manager or the user 38 | * @param window Window that was repositioned 39 | * @param oldPosition Previous position of the window 40 | * @param newPosition New position of the window 41 | */ 42 | void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/TerminalResizeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | 23 | /** 24 | * Listener interface that can be used to be alerted on terminal resizing 25 | */ 26 | public interface TerminalResizeListener { 27 | /** 28 | * The terminal has changed its size, most likely because the user has resized the window. This callback is 29 | * invoked by something inside the lanterna library, it could be a signal handler thread, it could be the AWT 30 | * thread, it could be something else, so please be careful with what kind of operation you do in here. Also, 31 | * make sure not to take too long before returning. Best practice would be to update an internal status in your 32 | * program to mark that the terminal has been resized (possibly along with the new size) and then in your main 33 | * loop you deal with this at the beginning of each redraw. 34 | * @param terminal Terminal that was resized 35 | * @param newSize Size of the terminal after the resize 36 | */ 37 | @SuppressWarnings("UnusedParameters") 38 | void onResized(Terminal terminal, TerminalSize newSize); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/virtual/VirtualTerminalListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal.virtual; 20 | 21 | import com.googlecode.lanterna.terminal.Terminal; 22 | import com.googlecode.lanterna.terminal.TerminalResizeListener; 23 | 24 | /** 25 | * Listener class for {@link VirtualTerminal} that allows you to receive callbacks on certain events. Please note that 26 | * while this extends {@link TerminalResizeListener} and can be attached to a {@link VirtualTerminal} through 27 | * {@link com.googlecode.lanterna.terminal.Terminal#addResizeListener(TerminalResizeListener)}, in that case only the 28 | * resize event will fire on the listener. 29 | */ 30 | public interface VirtualTerminalListener extends TerminalResizeListener { 31 | /** 32 | * Called when the {@link Terminal#flush()} method is invoked on the {@link VirtualTerminal} 33 | */ 34 | void onFlush(); 35 | 36 | /** 37 | * Called when the {@link Terminal#bell()} method is invoked on the {@link VirtualTerminal} 38 | */ 39 | void onBell(); 40 | 41 | /** 42 | * Called when the {@link Terminal#close()} method is invoked on the {@link VirtualTerminal} 43 | */ 44 | void onClose(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/GUIBackdrop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | import com.googlecode.lanterna.graphics.ThemeDefinition; 23 | 24 | /** 25 | * Special component that is by default displayed as the background of a text gui unless you override it with something 26 | * else. Themes can control how this backdrop is drawn, the normal is one solid color. 27 | */ 28 | public class GUIBackdrop extends EmptySpace { 29 | @Override 30 | protected ComponentRenderer createDefaultRenderer() { 31 | return new ComponentRenderer() { 32 | 33 | @Override 34 | public TerminalSize getPreferredSize(EmptySpace component) { 35 | return TerminalSize.ONE; 36 | } 37 | 38 | @Override 39 | public void drawComponent(TextGUIGraphics graphics, EmptySpace component) { 40 | ThemeDefinition themeDefinition = component.getTheme().getDefinition(GUIBackdrop.class); 41 | graphics.applyThemeStyle(themeDefinition.getNormal()); 42 | graphics.fill(themeDefinition.getCharacter("BACKGROUND", ' ')); 43 | } 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/table/TableCellBorderStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.table; 20 | 21 | /** 22 | * Describing how table cells are separated when drawn 23 | */ 24 | public enum TableCellBorderStyle { 25 | /** 26 | * There is no separation between table cells, they are drawn immediately next to each other 27 | */ 28 | NONE(0), 29 | /** 30 | * There is a single space of separation between the cells, drawn as a single line 31 | */ 32 | SINGLE_LINE(1), 33 | /** 34 | * There is a single space of separation between the cells, drawn as a double line 35 | */ 36 | DOUBLE_LINE(1), 37 | /** 38 | * There is a single space of separation between the cells, kept empty 39 | */ 40 | EMPTY_SPACE(1), 41 | ; 42 | 43 | private final int size; 44 | 45 | TableCellBorderStyle(int size) { 46 | this.size = size; 47 | } 48 | 49 | /** 50 | * Returns the number of rows (for vertical borders) or columns (for horizontal borders) this table cell border will 51 | * take up when used. 52 | * @return Size of the border, in rows or columns depending on the context 53 | */ 54 | int getSize() { 55 | return size; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/gui2/WindowManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.gui2; 2 | 3 | import com.googlecode.lanterna.TerminalPosition; 4 | import com.googlecode.lanterna.TerminalSize; 5 | import com.googlecode.lanterna.input.KeyStroke; 6 | import com.googlecode.lanterna.input.KeyType; 7 | import com.googlecode.lanterna.screen.Screen; 8 | 9 | import java.io.IOException; 10 | 11 | public class WindowManagerTest extends TestBase { 12 | public static void main(String[] args) throws IOException, InterruptedException { 13 | new WindowManagerTest().run(args); 14 | } 15 | 16 | @Override 17 | protected MultiWindowTextGUI createTextGUI(Screen screen) { 18 | return new MultiWindowTextGUI(new SeparateTextGUIThread.Factory(), screen, new CustomWindowManager()); 19 | } 20 | 21 | @Override 22 | public void init(WindowBasedTextGUI textGUI) { 23 | final Window mainWindow = new BasicWindow("Window Manager Test"); 24 | Panel contentArea = new Panel(); 25 | contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL)); 26 | contentArea.addComponent(new EmptySpace(TerminalSize.ONE)); 27 | contentArea.addComponent(new Button("Close", new Runnable() { 28 | @Override 29 | public void run() { 30 | mainWindow.close(); 31 | } 32 | })); 33 | mainWindow.setComponent(contentArea); 34 | textGUI.addWindow(mainWindow); 35 | } 36 | 37 | private static class CustomWindowManager extends DefaultWindowManager { 38 | @Override 39 | protected void prepareWindow(TerminalSize screenSize, Window window) { 40 | super.prepareWindow(screenSize, window); 41 | 42 | window.setDecoratedSize(window.getPreferredSize().withRelative(12, 10)); 43 | window.setPosition(new TerminalPosition( 44 | screenSize.getColumns() - window.getDecoratedSize().getColumns() - 1, 45 | screenSize.getRows() - window.getDecoratedSize().getRows() - 1 46 | )); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/ResetAllTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna.terminal; 21 | 22 | import com.googlecode.lanterna.SGR; 23 | import com.googlecode.lanterna.TestTerminalFactory; 24 | import com.googlecode.lanterna.TextColor; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * 30 | * @author martin 31 | */ 32 | public class ResetAllTest { 33 | public static void main(String[] args) throws InterruptedException, IOException { 34 | Terminal terminal = new TestTerminalFactory(args).createTerminal(); 35 | terminal.enterPrivateMode(); 36 | terminal.clearScreen(); 37 | terminal.setCursorPosition(10, 5); 38 | terminal.putCharacter('H'); 39 | terminal.putCharacter('e'); 40 | terminal.enableSGR(SGR.BOLD); 41 | terminal.putCharacter('l'); 42 | terminal.setForegroundColor(TextColor.ANSI.CYAN); 43 | terminal.putCharacter('l'); 44 | terminal.enableSGR(SGR.REVERSE); 45 | terminal.putCharacter('o'); 46 | terminal.resetColorAndSGR(); 47 | terminal.putCharacter('!'); 48 | terminal.setCursorPosition(0, 0); 49 | terminal.flush(); 50 | 51 | Thread.sleep(5000); 52 | terminal.exitPrivateMode(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/BlinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna.terminal; 21 | 22 | import com.googlecode.lanterna.SGR; 23 | import com.googlecode.lanterna.TestTerminalFactory; 24 | import com.googlecode.lanterna.TextColor; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * 30 | * @author Martin 31 | */ 32 | public class BlinkTest { 33 | public static void main(String[] args) throws IOException { 34 | Terminal rawTerminal = new TestTerminalFactory(args).createTerminal(); 35 | rawTerminal.enterPrivateMode(); 36 | rawTerminal.clearScreen(); 37 | rawTerminal.setForegroundColor(TextColor.ANSI.RED); 38 | rawTerminal.enableSGR(SGR.BLINK); 39 | rawTerminal.setCursorPosition(10, 10); 40 | rawTerminal.putCharacter('H'); 41 | rawTerminal.putCharacter('e'); 42 | rawTerminal.putCharacter('l'); 43 | rawTerminal.putCharacter('l'); 44 | rawTerminal.putCharacter('o'); 45 | rawTerminal.putCharacter('!'); 46 | rawTerminal.setCursorPosition(0, 0); 47 | rawTerminal.flush(); 48 | try { 49 | Thread.sleep(5000); 50 | } 51 | catch(InterruptedException e) {} 52 | rawTerminal.exitPrivateMode(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/NormalCharacterPattern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Character pattern that matches one character as one KeyStroke with the character that was read 25 | * 26 | * @author Martin, Andreas 27 | */ 28 | public class NormalCharacterPattern implements CharacterPattern { 29 | @Override 30 | public Matching match(List seq) { 31 | if (seq.size() != 1) { 32 | return null; // nope 33 | } 34 | char ch = seq.get(0); 35 | if (isPrintableChar(ch)) { 36 | KeyStroke ks = new KeyStroke(ch, false, false); 37 | return new Matching( ks ); 38 | } else { 39 | return null; // nope 40 | } 41 | } 42 | 43 | /** 44 | * From http://stackoverflow.com/questions/220547/printable-char-in-java 45 | * @param c character to test 46 | * @return True if this is a 'normal', printable character, false otherwise 47 | */ 48 | private static boolean isPrintableChar(char c) { 49 | if (Character.isISOControl(c)) { return false; } 50 | Character.UnicodeBlock block = Character.UnicodeBlock.of(c); 51 | return block != null && block != Character.UnicodeBlock.SPECIALS; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/screen/ScreenTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Svatopluk Dedic 18 | */ 19 | package com.googlecode.lanterna.screen; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | 23 | /** 24 | * Mixin interface of an area or location object that that provides translation to screen (absolute) 25 | * coordinates. 26 | * 27 | * @author sdedic 28 | */ 29 | public interface ScreenTranslator { 30 | /** 31 | * Returns the screen on terminal coordinates of the given position within the implementing area. 32 | * The result value can be used with {@link Screen} object,or its {@link Screen#newTextGraphics()}, 33 | * it accommodates all coordinate translations from the chain of TextGraphics. 34 | * If `pos' is {@code null}, the method returns screen coordinates of origin (usually top-left corner) 35 | * of this area object. 36 | *

37 | * Will return {@code null}, if the position is outside area implementing ScreenTranslator. 38 | * 39 | * @param pos the position to translate, or {@code null} to convert position of top-left corner of this area 40 | * @return screen coordinates of the given position, or origin (usually top-left corner) of this area, if `pos' 41 | * is {@code null}. 42 | */ 43 | public TerminalPosition toScreenPosition(TerminalPosition pos); 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue249.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | * Author celyo (github) 19 | */ 20 | package com.googlecode.lanterna.issue; 21 | 22 | import java.io.IOException; 23 | 24 | import com.googlecode.lanterna.TerminalSize; 25 | import com.googlecode.lanterna.TextColor; 26 | import com.googlecode.lanterna.gui2.*; 27 | import com.googlecode.lanterna.screen.*; 28 | import com.googlecode.lanterna.terminal.*; 29 | 30 | public class Issue249 { 31 | public static void main(String[] args) throws IOException { 32 | 33 | // Setup terminal and screen layers 34 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 35 | Screen screen = new TerminalScreen(terminal); 36 | screen.startScreen(); 37 | 38 | TerminalSize screenSize = screen.getTerminalSize(); 39 | 40 | // Create panel to hold components 41 | Panel panel = new Panel(); 42 | panel.setPreferredSize(screenSize); 43 | 44 | // Create window to hold the panel 45 | BasicWindow window = new BasicWindow(); 46 | window.setComponent(panel); 47 | 48 | // Create gui and start gui 49 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 50 | gui.addWindowAndWait(window); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/screen/WrapBehaviour.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.screen; 20 | 21 | /** 22 | * What to do when line length is exceeded. 23 | * 24 | * @author avl42 25 | */ 26 | public enum WrapBehaviour { 27 | /** 28 | * Never ever leave current line. 29 | */ 30 | SINGLE_LINE(false,false,false), 31 | /** 32 | * Don't wrap lines automatically, but honor explicit line-feeds. 33 | */ 34 | CLIP(true,false,false), 35 | /** 36 | * Wrap at any character boundaries. 37 | */ 38 | CHAR(true,true,false), 39 | /** 40 | * Only wrap at word boundaries. If a single word exceeds line 41 | * length, it will still be broken to line length. 42 | */ 43 | WORD(true,true,true); 44 | 45 | private final boolean allowLineFeed, autoWrap, keepWords; 46 | 47 | WrapBehaviour(boolean allowLineFeed,boolean autoWrap,boolean keepWords) { 48 | this.allowLineFeed = allowLineFeed; 49 | this.autoWrap = autoWrap; 50 | this.keepWords = keepWords; 51 | } 52 | 53 | public boolean allowLineFeed() { 54 | return allowLineFeed; 55 | } 56 | public boolean autoWrap() { 57 | return autoWrap; 58 | } 59 | public boolean keepWords() { 60 | return keepWords; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue392.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.issue; 2 | 3 | import com.googlecode.lanterna.gui2.BasicWindow; 4 | import com.googlecode.lanterna.gui2.Button; 5 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 6 | import com.googlecode.lanterna.gui2.TextGUIThread; 7 | import com.googlecode.lanterna.screen.TerminalScreen; 8 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 9 | import com.googlecode.lanterna.terminal.Terminal; 10 | import java.io.IOException; 11 | 12 | public class Issue392 { 13 | private static MultiWindowTextGUI textGUI; 14 | 15 | public static void main(String[] args) throws IOException { 16 | DefaultTerminalFactory terminalFactory = new DefaultTerminalFactory(); 17 | Terminal terminal = terminalFactory.createTerminal(); 18 | TerminalScreen screen = new TerminalScreen(terminal); 19 | screen.startScreen(); 20 | textGUI = new MultiWindowTextGUI(screen); 21 | setExceptionHandler(); 22 | BasicWindow window = new BasicWindow(); 23 | 24 | Button button = new Button("test"); 25 | button.addListener(b -> { 26 | setExceptionHandler(); 27 | throw new RuntimeException("This should be caught in the uncaght exception handler!"); 28 | }); 29 | window.setComponent(button); 30 | 31 | textGUI.addWindowAndWait(window); 32 | screen.stopScreen(); 33 | } 34 | 35 | private static void setExceptionHandler() { 36 | textGUI.getGUIThread().setExceptionHandler(new TextGUIThread.ExceptionHandler() { 37 | 38 | private boolean handleException(Exception e) { 39 | System.err.println("### Caught!"); 40 | e.printStackTrace(); 41 | return false; 42 | } 43 | 44 | @Override 45 | public boolean onIOException(IOException e) { 46 | return handleException(e); 47 | } 48 | 49 | @Override 50 | public boolean onRuntimeException(RuntimeException e) { 51 | return handleException(e); 52 | } 53 | }); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /docs/examples/gui/hello_world.md: -------------------------------------------------------------------------------- 1 | Hello World - GUI Example 2 | --- 3 | 4 | In this initial example, we take a look at a basic GUI window which contains a couple of components. 5 | There is little to no interactivity in this example, however, it should be a good starting point as it demonstrates 6 | how easy it is to build up interfaces. If you're familiar with Java Swing, you'll feel right at home with Lanterna. 7 | 8 | ``` 9 | import com.googlecode.lanterna.TerminalSize; 10 | import com.googlecode.lanterna.TextColor; 11 | import com.googlecode.lanterna.gui2.*; 12 | import com.googlecode.lanterna.screen.Screen; 13 | import com.googlecode.lanterna.screen.TerminalScreen; 14 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 15 | import com.googlecode.lanterna.terminal.Terminal; 16 | 17 | import java.io.IOException; 18 | 19 | public class HelloWorld { 20 | public static void main(String[] args) throws IOException { 21 | 22 | // Setup terminal and screen layers 23 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 24 | Screen screen = new TerminalScreen(terminal); 25 | screen.startScreen(); 26 | 27 | // Create panel to hold components 28 | Panel panel = new Panel(); 29 | panel.setLayoutManager(new GridLayout(2)); 30 | 31 | panel.addComponent(new Label("Forename")); 32 | panel.addComponent(new TextBox()); 33 | 34 | panel.addComponent(new Label("Surname")); 35 | panel.addComponent(new TextBox()); 36 | 37 | panel.addComponent(new EmptySpace(new TerminalSize(0,0))); // Empty space underneath labels 38 | panel.addComponent(new Button("Submit")); 39 | 40 | // Create window to hold the panel 41 | BasicWindow window = new BasicWindow(); 42 | window.setComponent(panel); 43 | 44 | // Create gui and start gui 45 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); 46 | gui.addWindowAndWait(window); 47 | 48 | } 49 | } 50 | ``` 51 | 52 | ### Screenshot 53 | 54 | Here's a screenshot of the above code, running: 55 | 56 | ![](screenshots/hello_world.png) -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/graphics/ThemeStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.graphics; 20 | 21 | import com.googlecode.lanterna.SGR; 22 | import com.googlecode.lanterna.TextColor; 23 | 24 | import java.util.EnumSet; 25 | 26 | /** 27 | * ThemeStyle is the lowest entry in the theme hierarchy, containing the actual colors and SGRs to use. When drawing a 28 | * component, you would pick out a {@link ThemeDefinition} that applies to the whole component and then choose to 29 | * activate individual {@link ThemeStyle}s when drawing the different parts of the component. 30 | * @author Martin 31 | */ 32 | public interface ThemeStyle { 33 | /** 34 | * Returns the foreground color associated with this style 35 | * @return foreground color associated with this style 36 | */ 37 | TextColor getForeground(); 38 | 39 | /** 40 | * Returns the background color associated with this style 41 | * @return background color associated with this style 42 | */ 43 | TextColor getBackground(); 44 | 45 | /** 46 | * Returns the set of SGR flags associated with this style. This {@code EnumSet} is either unmodifiable or a copy so 47 | * altering it will not change the theme in any way. 48 | * @return SGR flags associated with this style 49 | */ 50 | EnumSet getSGRs(); 51 | } 52 | -------------------------------------------------------------------------------- /docs/examples/gui/text_input_dialogs.md: -------------------------------------------------------------------------------- 1 | Text Input Dialogs 2 | --- 3 | 4 | Text input dialogs are pop-up windows that allow user input. 5 | 6 | To create an input dialog, as with all dialogs, you'll need to create and pass in a `WindowBasedTextGUI`: 7 | 8 | ``` 9 | // Setup terminal and screen layers 10 | Terminal terminal = new DefaultTerminalFactory().createTerminal(); 11 | Screen screen = new TerminalScreen(terminal); 12 | screen.startScreen(); 13 | 14 | // Setup WindowBasedTextGUI for dialogs 15 | final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen); 16 | ``` 17 | 18 | In the following example, an input box is shown to the user when the button is clicked and whatever is typed into the input dialog is stored in the variable `input`: 19 | 20 | ``` 21 | panel.addComponent(new Button("Test", new Runnable() { 22 | @Override 23 | public void run() { 24 | String input = TextInputDialog.showDialog(textGUI, "Title", "This is the description", "Initial content"); 25 | } 26 | })); 27 | ``` 28 | 29 | As you can see, it's incredibly easy to create and show an input dialog: 30 | 31 | ``` 32 | TextInputDialog.showDialog(textGUI, "Title", "This is the description", "Initial content"); 33 | ``` 34 | 35 | You can also use a `TextInputDialogBuilder` to build up and show a text dialog: 36 | 37 | ``` 38 | new TextInputDialogBuilder() 39 | .setTitle("Title") 40 | .setDescription("Enter a single number") 41 | .setValidationPattern(Pattern.compile("[0-9]"), "You didn't enter a single number!") 42 | .build() 43 | .showDialog(textGUI); 44 | ``` 45 | 46 | The `TextInputDialog` also supports multi-line text input: 47 | 48 | ``` 49 | String result = new TextInputDialogBuilder() 50 | .setTitle("Multi-line editor") 51 | .setTextBoxSize(new TerminalSize(35, 5)) 52 | .build() 53 | .showDialog(textGUI); 54 | ``` 55 | 56 | By using a builder, you can set a validation pattern, as shown above, which spits out an error if the user tries to pass in anything that doesn't match the provided regex. 57 | 58 | ### Screenshots 59 | 60 | #### Single-line: 61 | 62 | ![](screenshots/text_input_dialogs.png) 63 | 64 | #### Multi-line: 65 | 66 | ![](screenshots/multiline_input_dialogs.png) -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/graphics/Scrollable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.graphics; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Describes an area that can be 'scrolled', by moving a range of lines up or down. Certain terminals will implement 25 | * this through extensions and are much faster than if lanterna tries to manually erase and re-print the text. 26 | * 27 | * @author Andreas 28 | */ 29 | public interface Scrollable { 30 | /** 31 | * Scroll a range of lines of this Scrollable according to given distance. 32 | * 33 | * If scroll-range is empty (firstLine > lastLine || distance == 0) then 34 | * this method does nothing. 35 | * 36 | * Lines that are scrolled away from are cleared. 37 | * 38 | * If absolute value of distance is equal or greater than number of lines 39 | * in range, then all lines within the range will be cleared. 40 | * 41 | * @param firstLine first line of the range to be scrolled (top line is 0) 42 | * @param lastLine last (inclusive) line of the range to be scrolled 43 | * @param distance if > 0: move lines up, else if < 0: move lines down. 44 | * @throws IOException If there was an I/O error when running the operation 45 | */ 46 | void scrollLines(int firstLine, int lastLine, int distance) throws IOException; 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/terminal/swing/TerminalInputMethodRequests.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.terminal.swing; 2 | 3 | import com.googlecode.lanterna.TerminalPosition; 4 | 5 | import java.awt.*; 6 | import java.awt.font.TextHitInfo; 7 | import java.awt.im.InputMethodRequests; 8 | import java.text.AttributedCharacterIterator; 9 | 10 | class TerminalInputMethodRequests implements InputMethodRequests { 11 | 12 | private Component owner; 13 | private GraphicalTerminalImplementation terminalImplementation; 14 | 15 | public TerminalInputMethodRequests(Component owner, GraphicalTerminalImplementation terminalImplementation) { 16 | this.owner = owner; 17 | this.terminalImplementation = terminalImplementation; 18 | } 19 | 20 | @Override 21 | public Rectangle getTextLocation(TextHitInfo offset) { 22 | Point location = owner.getLocationOnScreen(); 23 | TerminalPosition cursorPosition = terminalImplementation.getCursorPosition(); 24 | 25 | int offsetX = cursorPosition.getColumn() * terminalImplementation.getFontWidth(); 26 | int offsetY = cursorPosition.getRow() * terminalImplementation.getFontHeight() + terminalImplementation.getFontHeight(); 27 | 28 | return new Rectangle(location.x + offsetX, location.y + offsetY, 0, 0); 29 | } 30 | 31 | @Override 32 | public TextHitInfo getLocationOffset(int x, int y) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public int getInsertPositionOffset() { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex, AttributedCharacterIterator.Attribute[] attributes) { 43 | return null; 44 | } 45 | 46 | @Override 47 | public int getCommittedTextLength() { 48 | return 0; 49 | } 50 | 51 | @Override 52 | public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] attributes) { 53 | return null; 54 | } 55 | 56 | @Override 57 | public AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] attributes) { 58 | return null; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/bundle/DefaultThemeTest.java: -------------------------------------------------------------------------------- 1 | package com.googlecode.lanterna.bundle; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.lang.reflect.Field; 10 | import java.util.Scanner; 11 | 12 | /** 13 | * To ensure our bundled default theme matches the theme definition file in resources 14 | */ 15 | public class DefaultThemeTest { 16 | @Test 17 | public void ensureResourceFileDefaultTestIsTheSameAsTheEmbeddedTest() throws NoSuchFieldException, IllegalAccessException, IOException { 18 | String embeddedDefinition = getEmbeddedDefinition(); 19 | String resourceDefinition = getResourceDefinition(); 20 | Assert.assertEquals(resourceDefinition, embeddedDefinition); 21 | } 22 | 23 | private String getEmbeddedDefinition() throws NoSuchFieldException, IllegalAccessException { 24 | Field definitionField = DefaultTheme.class.getDeclaredField("definition"); 25 | definitionField.setAccessible(true); 26 | return (String)definitionField.get(null); 27 | } 28 | 29 | private String getResourceDefinition() throws IOException { 30 | ClassLoader classLoader = DefaultThemeTest.class.getClassLoader(); 31 | InputStream resourceAsStream = null; 32 | try { 33 | resourceAsStream = classLoader.getResourceAsStream("default-theme.properties"); 34 | if (resourceAsStream == null) { 35 | resourceAsStream = new FileInputStream("src/main/resources/default-theme.properties"); 36 | } 37 | 38 | // https://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string 39 | Scanner s = new Scanner(resourceAsStream).useDelimiter("\\A"); 40 | String definition = s.hasNext() ? s.next() : ""; 41 | 42 | // Normalize line endings to LF 43 | definition = definition.replace("\r\n", "\n"); 44 | 45 | return definition; 46 | } 47 | finally { 48 | if(resourceAsStream != null) { 49 | resourceAsStream.close(); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/Border.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalPosition; 22 | import com.googlecode.lanterna.TerminalSize; 23 | 24 | /** 25 | * Main interface for different border classes, with additional methods to help lanterna figure out the size and offset 26 | * of components wrapped by borders. 27 | * @author Martin 28 | */ 29 | public interface Border extends Container, Composite { 30 | interface BorderRenderer extends ComponentRenderer { 31 | /** 32 | * How large is the offset from the top left corner of the border to the top left corner of the wrapped component? 33 | * @return Position of the wrapped components top left position, relative to the top left corner of the border 34 | */ 35 | TerminalPosition getWrappedComponentTopLeftOffset(); 36 | 37 | /** 38 | * Given a total size of the border composite and it's wrapped component, how large would the actual wrapped 39 | * component be? 40 | * @param borderSize Size to calculate for, this should be the total size of the border and the inner component 41 | * @return Size of the inner component if the total size of inner + border is borderSize 42 | */ 43 | TerminalSize getWrappedComponentSize(TerminalSize borderSize); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue95.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.issue; 20 | 21 | import com.googlecode.lanterna.screen.TerminalScreen; 22 | import com.googlecode.lanterna.screen.Screen; 23 | import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame; 24 | import com.googlecode.lanterna.terminal.swing.TerminalEmulatorAutoCloseTrigger; 25 | 26 | import java.io.IOException; 27 | import javax.swing.WindowConstants; 28 | 29 | /** 30 | * 31 | * @author martin 32 | */ 33 | public class Issue95 { 34 | public static void main(String[] args) throws InterruptedException, IOException { 35 | SwingTerminalFrame terminal = new SwingTerminalFrame(TerminalEmulatorAutoCloseTrigger.CLOSE_ON_EXIT_PRIVATE_MODE); 36 | terminal.setCursorVisible(false); 37 | 38 | Screen screen = new TerminalScreen(terminal); 39 | screen.startScreen(); 40 | 41 | terminal.setTitle("Freedom: An arena-battle roguelike"); 42 | terminal.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 43 | terminal.setResizable(false); 44 | terminal.setVisible(true); 45 | 46 | while(screen.pollInput() == null) { 47 | if(screen.doResizeIfNecessary() != null) { 48 | screen.refresh(); 49 | } 50 | Thread.sleep(100); 51 | } 52 | screen.stopScreen(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /docs/GUIGuideStartTheGUI.md: -------------------------------------------------------------------------------- 1 | # Start the GUI 2 | ## Getting the `WindowBasedTextGUI` object ### 3 | Lanterna has a basic `TextGUI` interface and a slightly more extended `WindowBasedTextGUI` interface you will be using 4 | when working with the GUI system built-in. In reality though, there is only one concrete implementation at this point, 5 | `MultiWindowTextGUI` so there isn't really any case where you would use `TextGUI` over `WindowBasedTextGUI`. 6 | 7 | To instantiate, you need a `Screen` object that the GUI will render too: 8 | 9 | WindowBasedTextGUI gui = new MultiWindowTextGUI(screen); 10 | 11 | ## Threading concerns 12 | Usually GUI APIs have threading issues of some sort. Many simply give up and declare that all modifications have to be 13 | done on a designated "GUI thread". This is generally a reasonably approach and while Lanterna doesn't enforce it 14 | (internal API is synchronized on a best-effort basis), it's recommended. When you create the text GUI in your code, 15 | you can make a decision about if you want Lanterna to create its own GUI thread that will be responsible for all the drawing 16 | operations or if you want your own thread to do this. The managed GUI thread is slightly more complicated so in this 17 | guide we are going to use the latter. While most of the API remains the same (the separate GUI thread approach will 18 | require manually starting and stopping), whenever there are differences these will be pointed out. 19 | 20 | By default, when you create a `MultiWindowTextGUI` like in the previous section, Lanterna will use the same-thread 21 | strategy. 22 | 23 | ## Starting the GUI 24 | Unlike `Screen`, the `TextGUI` interface doesn't have start or stop methods. It will simply use the `Screen` object you 25 | pass in as-is. Because of this, you'll want to start the screen before attempting to draw anything with the GUI. 26 | 27 | Terminal term = new DefaultTerminalFactory().createTerminal(); 28 | Screen screen = new TerminalScreen(term); 29 | WindowBasedTextGUI gui = new MultiWindowTextGUI(screen); 30 | screen.startScreen(); 31 | 32 | // use GUI here until the GUI wants to exit 33 | 34 | screen.stopScreen(); 35 | 36 | ## Next 37 | Continue to [Basic windows](GUIGuideWindows.md) 38 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.InputStream; 23 | import java.io.PrintWriter; 24 | import java.io.StringWriter; 25 | import java.net.URL; 26 | 27 | public class TestUtils { 28 | private TestUtils() {} 29 | 30 | public static String downloadGPL() { 31 | try { 32 | URL url = new URL("http://www.gnu.org/licenses/gpl.txt"); 33 | try (InputStream inputStream = url.openStream()) { 34 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 35 | byte[] buffer = new byte[32 * 1024]; 36 | int readBytes = 0; 37 | while (readBytes != -1) { 38 | readBytes = inputStream.read(buffer); 39 | if (readBytes > 0) { 40 | byteArrayOutputStream.write(buffer, 0, readBytes); 41 | } 42 | } 43 | return new String(byteArrayOutputStream.toByteArray()); 44 | } 45 | } 46 | catch(Exception e) { 47 | StringWriter stringWriter = new StringWriter(); 48 | PrintWriter printWriter = new PrintWriter(stringWriter); 49 | e.printStackTrace(printWriter); 50 | return stringWriter.toString(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/screen/ScreenTextGraphics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.screen; 20 | import com.googlecode.lanterna.TextCharacter; 21 | import com.googlecode.lanterna.TerminalSize; 22 | import com.googlecode.lanterna.graphics.AbstractTextGraphics; 23 | import com.googlecode.lanterna.graphics.TextGraphics; 24 | 25 | /** 26 | * This is an implementation of TextGraphics that targets the output to a Screen. The ScreenTextGraphics object is valid 27 | * after screen resizing. 28 | * @author Martin 29 | */ 30 | class ScreenTextGraphics extends AbstractTextGraphics { 31 | private final Screen screen; 32 | 33 | /** 34 | * Creates a new {@code ScreenTextGraphics} targeting the specified screen 35 | * @param screen Screen we are targeting 36 | */ 37 | ScreenTextGraphics(Screen screen) { 38 | super(); 39 | this.screen = screen; 40 | } 41 | 42 | @Override 43 | public TextGraphics setCharacter(int columnIndex, int rowIndex, TextCharacter textCharacter) { 44 | //Let the screen do culling 45 | screen.setCharacter(columnIndex, rowIndex, textCharacter); 46 | return this; 47 | } 48 | 49 | @Override 50 | public TextCharacter getCharacter(int column, int row) { 51 | return screen.getBackCharacter(column, row); 52 | } 53 | 54 | @Override 55 | public TerminalSize getSize() { 56 | return screen.getTerminalSize(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/CtrlAndCharacterPattern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Character pattern that matches characters pressed while CTRL key is held down 25 | * 26 | * @author Martin, Andreas 27 | */ 28 | public class CtrlAndCharacterPattern implements CharacterPattern { 29 | @Override 30 | public Matching match(List seq) { 31 | int size = seq.size(); char ch = seq.get(0); 32 | if (size != 1) { 33 | return null; // nope 34 | } 35 | if (ch < 32) { 36 | // Control-chars: exclude lf,cr,Tab,Esc(^[), but still include ^\, ^], ^^ and ^_ 37 | char ctrlCode; 38 | switch (ch) { 39 | case '\n': case '\r': case '\t': case 0x08: 40 | case KeyDecodingProfile.ESC_CODE: return null; // nope 41 | case 0: /* ^@ */ ctrlCode = ' '; break; 42 | case 28: /* ^\ */ ctrlCode = '\\'; break; 43 | case 29: /* ^] */ ctrlCode = ']'; break; 44 | case 30: /* ^^ */ ctrlCode = '^'; break; 45 | case 31: /* ^_ */ ctrlCode = '_'; break; 46 | default: ctrlCode = (char)('a' - 1 + ch); 47 | } 48 | KeyStroke ks = new KeyStroke( ctrlCode, true, false); 49 | return new Matching( ks ); // yep 50 | } else { 51 | return null; // nope 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/AbsoluteLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | import java.util.List; 23 | 24 | /** 25 | * Layout manager that places components where they are manually specified to be and sizes them to the size they are 26 | * manually assigned to. When using the AbsoluteLayout, please use setPosition(..) and setSize(..) manually on each 27 | * component to choose where to place them. Components that have not had their position and size explicitly set will 28 | * not be visible. 29 | * 30 | * @author martin 31 | */ 32 | public class AbsoluteLayout implements LayoutManager { 33 | @Override 34 | public TerminalSize getPreferredSize(List components) { 35 | TerminalSize size = TerminalSize.ZERO; 36 | for(Component component: components) { 37 | size = size.max( 38 | new TerminalSize( 39 | component.getPosition().getColumn() + component.getSize().getColumns(), 40 | component.getPosition().getRow() + component.getSize().getRows())); 41 | 42 | } 43 | return size; 44 | } 45 | 46 | @Override 47 | public void doLayout(TerminalSize area, List components) { 48 | //Do nothing 49 | } 50 | 51 | @Override 52 | public boolean hasChanged() { 53 | return false; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/TestACS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | 20 | package com.googlecode.lanterna; 21 | 22 | import java.lang.reflect.Field; 23 | import java.util.HashSet; 24 | import java.util.Set; 25 | 26 | /** 27 | * This program will print all ACS symbols to standard out, it's a good test 28 | * to see if your terminal emulator supports these UTF-8 characters or not. 29 | * @author Martin 30 | */ 31 | public class TestACS 32 | { 33 | private static final Set NEW_LINE_AFTER = new HashSet() {{ 34 | add("MALE"); 35 | add("ARROW_LEFT"); 36 | add("BLOCK_SPARSE"); 37 | add("DOUBLE_LINE_VERTICAL"); 38 | add("DOUBLE_LINE_TOP_RIGHT_CORNER"); 39 | add("DOUBLE_LINE_BOTTOM_RIGHT_CORNER"); 40 | add("DOUBLE_LINE_CROSS"); 41 | add("SINGLE_LINE_T_LEFT"); 42 | add("SINGLE_LINE_T_DOUBLE_LEFT"); 43 | add("DOUBLE_LINE_T_LEFT"); 44 | add("DOUBLE_LINE_T_SINGLE_LEFT"); 45 | }}; 46 | 47 | public static void main(String[] args) 48 | { 49 | for(Field field : Symbols.class.getFields()) { 50 | field.setAccessible(true); 51 | try { 52 | System.out.printf("%1$s = %2$s%n%3$s", field.getName(), field.get(null), 53 | NEW_LINE_AFTER.contains(field.getName()) ? System.lineSeparator() : ""); 54 | } catch (IllegalAccessException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue150.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.issue; 20 | 21 | import com.googlecode.lanterna.TextColor; 22 | import com.googlecode.lanterna.gui2.*; 23 | import com.googlecode.lanterna.screen.Screen; 24 | import com.googlecode.lanterna.screen.TerminalScreen; 25 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 26 | import com.googlecode.lanterna.terminal.Terminal; 27 | 28 | import java.io.IOException; 29 | 30 | public class Issue150 { 31 | public static void main(String... args) throws IOException { 32 | Terminal term = new DefaultTerminalFactory().createTerminal(); 33 | Screen screen = new TerminalScreen(term); 34 | WindowManager windowManager = new DefaultWindowManager(); 35 | Component background = new EmptySpace(TextColor.ANSI.DEFAULT); 36 | final WindowBasedTextGUI gui = new MultiWindowTextGUI(screen, windowManager, background); 37 | screen.startScreen(); 38 | gui.addWindowAndWait(new BasicWindow("Issue150") {{ 39 | setComponent(createUi()); 40 | }}); 41 | screen.stopScreen(); 42 | } 43 | 44 | private static Component createUi() { 45 | ActionListBox actions = new ActionListBox(); 46 | actions.addItem("Enter terminal in a strange state", Issue150::stub); 47 | return actions; 48 | } 49 | 50 | private static T stub() { 51 | throw new UnsupportedOperationException("What a terrible failure!"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/table/TableHeaderRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.table; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | import com.googlecode.lanterna.gui2.TextGUIGraphics; 23 | 24 | /** 25 | * This interface can be implemented if you want to customize how table headers are drawn. 26 | * @param Type of data stored in each table cell 27 | * @author Martin 28 | */ 29 | public interface TableHeaderRenderer { 30 | /** 31 | * Called by the table when it wants to know how big a particular table header should be 32 | * @param table Table containing the header 33 | * @param label Label for this header 34 | * @param columnIndex Column index of the header 35 | * @return Size this renderer would like the header to have 36 | */ 37 | TerminalSize getPreferredSize(Table table, String label, int columnIndex); 38 | 39 | /** 40 | * Called by the table when it's time to draw a header, you can see how much size is available by checking the size 41 | * of the {@code textGUIGraphics}. The top-left position of the graphics object is the top-left position of this 42 | * header. 43 | * @param table Table containing the header 44 | * @param label Label for this header 45 | * @param index Column index of the header 46 | * @param textGUIGraphics Graphics object to header with 47 | */ 48 | void drawHeader(Table table, String label, int index, TextGUIGraphics textGUIGraphics); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/ComponentRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | 23 | /** 24 | * This interface defines a renderer for a component, an external class that does the sizing and rendering. All 25 | * components will have a default renderer defined, which can usually be overridden manually and swapped out for a 26 | * different renderer, but also themes can contain renderer definitions which are automatically assigned to their 27 | * associated components. 28 | * @param Type of the component which this renderer is designed for 29 | * @author Martin 30 | */ 31 | public interface ComponentRenderer { 32 | /** 33 | * Given the supplied component, how large does this renderer want the component to be? Notice that this is the 34 | * responsibility of the renderer and not the component itself, since the component has no idea what its visual 35 | * representation looks like. 36 | * @param component Component to calculate the preferred size of 37 | * @return The size this renderer would like the component to take up 38 | */ 39 | TerminalSize getPreferredSize(T component); 40 | 41 | /** 42 | * Using the supplied graphics object, draws the component passed in. 43 | * @param graphics Graphics object to use for drawing 44 | * @param component Component to draw 45 | */ 46 | void drawComponent(TextGUIGraphics graphics, T component); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/dialogs/MessageDialogButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.dialogs; 20 | 21 | import com.googlecode.lanterna.gui2.LocalizedString; 22 | 23 | /** 24 | * This enum has the available selection of buttons that you can add to a {@code MessageDialog}. They are used both for 25 | * specifying which buttons the dialog will have but is also returned when the user makes a selection 26 | * 27 | * @author Martin 28 | */ 29 | public enum MessageDialogButton { 30 | /** 31 | * "OK" 32 | */ 33 | OK(LocalizedString.OK), 34 | /** 35 | * "Cancel" 36 | */ 37 | CANCEL(LocalizedString.Cancel), 38 | /** 39 | * "Yes" 40 | */ 41 | YES(LocalizedString.Yes), 42 | /** 43 | * "No" 44 | */ 45 | NO(LocalizedString.No), 46 | /** 47 | * "Close" 48 | */ 49 | CLOSE(LocalizedString.Close), 50 | /** 51 | * "Abort" 52 | */ 53 | ABORT(LocalizedString.Abort), 54 | /** 55 | * "Ignore" 56 | */ 57 | IGNORE(LocalizedString.Ignore), 58 | /** 59 | * "Retry" 60 | */ 61 | RETRY(LocalizedString.Retry), 62 | 63 | /** 64 | * "Continue" 65 | */ 66 | CONTINUE(LocalizedString.Continue); 67 | 68 | private final LocalizedString label; 69 | 70 | MessageDialogButton(final LocalizedString label) { 71 | this.label = label; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return label.toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/TODO.txt: -------------------------------------------------------------------------------- 1 | * [DONE] Label background color 2 | * [DONE] Editable TextArea 3 | * Overlapping windows - X-Y offset 4 | * [DONE] ListBox page up/page down 5 | * Menus 6 | * [DONE] TextBox fill character (Issue 66) 7 | * [DONE] Telnet support 8 | * [DONE] Proper Table class (+scroll) 9 | * [DONE] Manual setFocus() for components 10 | * [DONE] Resize terminal (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html) 11 | * Tabbed panel 12 | * Render window title other place than left-aligned 13 | 14 | From Brad C. by email to lanterna-discuss on 2014-06-09: 15 | * [DONE] Border Colors - Would be nice if you could optionally override the Theme to include a Background and Foreground color on the various borders. 16 | * [DONE] Double Border - Much like the Standard border, but using ACS.DOUBLE_LINE.* 17 | * [DONE] Text Box (On Key Press) - Allow for an Override on Key Press of the Text Box Component. This would allow someone to apply a default action specific to that component. In this case, I wanted the ENTER key to perform an action. 18 | * [DONE] Wrapped Label - I developed a Label component that wraps according to the width of the parent container. This is similar to the logic you have for your label, other than I am doing some Regular Expression work to wrap at logical spaces. I believe yours simply cuts off the line and adds the periods (...) 19 | * Custom Theme Categories - As I am developing my own components, I found the need to utilize custom categories.. This quickly became problematic, and I was only able to solve it by creating an extended Theme class of my own. It works, but it would be nice if those of us who write components had a way of using something other than the Category Enumeration. 20 | * CommonProfile Accessor - We use a Terminal that is slightly customized (Anzio), so it would have been great if I could have extended CommonProfile (like you do for Putty) and implemented my own. Right now it's protected, so I am unable to do so.. 21 | * Colors - I think there would be some value in having more control of the colors (foreground and background) for most of the components. Basically overriding the theme itself. 22 | * [DONE] ListView Component - I am working on this now, but I am looking at a component that resembles a fully featured ListView component. Much like a table, only the entire "Row" is a single interactable item. -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/dialogs/DialogWindow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.dialogs; 20 | 21 | import com.googlecode.lanterna.gui2.*; 22 | 23 | import java.util.Collections; 24 | import java.util.HashSet; 25 | import java.util.Set; 26 | 27 | /** 28 | * Thin layer on top of the {@code AbstractWindow} class that automatically sets properties and hints to the window to 29 | * make it act more like a modal dialog window 30 | */ 31 | public abstract class DialogWindow extends AbstractWindow { 32 | 33 | private static final Set GLOBAL_DIALOG_HINTS = 34 | Collections.unmodifiableSet(new HashSet<>(Collections.singletonList(Hint.MODAL))); 35 | 36 | /** 37 | * Default constructor, takes a title for the dialog and runs code shared for dialogs 38 | * @param title Title of the window 39 | */ 40 | protected DialogWindow(String title) { 41 | super(title); 42 | setHints(GLOBAL_DIALOG_HINTS); 43 | } 44 | 45 | /** 46 | * Opens the dialog by showing it on the GUI and doesn't return until the dialog has been closed 47 | * @param textGUI Text GUI to add the dialog to 48 | * @return Depending on the {@code DialogWindow} implementation, by default {@code null} 49 | */ 50 | public Object showDialog(WindowBasedTextGUI textGUI) { 51 | textGUI.addWindow(this); 52 | 53 | //Wait for the window to close, in case the window manager doesn't honor the MODAL hint 54 | waitUntilClosed(); 55 | return null; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/Issue274.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Author Rajatt, modified by Andreas 3 | */ 4 | package com.googlecode.lanterna.issue; 5 | 6 | import java.io.IOException; 7 | import com.googlecode.lanterna.TerminalSize; 8 | import com.googlecode.lanterna.gui2.BasicWindow; 9 | import com.googlecode.lanterna.gui2.Button; 10 | import com.googlecode.lanterna.gui2.Direction; 11 | import com.googlecode.lanterna.gui2.LinearLayout; 12 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; 13 | import com.googlecode.lanterna.gui2.Panel; 14 | import com.googlecode.lanterna.gui2.TextBox; 15 | import com.googlecode.lanterna.gui2.Window; 16 | import com.googlecode.lanterna.screen.Screen; 17 | import com.googlecode.lanterna.screen.TerminalScreen; 18 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; 19 | import com.googlecode.lanterna.terminal.MouseCaptureMode; 20 | import com.googlecode.lanterna.terminal.Terminal; 21 | 22 | public class Issue274 { 23 | 24 | public static void main(String[] args) throws IOException { 25 | 26 | final Terminal ter = new DefaultTerminalFactory() 27 | .setForceTextTerminal(true) 28 | .setMouseCaptureMode(MouseCaptureMode.CLICK) 29 | .setTelnetPort(1024) 30 | .createTerminal(); 31 | 32 | final Screen screen = new TerminalScreen(ter); 33 | screen.startScreen(); 34 | final MultiWindowTextGUI gui = new MultiWindowTextGUI(screen); 35 | 36 | Panel menubar = new Panel(); 37 | menubar.setLayoutManager(new LinearLayout(Direction.HORIZONTAL).setSpacing(1)); 38 | 39 | TextBox text = new TextBox(new TerminalSize(10,10),TextBox.Style.MULTI_LINE); 40 | menubar.addComponent(text); 41 | 42 | menubar.addComponent(new Button("Open", () -> { 43 | final Window op = new BasicWindow("Select file"); 44 | gui.addWindow(op); 45 | op.setComponent(new Button("Close", op::close)); 46 | })); 47 | 48 | menubar.addComponent(new Button("Save")); 49 | 50 | menubar.addComponent(new Button("Exit", () -> gui.getActiveWindow().close())); 51 | 52 | Window main = new BasicWindow("Test"); 53 | main.setComponent(menubar); 54 | try { 55 | gui.addWindowAndWait(main); 56 | } 57 | finally { 58 | screen.stopScreen(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/input/InputProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.input; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Objects implementing this interface can read character streams and transform them into {@code Key} objects which can 25 | * be read in a FIFO manner. 26 | * 27 | * @author Martin 28 | */ 29 | public interface InputProvider { 30 | /** 31 | * Returns the next {@code Key} off the input queue or null if there is no more input events available. Note, this 32 | * method call is not blocking, it returns null immediately if there is nothing on the input stream. 33 | * @return Key object which represents a keystroke coming in through the input stream 34 | * @throws java.io.IOException Propagated error if the underlying stream gave errors 35 | */ 36 | KeyStroke pollInput() throws IOException; 37 | 38 | /** 39 | * Returns the next {@code Key} off the input queue or blocks until one is available. NOTE: In previous 40 | * versions of Lanterna, this method was not blocking. From lanterna 3, it is blocking and you can call 41 | * {@code pollInput()} for the non-blocking version. 42 | * @return Key object which represents a keystroke coming in through the input stream 43 | * @throws java.io.IOException Propagated error if the underlying stream gave errors 44 | */ 45 | KeyStroke readInput() throws IOException; 46 | 47 | //TODO: Add a version of readInput() that takes a timeout specification, in a future version of lanterna 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/gui2/MultiButtonTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | import com.googlecode.lanterna.TestTerminalFactory; 23 | import com.googlecode.lanterna.screen.Screen; 24 | 25 | import java.io.IOException; 26 | 27 | public class MultiButtonTest { 28 | public static void main(String[] args) throws IOException { 29 | Screen screen = new TestTerminalFactory(args).createScreen(); 30 | screen.startScreen(); 31 | MultiWindowTextGUI textGUI = new MultiWindowTextGUI(screen); 32 | textGUI.setEOFWhenNoWindows(true); 33 | try { 34 | final BasicWindow window = new BasicWindow("Button test"); 35 | Panel contentArea = new Panel(); 36 | contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL)); 37 | contentArea.addComponent(new Button("")); 38 | contentArea.addComponent(new Button("TRE")); 39 | contentArea.addComponent(new Button("Button")); 40 | contentArea.addComponent(new Button("Another button")); 41 | contentArea.addComponent(new EmptySpace(new TerminalSize(5, 1))); 42 | //contentArea.addComponent(new Button("Here is a\nmulti-line\ntext segment that is using \\n")); 43 | contentArea.addComponent(new Button("OK", window::close)); 44 | 45 | window.setComponent(contentArea); 46 | textGUI.addWindowAndWait(window); 47 | } 48 | finally { 49 | screen.stopScreen(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/googlecode/lanterna/gui2/table/TableCellRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2020 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.gui2.table; 20 | 21 | import com.googlecode.lanterna.TerminalSize; 22 | import com.googlecode.lanterna.gui2.TextGUIGraphics; 23 | 24 | /** 25 | * The main interface to implement when you need to customize the way table cells are drawn 26 | * 27 | * @param Type of data in the table cells 28 | * @author Martin 29 | */ 30 | public interface TableCellRenderer { 31 | /** 32 | * Called by the table when it wants to know how big a particular table cell should be 33 | * @param table Table containing the cell 34 | * @param cell Data stored in the cell 35 | * @param columnIndex Column index of the cell 36 | * @param rowIndex Row index of the cell 37 | * @return Size this renderer would like the cell to have 38 | */ 39 | TerminalSize getPreferredSize(Table table, V cell, int columnIndex, int rowIndex); 40 | 41 | /** 42 | * Called by the table when it's time to draw a cell, you can see how much size is available by checking the size of 43 | * the {@code textGUIGraphics}. The top-left position of the graphics object is the top-left position of this cell. 44 | * @param table Table containing the cell 45 | * @param cell Data stored in the cell 46 | * @param columnIndex Column index of the cell 47 | * @param rowIndex Row index of the cell 48 | * @param textGUIGraphics Graphics object to draw with 49 | */ 50 | void drawCell(Table table, V cell, int columnIndex, int rowIndex, TextGUIGraphics textGUIGraphics); 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/InitialSizeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.terminal; 20 | 21 | import com.googlecode.lanterna.SGR; 22 | import com.googlecode.lanterna.TerminalSize; 23 | import com.googlecode.lanterna.TestTerminalFactory; 24 | import java.io.IOException; 25 | 26 | /** 27 | * 28 | * @author Martin 29 | */ 30 | public class InitialSizeTest { 31 | public static void main(String[] args) throws IOException { 32 | final Terminal rawTerminal = new TestTerminalFactory(args).createTerminal(); 33 | rawTerminal.enterPrivateMode(); 34 | rawTerminal.clearScreen(); 35 | 36 | rawTerminal.setCursorPosition(5, 5); 37 | printString(rawTerminal, "Waiting for initial size..."); 38 | rawTerminal.flush(); 39 | 40 | TerminalSize initialSize = rawTerminal.getTerminalSize(); 41 | rawTerminal.clearScreen(); 42 | rawTerminal.setCursorPosition(5, 5); 43 | printString(rawTerminal, "Initial size: "); 44 | rawTerminal.enableSGR(SGR.BOLD); 45 | printString(rawTerminal, initialSize.toString()); 46 | rawTerminal.resetColorAndSGR(); 47 | rawTerminal.flush(); 48 | 49 | try { 50 | Thread.sleep(5000); 51 | } 52 | catch(InterruptedException e) {} 53 | rawTerminal.exitPrivateMode(); 54 | } 55 | 56 | private static void printString(Terminal rawTerminal, String string) throws IOException { 57 | for(int i = 0; i < string.length(); i++) { 58 | rawTerminal.putCharacter(string.charAt(i)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/terminal/NewSwingTerminalTest.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/test/java/com/googlecode/lanterna/issue/IssueX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of lanterna (https://github.com/mabe02/lanterna). 3 | * 4 | * lanterna is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Copyright (C) 2010-2024 Martin Berglund 18 | */ 19 | package com.googlecode.lanterna.issue; 20 | 21 | import com.googlecode.lanterna.SGR; 22 | import com.googlecode.lanterna.graphics.TextGraphics; 23 | import com.googlecode.lanterna.TestTerminalFactory; 24 | import com.googlecode.lanterna.screen.Screen; 25 | import java.io.IOException; 26 | 27 | class IssueX { 28 | 29 | public static void main(String[] args) throws InterruptedException, IOException { 30 | LanternaTerminalWriter writer = new LanternaTerminalWriter(args); 31 | for (int i = 0; i < 1000; i++) { 32 | writer.write(String.valueOf(i), SGR.BOLD); 33 | Thread.sleep(100); 34 | } 35 | writer.close(); 36 | } 37 | 38 | public static class LanternaTerminalWriter { 39 | 40 | private Screen screen; 41 | private TextGraphics screenWriter; 42 | 43 | public LanternaTerminalWriter(String[] args) throws IOException { 44 | screen = new TestTerminalFactory(args).createScreen(); 45 | screen.startScreen(); 46 | 47 | screenWriter = screen.newTextGraphics(); 48 | } 49 | 50 | public void close() throws IOException { 51 | screen.stopScreen(); 52 | } 53 | 54 | public void write(String string, SGR... styles) throws IOException { 55 | screenWriter.enableModifiers(styles); 56 | int current_y = 1; 57 | int default_x = 3; 58 | screenWriter.putString(default_x, current_y, string); 59 | screen.pollInput(); 60 | screen.refresh(); 61 | } 62 | 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /docs/examples/gui/layout_managers.md: -------------------------------------------------------------------------------- 1 | Layout Managers 2 | --- 3 | 4 | Absolute Layout 5 | --- 6 | A Layout manager that places components where they are manually specified to be and sizes them to the size they are manually assigned to. When using the AbsoluteLayout, please use `setPosition()` and `setSize()` manually on each component to choose where to place them. 7 | 8 | To set a given panel's layout to be absolute: 9 | 10 | ``` 11 | panel.setLayoutManager(new AbsoluteLayout()); 12 | ``` 13 | 14 | Linear Layout 15 | --- 16 | A simple layout manager the puts all components on a single line. Linear Layout has two `Direction`'s, `HORIZONTAL` and `VERTICAL`. 17 | 18 | ``` 19 | // To have the components sit next to each other 20 | panel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) 21 | 22 | // To have the components sit on top of each other 23 | panel.setLayoutManager(new LinearLayout(Direction.VERTICAL)) 24 | ``` 25 | 26 | 27 | Border Layout 28 | --- 29 | Imitates the BorderLayout class from AWT, allowing you to add a center component with optional components around it in top, bottom, left and right locations. The edge components will be sized at their preferred size and the center component will take up whatever remains. 30 | 31 | In the following example, the text box will be full screen, centered and multiline: 32 | 33 | ``` 34 | panel.setLayoutManager(new BorderLayout()); 35 | 36 | // Sets the textbox to be in the center of the screen 37 | TextBox textBox = new TextBox("", TextBox.Style.MULTI_LINE); 38 | textBox.setLayoutData(BorderLayout.Location.CENTER); 39 | 40 | //... 41 | 42 | // Tip: Sets the window to be full screen. 43 | window.setHints(Arrays.asList(Window.Hint.FULL_SCREEN)); 44 | ``` 45 | 46 | 47 | Grid Layout 48 | --- 49 | This emulates the behaviour of the GridLayout in SWT (as opposed to the one in AWT/Swing). 50 | 51 | To set a given panel's layout to be a grid layout: 52 | 53 | ``` 54 | // Grid will have two columns 55 | panel.setLayoutManager(new GridLayout(2)); 56 | 57 | // As this grid is a 2xN grid, each row must have 2 elements. 58 | // An empty space is added before the button to fill in the cell before the buttons cell. 59 | buttonPanel.addComponent(new EmptySpace(new TerminalSize(0, 0))); 60 | buttonPanel.addComponent(new Button("Enter")); 61 | ``` 62 | 63 | Each time a component is added to the panel, it will be added to the grid in a left to right fashion, starting at 0x0. When the components get to the end of the column, it will start a new row. --------------------------------------------------------------------------------