Java library for creating text-based GUIs

Related tags

CLI lanterna
Overview

Lanterna

Lanterna screenshot

Lanterna is a Java library allowing you to write easy semi-graphical user interfaces in a text-only environment, very similar to the C library curses but with more functionality. Lanterna is supporting xterm compatible terminals and terminal emulators such as konsole, gnome-terminal, putty, xterm and many more. One of the main benefits of lanterna is that it's not dependent on any native library but runs 100% in pure Java.

Also, when running Lanterna on computers with a graphical environment (such as Windows or Xorg), a bundled terminal emulator written in Swing will be used rather than standard output. This way, you can develop as usual from your IDE (most of them doesn't support ANSI control characters in their output window) and then deploy to your headless server without changing any code.

Lanterna is structured into three layers, each built on top of the other and you can easily choose which one fits your needs best.

  1. The first is a low level terminal interface which gives you the most basic control of the terminal text area. You can move around the cursor and enable special modifiers for characters put to the screen. You will find these classes in package com.googlecode.lanterna.terminal.

  2. The second level is a full screen buffer, the whole text screen in memory and allowing you to write to this before flushing the changes to the actual terminal. This makes writing to the terminal screen similar to modifying a bitmap. You will find these classes in package com.googlecode.lanterna.screen.

  3. The third level is a full GUI toolkit with windows, buttons, labels and some other components. It's using a very simple window management system (basically all windows are modal) that is quick and easy to use. You will find these classes in package com.googlecode.lanterna.gui2.

Maven

Lanterna is available on Maven Central, through Sonatype OSS hosting. Here's what you want to use:

    <dependency>
        <groupId>com.googlecode.lanterna</groupId>
        <artifactId>lanterna</artifactId>
        <version>3.1.1</version>
    </dependency>

Discussions

There is a google group for discussions and announcements related to Lanterna.

Development Guide

See docs for examples and guides.

JavaDoc is available here:

The JavaDocs for the previous versions (2.1 and 3.0) are also available here:

There is also a development guide and some tutorials available right here on Github.

Comments
  • Issues with Lanterna Terminal Starting/Stopping

    Issues with Lanterna Terminal Starting/Stopping

    I have a couple of inconvenience running Lanterna 3 app on OS X:

    • then I start the app from Terminal, which is using DefaultTerminalFactory I always getting Swing terminal windows for my app. This doesn't feel nice. I expect app to run in terminal if I start it from terminal. I guess it has something to do with JVM flags.
    • after running my app using ANSITerminal my mouse can't scroll terminal contents anymore. Instead it works as and arrow keys, making me close terminal to get rid of this effect. This is very inconvenient - mouse should work as it was before after I leaving the app. At least this is what happens if app exits due to exception. I guess there should be some shutdown hook to make it work as it used to before.
    opened by dant3 38
  • Scrolling a Screen

    Scrolling a Screen

    I'm using Lanterna 3.0.0-alpha6 and am trying to put together an irssi type interface. In my application the top-most portion of the terminal scrolls, the bottom line is reserved for user input. Presently when I need to scroll the content I redraw the top portion of the window in it's entirety, adding my new line to the bottom.

    This works okay with the Swing terminal but performs poorly with an actual xterm (or Gnome Terminal) window. Is there a better way of scrolling text?

    Thank you!

    opened by cmiles74 35
  • Make Lanterna work with Java 1.4.2

    Make Lanterna work with Java 1.4.2

    What steps will reproduce the problem?
    1.
    2.
    3.
    
    What is the expected output? What do you see instead?
    
    
    What version of the product are you using? On what operating system?
    
    
    Please provide any additional information below.
    
    I can only use java 142. Can you please, post the jar file that has class files 
    compiled with java142. I am restricted to use Java142 and I am trying out a 
    different Operating system. I am trying to use this on IBM 4690. I found this 
    useful, because it doesnt use any native DLLs. Please feel free advice. Also, I 
    would be grateful if you can compile the source against 142.
    
    Thanks,
    Sunil.
    
    

    Original issue reported on code.google.com by [email protected] on 18 Oct 2011 at 8:17

    Priority-Medium auto-migrated Type-Enhancement 
    opened by GoogleCodeExporter 33
  • Crash on using Panel.setContent from ActionDialog callback

    Crash on using Panel.setContent from ActionDialog callback

    I'm trying to update my ui from ActionDialog callback. What I'm doing is:

    val window = new BasicWindow()
    window.setComponent(createUi(None))
    // ...
    val dialog = new ActionDialogBuilder()
    dialog.addAction(device.name, toRunnable(() => window.setComponent(createUi(Some(device)))))
    dialog.build().showDialog(gui)
    // ...
    def createUi(device):Panel = Panels.vertical(component1(device), componentWhichMightCallDialogAbove)
    //...
    def toRunnable(fn: () => Unit):Runnable = new Runnable { override def run() = fn.apply() }
    

    But then this Runnable action get's called I'm getting exception:

    java.lang.NullPointerException
            at com.googlecode.lanterna.gui2.AbstractComponent.toBasePane(AbstractComponent.java:218)
            at com.googlecode.lanterna.gui2.AbstractComponent.toBasePane(AbstractComponent.java:218)
            at com.googlecode.lanterna.gui2.AbstractBasePane.getCursorPosition(AbstractBasePane.java:174)
            at com.googlecode.lanterna.gui2.MultiWindowTextGUI.getCursorPosition(MultiWindowTextGUI.java:181)
            at com.googlecode.lanterna.gui2.AbstractTextGUI.updateScreen(AbstractTextGUI.java:118)
            at com.googlecode.lanterna.gui2.MultiWindowTextGUI.updateScreen(MultiWindowTextGUI.java:144)
            at com.googlecode.lanterna.gui2.AbstractTextGUIThread.processEventsAndUpdate(AbstractTextGUIThread.java:61)
            at com.googlecode.lanterna.gui2.MultiWindowTextGUI.waitForWindowToClose(MultiWindowTextGUI.java:275)
            at com.googlecode.lanterna.gui2.AbstractWindow.waitUntilClosed(AbstractWindow.java:164)
            at com.googlecode.lanterna.gui2.dialogs.DialogWindow.showDialog(DialogWindow.java:26)
            at com.github.dant3.catlog.Main$.com$github$dant3$catlog$Main$$showDevicesList(Main.scala:58)
            at com.github.dant3.catlog.Main$$anonfun$createToolbar$1.apply$mcV$sp(Main.scala:44)
            at com.github.dant3.catlog.ui.Toolbar.com$github$dant3$catlog$ui$Toolbar$$handleKeyStroke(Toolbar.scala:20)
            at com.github.dant3.catlog.ui.Toolbar$$anon$1.onUnhandledKeyStroke(Toolbar.scala:16)
            at com.googlecode.lanterna.gui2.AbstractTextGUI.fireUnhandledKeyStroke(AbstractTextGUI.java:154)
            at com.googlecode.lanterna.gui2.AbstractTextGUI.processInput(AbstractTextGUI.java:100)
            at com.googlecode.lanterna.gui2.AbstractTextGUIThread.processEventsAndUpdate(AbstractTextGUIThread.java:53)
            at com.googlecode.lanterna.gui2.MultiWindowTextGUI.waitForWindowToClose(MultiWindowTextGUI.java:275)
            at com.googlecode.lanterna.gui2.AbstractWindow.waitUntilClosed(AbstractWindow.java:164)
            at com.googlecode.lanterna.gui2.MultiWindowTextGUI.addWindowAndWait(MultiWindowTextGUI.java:252)
            at com.github.dant3.catlog.Main$$anonfun$main$1.apply(Main.scala:19)
            at com.github.dant3.catlog.Main$$anonfun$main$1.apply(Main.scala:17) 
            at com.github.dant3.catlog.ui.GUI$.run(GUI.scala:21)
            at com.github.dant3.catlog.Main$.main(Main.scala:17)
            at com.github.dant3.catlog.Main.main(Main.scala)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:497)
    

    You can find complete sources at https://github.com/dant3/catlog/blob/2725bfd14aeb5d1e371096ecd7fb46ee3c0d9c81/src/main/scala/com/github/dant3/catlog/Main.scala#L48

    opened by dant3 26
  • does not react properly to backspace (terminology)

    does not react properly to backspace (terminology)

    in Terminology backspace causes 'h' to be written to the textfields ticking the option to send delte instead of backspaces fixes it

    but i bet there will be some temrinals or cases when this is not a option

    opened by NikkyAI 23
  • Window Scrolling in Putty

    Window Scrolling in Putty

    Using Putty, when the GUI Window is larger than the putty window, a notification to use the Ctrl+Arrow is displayed. However, Putty intercepts the Ctrl+Arrow commands, which prevents scrolling.

    opened by chrsdbll 23
  • Random white screen with SwingTerminal

    Random white screen with SwingTerminal

    On Ubuntu 10.04, sometimes when launching the SwingTerminal, the window starts 
    all white and it doesn't draw anything. Seems very random, still haven't been 
    able to figure out to reproduce it.
    
    Unverified on any other platform
    

    Original issue reported on code.google.com by [email protected] on 28 Jun 2010 at 7:32

    Priority-Medium auto-migrated OpSys-All Type-Defect 
    opened by GoogleCodeExporter 23
  • Please ship WindowsTerminal along with rest of the binary classes

    Please ship WindowsTerminal along with rest of the binary classes

    Currently, the version of the library available from the Maven Central lacks WindowsTerminal class.

    Please ship WindowsTerminal plus native code for win32/win64 along with the rest of the library.

    Additionally, lanterna can have an optional dependency on the native-platform library which already ships the native primitives for all mainstream platforms. WindowsTerminal could be re-implemented via those primitives -- see WindowsConsoleFunctions.java.

    opened by unix-junkie 22
  • When running jdk-headless, Lanterna fails immediately

    When running jdk-headless, Lanterna fails immediately

    If a headless JDK/JRE is installed, Lanterna will experience a java.lang.ExceptionInInitializerError at DefaultTerminalFactory.java:85, which is caused by a java.lang.NullPointerException being thrown by sun.awt.FontConfiguration.getVersion call which happens when SwingTerminalFontConfiguration.java:197 calls isFontMonospaced during construction.

    There should be a if (!GraphicsEnvironment.isHeadless()) { } around the SwingTerminalFrame initializers in the DefaultTerminalFactory constructor to avoid this problem.

    opened by spatula75 18
  • Virtual screen and components size measures.

    Virtual screen and components size measures.

    I have a gui app with following layout:

    +--[ main window   ]---------------+
    |  toolbar                         |
    +----------------------------------+
    |  listbox with long strings       |
    +----------------------------------+
       ↑
       +-- LinearLayout(orinetation = Vertical)
    

    See screenshot for example. Then my listbox has very long strings inside it's size measure tells that it want this hige amount of columns of terminal. As I see it, screen area stretches itself making whole terminal a big scrollable area. This doesn't looks like a convenient behaviour. Issues I see here are:

    1. scrollable screen area doesn't looks like a general usecase. I see very limited convenient usages of it. If we would look at alternatives in non-terminal gui apps, I know only one very special case groups of apps which uses full-window scrolling (notice - not the screen scrolling - only particular window) - like photo editing tools or music editors.
    2. LinearLayout behaviour seems strange. I understand why it could recommend window to become bigger if it's not yet fits whole screen space, but I don't understand why it recommends taking even more space.

    One more interesting thing is vertical scrollbar I see nearby listbox. Not sure what it displays, but looks really odd.

    image

    opened by dant3 17
  • getTerminalSize() issues with gnome terminal

    getTerminalSize() issues with gnome terminal

    TerminalFacade.createScreen(TerminalFacade.createTextTerminal()).getTerminalSize
    ()
    
    return {80x20} regardless of the terminal size, and
    
    TerminalFacade.createScreen(TerminalFacade.createTextTerminal()).getTerminal().g
    etTerminalSize()
    
    seems to get the correct size but after about a second it throws the following 
    exception:
    
    Exception in thread "main" java.io.IOException: Timeout while waiting for 
    terminal size report! Maybe your terminal doesn't support cursor position 
    report, please consider using a custom size querier                            
    at 
    com.googlecode.lanterna.terminal.InputEnabledAbstractTerminal.waitForTerminalSiz
    eReport(InputEnabledAbstractTerminal.java:79)                  at 
    com.googlecode.lanterna.terminal.text.ANSITerminal.getTerminalSize(ANSITerminal.
    java:62)                                                       at 
    com.googlecode.lanterna.terminal.text.UnixTerminal.getTerminalSize(UnixTerminal.
    java:154)                                                      at 
    Test.main(Test.java:22)                                         
    
    

    Original issue reported on code.google.com by [email protected] on 7 Jan 2013 at 12:12

    Priority-Medium auto-migrated Type-Defect 
    opened by GoogleCodeExporter 17
  • Spanish translation of ui messages

    Spanish translation of ui messages

    Hi!

    I want to collaborate with Lanterna project with this small file. The translation to spanish for ui messages.

    Thank you for you awesome job, guys!

    opened by hamfree 0
  • Terminal window resize and resizing disabling

    Terminal window resize and resizing disabling

    Is there any possibility to resize the terminal from the code layer at runtime?

    On the other hand, is it possible to set the terminal as not resizable by the user?

    opened by Sophusy 1
  • Control characters support

    Control characters support

    In MacOS, in iTerm2 terminal there is a feature to draw images directly to terminal. All you need to do is to print a message in special format, like this:

    final String base64 = "base64-encoded-image-here";
    final String s = "]1337;File=inline=1;width=100%%;height=100%%:" + base64;
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    terminal.putCharacter('\033');     // <--
    terminal.putString(s);
    terminal.putCharacter('\007');     // <--
    terminal.flush();
    

    But it doesn't seem to be working. It just prints s and ignores control characters (\033 and \007). So does Lanterna support control characters?

    opened by mitrakov 4
  • Please use CAPITAL enum constants in LinearLayout.Alignment

    Please use CAPITAL enum constants in LinearLayout.Alignment

    Would it be possible to change the enum constants in LinearLayout.Alignment to, respectively, BEGINNING, CENTER, END, FILL, i.e. capitalized as in GridLayout.Alignment?

    Thanks, MZ

    opened by zanonmark 2
  • Please make Components use Listeners only for events

    Please make Components use Listeners only for events

    Hi, and thanks for Lanterna!

    One thing I don't understand is: why having some events handled as protected methods e.g.: (Component.afterEnterFocus()) and handled via Listeners in other parts of the package (e.g.: Terminal.addResizeListener(), but also Button.addListener())? Would it be possible to use Listeners everywhere? Not only for consistency, but also because IMHO they're more flexible.

    Thanks, MZ

    opened by zanonmark 2
  • Fix: pass correct target focus to previous focus

    Fix: pass correct target focus to previous focus

    Hi,

    When using this library, I noticed that when overriding afterLeaveFocus(direction: Interactable.FocusChangeDirection, nextInFocus: Interactable), the nextInFocus variable was actually set to the current Interactable and not the target one.

    This patch fixes that.

    Thank you

    opened by zyuiop 0
