I am trying to use the Jansi Java Library for using color in the CMD/Console and I have come across a little problem. When I use the Jansi Library and try to use the print f statement
System.out.printf("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?\n>> ");
the ">> " doesn't print at the end. Instead, the Scanner is called and asks for my input. Why does this happen and is there any way i can make it so that the ">> " and the Scanner input appear on one line?
import java.util.Scanner;
import org.fusesource.jansi.AnsiConsole;
public class Test {
public static void main(String[] args) {
AnsiConsole.systemInstall();
String name;
Scanner scanner = new Scanner(System.in);
String BLACK = "\u001B[0;30m";
String RED = "\u001B[0;31m";
String GREEN = "\u001B[0;32m";
String YELLOW = "\u001B[0;33m";
String BLUE = "\u001B[0;34m";
String MAGENTA = "\u001B[0;35m";
String CYAN = "\u001B[0;36m";
String WHITE = "\u001B[0;37m";
System.out.printf("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?\n>> ");
name = scanner.nextLine();
}
}
This code works fine after commenting out the AnsiConsole thing.
This is what I get printed out.
Hello young lad! What is thy [0;31mname [0;37myou were given at birth?
>> John