JLine not showing chars after using readChar()

217 Views Asked by At

I tried to make simple keyboard tester in java so i use Jline for reading chars without pressing ENTER, but when i try to read line from Console it's not showing chars. I tried to use diffrent version of JLine (currently i use 2.14.6), reset Terminal , turn on Echo etc. But still nothing.

ConsoleReader console = new ConsoleReader();
    //ConsoleReader cr = new ConsoleReader();
    console.setKeyMap("UTF-8");
    
    System.out.println("Press ESC for end testing");
    int key = 0;
    while(key != 27) 
    {
        key = console.readCharacter(true);
        System.out.println(key + " : " + Character.getName(key));
    }
    
    
    
    //console.getTerminal().setEchoEnabled(true);
    console.getTerminal().init();
    console.getTerminal().reset(); 
    
    console.close();
    console.delete();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter text: ");
    
    System.out.println(br.readLine());
    br.close();

EDIT: I added this lines and it works

        console.getTerminal().setEchoEnabled(true);
        console.getTerminal().init();
        console.getTerminal().reset(); 
        console.getTerminal().restore(); 
1

There are 1 best solutions below

1
On

It looks like you're using JLine 2 and not JLine 3. Jline 2 has not been maintained since years, so you should really upgrade to 3.x