我想知道是否有什么办法可以设置我在 Java 中输出到控制台的文本的颜色。是否特定于系统并不重要,因为该程序只能在我的 Windows 7 x64 笔记本电脑上运行。
这个问题: Change color in java eclipse console 几周前被问及一个很好的解决方案(由@VonC)解决类似的问题,但它只解决了eclipse内部的问题。
如果我从命令行执行我的程序可以达到同样的效果吗?如果是这样怎么办?
I was wondering if there is someway for me to set the color of the text that I output to the console in Java. It does not matter if it is system specific as the program will only be run on my Windows 7 x64 laptop.
This question: Change color in java eclipse console was asked several weeks ago and had a good solution(by @VonC) to a similar problem however it only addressed the issue inside eclipse.
Can the same effect be achieved if I execute my program from the command line? and if so how?
发布评论
评论(5)
你可以看一下 Java Curses 库:
http://sourceforge.net/projects/javacurses/
以下是有关如何使用它的条目:
http://www.javaworld.com/javaworld /javaqa/2002-12/02-qa-1220-console.html
You can take a look at the Java Curses Library:
http://sourceforge.net/projects/javacurses/
Here's an entry on how to use it:
http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html
你这个……
进一步阅读 http://jansi.fusesource.org/
thy this....
furthermore read http://jansi.fusesource.org/
您可能感兴趣的另一个库是 Jansi: http://jansi.fusesource.org/
Jansi 解释 ANSI编码并格式化它们以用于控制台输出。它适用于 UNIX 和 Windows。
更新 11/2014: 您还可以查看 github 页面
Another library you may be interested in is Jansi: http://jansi.fusesource.org/
Jansi interprets ANSI code and format them for the console output. It works for both unix and windows.
Update 11/2014: you can also see the github Page
与 Java 控制台输出没有直接关系,但如果您希望在 Kotlin 控制台输出中使用 ANSI 颜色,这是一个很棒的库 - https://github.com/importre/crayon
Not directly related to Java console output, but if you're looking to use ANSI colors in Kotlin console output, this is a great library to use - https://github.com/importre/crayon
我的项目需要颜色。这里为大家准备了一堂课。只需执行 Colors.(color) +“whatever”即可添加颜色、粗体或斜体。使用 Colors.reset 重置颜色。希望这有帮助。
I needed colors for a project. Here is a class for everyone. Just do Colors.(color) + "whatever" to add color, bold, or italic. Use Colors.reset to reset the colors. Hope this helps.