Java Scanner Class: Using Left and Right Buttons with Bash

I am not very familiar with Linux / Bash, so I cannot find the right search conditions.

Take a snippet:

public class Main {
    public static void main(String[] args) {
        java.util.Scanner keyboard = new java.util.Scanner(System.in);
        while(true) {
            System.out.print("$ ");
            String in = keyboard.nextLine();
            if(in.equals("q")) break;
            System.out.println("    "+in);
        }
    }
}

If I run it in my Linux box using Bash, I cannot use any of the arrow buttons (I am only interested in the button left- and rightby the way). For example, if I type "test" and then try to go back by pressing the left button, instead of my cursor, one character is returned ^[[D:

$ test^[[D  

I tried the new Console class , but the end result is the same. In windows shell cmd.exe, I don't have this problem.

, : Java, Bash, , ^[[D, ?

, " ". , , , Superuser, , -, Bash.

.

+3
2

Bash - , ; . , bash readline - Java, . , - .

+3

Source: https://habr.com/ru/post/1738717/


All Articles