0

I use JLine library to handle console input and output.

Terminal terminal = TerminalFactory.getFlavor(TerminalFactory.Flavor.valueOf("UNIX"));
terminal.init();
terminal.setEchoEnabled(true);
ConsoleReader console = new ConsoleReader(System.in,System.out);
int key = console.readCharacter();

I use JLine v2.6. Echo doesn't work. What is wrong with the above code? Can somebody help?

Sick and tired of searching for other libraries like JLine. Is there any other Java library to handle console input?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Just a thought, if you're "sick and tired of searching for other[s]", then as jLine2 is actively and enthusiastically maintained, why not contribute to it? The cup seems half full to me .. – earcam Dec 02 '12 at 20:27

2 Answers2

2

JLine uses native code on every platform you run it on. Some terminals on some platforms don't have the correct settings for it to work right out of the box.

The default behavior varies between platforms because of the native terminals on those platforms, but it does work very well once you get it setup and configured correctly. Most likely your problem is your terminal emulation settings and has nothing to do with JLine.

That said, I have had great success with it on OSX ( bash ), Windows and RHEL/Centos ( bash ).

1

It seems ConsoleReader's readCharacter(); doesn't echo, but readLine() and readLine(String prompt) do.

Looking at the (easily available) source of console.readCharacter() method it explicitly calls (private) clearEcho() which clears the echo by moving a pointer back.

Although the documentation is a little thin, as jLine is designed to be compatible with GNU readLine and BSD editLine the emphasis does seem to be on providing console support for line processing.

I'd assume character processing is provided but you'd be responsible for echoing the character.

earcam
  • 6,662
  • 4
  • 37
  • 57