1

I'm struggling with the basics of getting a simple console application to work with JLine3.

I've initialized it like this:

    terminal = TerminalBuilder.builder()
                .streams(System.in, System.out)
                .build();
    lineReader = LineReaderBuilder.builder().terminal(terminal).build();

and I try to read a line like this:

    String in = lineReader.readLine("/>").trim();

and if the user just types text correctly, I get the right input. Backspace works for correcting the input. But moving the cursor back using the left arrow key doesn't; instead of the cursor moving, I see ^[0D displayed on the screen.

I tried various other options but nothing changed. I want to move on in due course to exploit history and auto-completion, but I'm failing at the first baby steps.

I've obviously missed something basic (but the documentation isn't good...)

Using JLine 3.13.3 on MacOS 10.13.6

Michael Kay
  • 156,231
  • 11
  • 92
  • 164

1 Answers1

0

If you want to create a terminal for the real console the JVM is running in, you'd rather use:

     terminal = TerminalBuilder
                .builder()
                .system(true)
                .build();

That should work better...

mattirn
  • 26
  • 4
  • Many thanks for the response. I've shipped with JLine2 for the moment, but I'll give this a try when I get a chance. – Michael Kay Mar 27 '20 at 15:35