I would like to use a select element in a Java CLI, similar to this example:

that I stole from https://github.com/go-survey/survey
I found plenty of information about how you could do it in Go, but I did not find something useful for Java except the library https://github.com/mabe02/lanterna which is not really what I am looking for because I tries to create a whole GUI in a shell, and does not support powershell or cmd on Windows.
Can anyone tell me how to do this?
I can't remember such ready to use library. But you may create one. You can utilize ANSI escape codes for coloring text and VT100 control codes for cursor positioning.
Here is an example for color:
public static final String RED = "\033[0;31m"; // RED
public static final String RESET = "\033[0m"; // Text Reset
public static void main(String[] args) {
System.out.println(RED + "This text is red!" + RESET);
}
and for position:
System.out.print(String.format("\033[%d;%dH", row, column));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With