用另一种颜色显示System.out.println输出 [英] Show System.out.println output with another color
问题描述
System.out.println
方法/ p> 例如:
System.out.println(我想要这是红色);
System.out.println(我希望这是蓝色);
System.out.println(我希望这是黄色);
System.out.println(我希望这是洋红色);
更多的可读性。
编辑
与sysout我有这个
与syserr我有这个
在Eclipse中,最简单的方法是使用 System.err.println
为您想要红色的行 - 我认为这是默认值。 (您可以在首选项 - >运行/调试 - >控制台)中更改。
在实际运行时,差异不会显示>控制台当然,但我不认为 Eclipse控制台支持ANSI颜色转义序列等。
编辑:对于Windows控制台,我希望 ANSI转义序列工作。它不是非常便于携带,但如果这不是问题,您可以创建一个类来适当地封装转义序列,因此可以调用以下内容:
ansiConsole.printRed(sample line in red);
ansiConsole.printBlue(sample line in blue);
(我可能会使这些方法返回到每次调用后的当前颜色。)
编辑:如评论中所述, Jansi <一个>库已经存在,所以你也可以使用它。它没有上述方法,但我确定它仍然会做你想要的...
I have a big project to debug, and I was wondering if there is anyway I could use to change the System.out.println
method in the output of eclipse
for example :
System.out.println("I want this to be red");
System.out.println("I want this to be blue");
System.out.println("I want this to be yellow");
System.out.println("I want this to be magenta");
for more readability.
EDIT
with sysout I have this
with syserr I have this
Within Eclipse, the simplest approach would be to use System.err.println
for lines you want to be in red - I believe that's the default. (You can change it in Preferences -> Run/Debug -> Console).
That difference won't show up when running in a real console of course, but I don't think the Eclipse console supports ANSI colour escape sequences etc.
EDIT: For the Windows console, I'd expect ANSI escape sequences to work. It's not hugely portable, but if that's not a problem, you could just create a class to encapsulate the escape sequences appropriately, so you could call something like:
ansiConsole.printRed("sample line in red");
ansiConsole.printBlue("sample line in blue");
(I'd probably make those methods return back to whatever the "current" colour was after each call.)
EDIT: As noted in comments, the Jansi library already exists, so you might as well use that. It doesn't have the methods described above, but I'm sure it'll still do what you want...
这篇关于用另一种颜色显示System.out.println输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!