您的位置:首页 > 编程语言 > PHP开发

How to print colored output on the terminal

2012-05-20 22:47 471 查看
Procuding colored output on the terminal is very intersting stuff. We produce colored output using escape sequences.

Color codes are used to represent each color. For example, reset=0, black=30, red=31, green=32, yellow=33, blue=34, magenta=35, cyan=36, and white=37.
In order to print colored text, enter the following:
echo -e "e[1;31m This is red text e[0m"
Here e[1;31 is the escape string that sets the color to red and e[0m resets the color back.
Replace 31 with the required color code.
For a colored background, reset=0, black=40, red=41, green=42, yellow=43, blue=44, magenta=45, cyan=46, and white=47, are the color code that are commonly used.
In order to print a colored background, enter the following:
echo -e "e[1;42m Green Background e[0m"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: