jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 218 forks source link

Terminal on Windows with JNA or Jansi is lagging #508

Closed MCMDEV closed 4 years ago

MCMDEV commented 4 years ago

I'm not sure if this is normal behaviour but the input in when using either JNA or Jansi are lagging and keypresses aren't registering properly.

try {
            Terminal terminal = TerminalBuilder.builder().system(true).nativeSignals(true).jna(true).build();
            LineReader reader = LineReaderBuilder.builder().completer(new StringsCompleter("abc")).build();

            while (true)    {
                String line = reader.readLine("> ");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
MCMDEV commented 4 years ago

I tried the Example and it's working perfectly smooth.

mattirn commented 4 years ago

@MCMDEV, do you have jna/jansi jar in your classpath? By the way if you want that LineReader uses your terminal you should build reader as

LineReader reader = LineReaderBuilder.builder()
                                     .terminal(terminal)
                                     .completer(new StringsCompleter("abc"))
                                     .build();
shoaniki commented 4 years ago

I have observed the same effect when multiple Windows terminals are created -- it looks as though they end up competing to receive events, so it becomes random whether or not each keypress will reach the terminal you're actually using.

This would be triggered in this example because the LineReaderBuilder is creating a second terminal implicitly, as @mattirn observes.

gnodet commented 4 years ago

Multiple system terminals are not supported. Your process only has one, so you should not try to create multiple system terminals with jline. The TerminalBuilder could throw an exception if a system terminal has been created and not closed while attempting to create another one.