mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.26k stars 242 forks source link

Screen API leaves terminal echo off upon exit #532

Open Windwoes opened 3 years ago

Windwoes commented 3 years ago

This looks like a really cool library, but there seems to be a bug with the screen API, where after calling stopScreen(), the terminal will not echo characters as they are typed.

Here is the code I am testing with. I am using GNOME Terminal on Ubuntu 16.04 with v3.1.1 of the library. To reproduce, simply run the JAR from the command line, then attempt to type something in the terminal after it exits.

public class Main
{
    Terminal terminal;
    Screen screen;

    public static void main(String[] args) throws IOException
    {
        new Main().main();
    }

    public void main() throws IOException
    {
        DefaultTerminalFactory factory = new DefaultTerminalFactory();
        terminal = factory.createTerminal();

        screen = factory.createScreen();
        screen.startScreen();

        TextGraphics graphics = screen.newTextGraphics();
        graphics.setBackgroundColor(TextColor.ANSI.WHITE_BRIGHT);
        graphics.drawRectangle(new TerminalPosition(0,0), new TerminalSize(80,1), ' ');

        graphics.setForegroundColor(TextColor.ANSI.BLACK);
        graphics.putString(new TerminalPosition(0,0), "Hello world");

        screen.refresh();

        try
        {
            Thread.sleep(2000);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        screen.stopScreen();
    }
}
karelantonio commented 3 years ago

You has tried use the enter/exit privateMode in Terminal?

avl42 commented 3 years ago

Not sure if this is still relevant, but you can look at some of the tests (src/test/java/... in the lanterna sources) for how they do it to restore tty-state to normal - maybe you need some "try ... finally ..." to make sure the cleanup still gets called even after an exception...