如何将彩色文本输出到 Linux 终端? [英] How do I output coloured text to a Linux terminal?
本文介绍了如何将彩色文本输出到 Linux 终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将彩色字符打印到支持它的 Linux 终端?
How do I print coloured characters to a Linux terminal that supports it?
如何判断终端是否支持色码?
How do I tell whether the terminal supports colour codes?
推荐答案
你需要输出ANSI颜色代码.请注意,并非所有终端都支持此功能;如果不支持颜色序列,则会显示垃圾.
You need to output ANSI colour codes. Note that not all terminals support this; if colour sequences are not supported, garbage will show up.
示例:
cout << "