java 如何使用 Jansi 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5778946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use the Jansi library?
提问by Taranath Datta
I want to know how to use Jansi to print color in the command prompt on Windows.
我想知道如何使用 Jansi 在 Windows 的命令提示符中打印颜色。
回答by Favonius
From: http://www.rgagnon.com/javadetails/java-0047.html
来自:http: //www.rgagnon.com/javadetails/java-0047.html
import org.fusesource.jansi.AnsiConsole;
public class Test {
public static final String ANSI_CLS = "\u001b[2J";
public static final String ANSI_HOME = "\u001b[H";
public static final String ANSI_BOLD = "\u001b[1m";
public static final String ANSI_AT55 = "\u001b[10;10H";
public static final String ANSI_REVERSEON = "\u001b[7m";
public static final String ANSI_NORMAL = "\u001b[0m";
public static final String ANSI_WHITEONBLUE = "\u001b[37;44m";
public static void main(String args[]){
AnsiConsole.systemInstall();
AnsiConsole.out.println(ANSI_CLS);
AnsiConsole.out.println
(ANSI_AT55 + ANSI_REVERSEON + "Hello world" + ANSI_NORMAL);
AnsiConsole.out.println
(ANSI_HOME + ANSI_WHITEONBLUE + "Hello world" + ANSI_NORMAL);
AnsiConsole.out.print
(ANSI_BOLD + "Press a key..." + ANSI_NORMAL);
try {System.in.read();}catch(Exception e){}
AnsiConsole.out.println(ANSI_CLS);
AnsiConsole.systemInstall();
}
}
And do not try to run within eclipse. The colors won't appear on eclipse console. Bundle it in a jar and run it on windows console i.e. command prompt.
并且不要尝试在 eclipse 中运行。颜色不会出现在 eclipse 控制台上。将它捆绑在一个 jar 中并在 Windows 控制台(即命令提示符)上运行它。
For better result try to be more specific when asking questions, like, providing a link to the library which you are referring to and if possible whatever piece of code you have written.
为了获得更好的结果,请在提问时尝试更具体,例如,提供指向您所指的库的链接,以及如果可能的话,提供您编写的任何代码段。
By the way I got that link by just googling: Jansi+ANSI+Color
顺便说一下,我只是通过谷歌搜索获得了该链接: Jansi+ANSI+Color