Owner
null
JCLR (JavaColor) is a library that allows you to write colored text in your terminal. It use the ANSI color system. Go check the README.md file to see how to use it.

JCLR JCLR (JavaColor) is a library that allows you to write colored text in your terminal. It use the ANSI color system. To start using it, go to the

Scythe 3 Aug 21, 2021
Several implementations of a text table, originally using ASCII and UTF-8 characters for borders.

ASCII Table ASCII table - A simple tool to format tables with various row/column options for indentation, indentation character, alignment, padding (l

Sven van der Meer 415 Dec 26, 2022
Java annotation-based framework for parsing Git like command line structures

Airline Airline is a Java annotation-based framework for parsing Git like command line structures. Latest release is 0.8, available from Maven Central

null 847 Nov 26, 2022
Spring based interactive shell

Spring Shell 3 Spring Shell 3 is a work to solely depend on Spring Boot 2.x and not trying to keep any backward compatibility with older Spring Shell

Spring 609 Dec 14, 2022
Annotation-based command framework for Minestom

Minestand Annotation-based command framework for Minestom Advantages over other frameworks Minestand works by converting your classes into Minestom co

null 6 Aug 27, 2022
Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.

Description Jansi is a small java library that allows you to use ANSI escape codes to format your console output which works even on Windows. It also

FuseSource 955 Dec 28, 2022
JLine is a Java library for handling console input.

JLine JLine is a Java library for handling console input. It is similar in functionality to BSD editline and GNU readline but with additional features

null 1.2k Jan 5, 2023
Command-line API for Atlassian JIRA using the Tomitribe CREST library

Atlassian JIRA Command-Line (CLI) Jamira is a command-line API for Atlassian JIRA using the Tomitribe CREST library. Installation Jamira can be downlo

Tomitribe 12 Sep 10, 2022
ASCII renderer in pure java with no external dependencies

Java ASCII Render ASCII renderer in pure java with no external dependencies. Java ASCII Render supports graphical primitives/elements, layers, context

David E. Veliev 140 Dec 12, 2022
Command line parsing framework for Java

JCommander This is an annotation based parameter parsing framework for Java 8. Here is a quick example: public class JCommanderTest { @Parameter

Cedric Beust 1.8k Dec 29, 2022
Tool for creating custom GUIs using packets.

Tool for creating custom GUIs using packets.

Geo3gamer 0 Feb 14, 2022
Automated door opening system w/GUIs programmed in Java and Arduino

The Automated Door Opening System is a major project created in both Java and Arduino for a first year Engineering course. This project is an iteration of my MATLAB version of this project.

Crasher1225 3 Jan 28, 2022
code to the rat i give to people if u want to change the webhook its in "src/main/java/github/quantizr/autogg/guis/gui" please just dont sell my rat :(

SkyblockRat My rats code join my discord! https://discord.gg/bbK6ndHqN6 i got tired of people asking "is it double hooked?!" so here is my rats code y

null 6 Dec 10, 2022
Fabric mod for rainbow backgrounds in minecraft guis

rainbowify rainbowify is a Fabric mod for Minecraft 1.17 that adds a customizable rainbow background to many Minecraft HUDs. Discord: https://discord.

Lennox 18 Sep 29, 2022
Text Object Java Objects (TOJOs): an object representation of a multi-line structured text file like CSV

It's a simple manager of "records" in a text file of CSV, JSON, etc. format. It's something you would use when you don't want to run a full database,

Yegor Bugayenko 19 Dec 27, 2022
Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Twitter 2.9k Jan 8, 2023
Open source Picture to text, text to Picture app

Pic SMS App Pic SMS is a free open source app. With Pic SMS, you can: convert pictures into text parts and send as SMS convert text parts into a pictu

Kaung Khant Kyaw 17 Feb 8, 2022
Extract text from a PDF (pdf to text). Api for PHP/JS/Python and others.

Extract text from a PDF (pdf to text). API in docker. Why did we create this project? In the Laravel project, it was necessary to extract texts from l

dotcode.moscow 6 May 13, 2022