Linux下C 更改字符在终端的显示颜色

使用\033[01;04;32;41m之类的配色方案在需要输出显示的文本之前,可以改变应用程序输出文本的颜色或者背景颜色。


比如:

#include <stdio.h>


int main(void) {
printf("\033[01;34m Hello World!\033[0m\n");

return 0;
}

上面的01表示加粗,34表示是蓝色,后面\033[0m表示恢复所有的属性为原来的默认值。也可以把上述的\033字符用\e替换。可以采用多种配色方案,比如上面提到的\033[01;04;32;41m,04表示下划线,32表示前景色是绿色,然后41表示背景色是红色。

由于使用的是Linux系统为终端提供的配色方案,所以该程序不具备移植性。可以看到,该程序在Windows会打印一些奇怪的符号。 

 

Some fun

You can paste the following into a terminal to get a stupid matrix like screensaver, or for an infinitely better example, see cmatrix.

tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock |
GREP_COLOR="1;32" grep --color "[^ ]"

For a silly 256 colour demo here is a command line to cycle through all shades of gray

yes "$(seq 232 255;seq 254 -1 233)" |
while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done

Note also the venerable game 0verkill, and the Colour AsCii Art library, which is included with mplayer for example:

mplayer -vo caca video.mpg

 

 

 

转载于:https://www.cnblogs.com/Stomach-ache/p/3703244.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值