printf "\033[31;42mhello world\033[0m\n"
C语言设置输出的字体前景色和背景色
颜色如下:
none = "\033[0m"
black = "\033[0;30m"
dark_gray = "\033[1;30m"
blue = "\033[0;34m"
light_blue = "\033[1;34m"
green = "\033[0;32m"
light_green -= "\033[1;32m"
cyan = "\033[0;36m"
light_cyan = "\033[1;36m"
red = "\033[0;31m"
light_red = "\033[1;31m"
purple = "\033[0;35m"
light_purple = "\033[1;35m"
brown = "\033[0;33m"
yellow = "\033[1;33m"
light_gray = "\033[0;37m"
white = "\033[1;37m"
字背景颜色范围: 40--49 字颜色: 30--39
40: 黑 30: 黑
41:红 31: 红
42:绿 32: 绿
43:黄 33: 黄
44:蓝 34: 蓝
45:紫 35: 紫
46:深绿 36: 深绿
47:白色 37: 白色
输出特效格式控制:
\033[0m 关闭所有属性
\033[1m 设置高亮度
\03[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐
\033[30m -- \033[37m 设置前景色
\033[40m -- \033[47m 设置背景色
光标位置等的格式控制:
\033[nA 光标上移n行
\03[nB 光标下移n行
\033[nC 光标右移n行
\033[nD 光标左移n行
\033[y;xH设置光标位置
\033[2J 清屏
\033[K 清除从光标到行尾的内容
\033[s 保存光标位置
\033[u 恢复光标位置
\033[?25l 隐藏光标
\33[?25h 显示光标
例子(.sh文件中实现):
printf "\033[0m My father \033[0;30m was a \033[1;30m self-taught \033[0;34m mandolin player. \033[1;34m He was \033[0;32m one of \033[1;32m the best \03 3[0;36m string instrument \033[1;36m players in \033[0;31m our town. \033[1; 31m He could \033[0;35m not read music, \033[1;35m but if \033[0;33m he hear d \033[1;33m a tune a \033[0;37m few times, \033[1;37m he could \033[30m pl ay it. \033[47m When he \033[40m was younger, 033[47m he was a member of a s mall country music band. "
效果: