[英]How to change my eclipse console results line color.For every line different color using java selenium
我想像這樣打印 eclipse 控制台
System.out.println("他是板球運動員"); red color
System.out.println("他是個舞者"); yellow color
System.out.println("他是一名足球運動員"); green color
System.out.println("他是一名截擊球員"); grey color
控制台顏色由 Eclipse 設置控制,但它不能在同一個流中打印不同的顏色。 例如,默認情況下所有System.err
文本為紅色,所有System.out
文本為黑色(如果您有深色主題,則為白色)。
您可以做的是在Eclipse 的控制台插件中安裝ANSI Escape ,以便 Eclipse 控制台可以解釋 ANSI Escape 代碼。 安裝它並重新啟動 Eclipse 。
然后你可以使用 ANSI 顏色代碼做這樣的事情:
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_CYAN = "\u001B[36m";
public static void main(String[] args) {
System.out.println(ANSI_RED + "this text is red" + ANSI_RESET);
System.out.println(ANSI_YELLOW + "this text is yellow" + ANSI_RESET);
System.out.println(ANSI_CYAN + "this text is cyan" + ANSI_RESET);
}
這是結果:
如果您需要更多顏色,這里是 ANSI 顏色代碼的完整列表。
另外,請注意ANSI_RESET
在關閉所有屬性的情況下使文本恢復正常。 確保在打印彩色文本后使用它來重置默認顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.