Up arrow based command history in console input (Java)

62 Views Asked by At

I am currently using:

Scanner scanner = new Scanner(System.in);

To get user input in Java, but I want to add a way for user to use previous command easily. If users presses UP key it should show previous command instead of ^[[A. It shouldn't suggest after I press enter. It should work like in bash. For example, I can type arrow key it displays previous command, I can modify it and then press enter to send command. Is it possible in Java? I tried using libraries like JLine, but I could get it working.

0

There are 0 best solutions below