Can't get input line editing to work in JLine3

417 Views Asked by At

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

1

There are 1 best solutions below

1
On

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...