我正在尝试使用Jansi Java库在CMD / Console中使用颜色,我遇到了一个小问题。当我使用Jansi Library并尝试使用print f语句
时System.out.printf("Hello young lad! What is thy " + RED + "name " + WHITE + "you were given at birth?\n>> ");
“>>”最后不打印。而是调用扫描仪并询问我的输入。为什么会发生这种情况,是否有任何方法可以使“>>”和扫描仪输入显示在一行上?
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();
}
}
答案 0 :(得分:1)
此代码在注释掉AnsiConsole之后工作正常。
这是我打印出来的。
Hello young lad! What is thy [0;31mname [0;37myou were given at birth?
>> John