zoukankan      html  css  js  c++  java
  • Linux下C 更改字符在终端的显示颜色

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


    比如:

    #include <stdio.h>


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

    return 0;
    }

    上面的01表示加粗,34表示是蓝色,后面33[0m表示恢复所有的属性为原来的默认值。也可以把上述的33字符用e替换。可以采用多种配色方案,比如上面提到的33[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
    "; 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
  • 相关阅读:
    Shell for
    rsync 目录 斜杠
    shell local
    linux secureCRT utf-8编码显示
    eclipse maven 项目不显示 target目录
    如何打印身份证实际大小
    linux 去掉 ^M
    hibernate 之 集合映射中list映射
    hibernate 之 复合主键映射
    hibernate 之 组件映射
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703244.html
Copyright © 2011-2022 走看看