shell 输入设置的颜色代码

1u4esq0p  于 12个月前  发布在  Shell
关注(0)|答案(1)|浏览(145)

我正在寻找一个包含此内容的文件

export fgBlack8="$(tput setf 0)";
export fgRed8="$(tput setf 1)";
export fgGreen8="$(tput setf 2)";
export fgYellow8="$(tput setf 3)";
export fgBlue8="$(tput setf 4)";
export fgMagenta8="$(tput setf 5)";
export fgCyan8="$(tput setf 6)";
export fgWhite8="$(tput setf 7)";

export bgBlack8="$(tput setb 0)";
export bgRed8="$(tput setb 1)";
export bgGreen8="$(tput setb 2)";
export bgYellow8="$(tput setb 3)";
export bgBlue8="$(tput setb 4)";
export bgMagenta8="$(tput setb 5)";
export bgCyan8="$(tput setb 6)";
export bgWhite8="$(tput setb 7)";

根据这个链接:https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/
然后,当用这样的几个命令测试颜色时,

echo -e "${fgBlack8}fgBlack8"
echo -e "${fgRed8}fgRed8"
echo -e "${fgGreen8}fgGreen8"
echo -e "${fgYellow8}fgYellow8"
echo -e "${fgBlue8}fgBlue8"
echo -e "${fgMagenta8}fgMagenta8"
echo -e "${fgCyan8}fgCyan8"
echo -e "${fgWhite8}fgWhite8"

我收到以下输出:

红如蓝,黄如青,反之亦然。是网站上的代码错了,还是我用错了,偶然产生了正确的颜色Map?

7d7tgy0s

7d7tgy0s1#

如果您使用的是tput命令,那么从

$ man tput

从SEE也将带您到

$ man terminfo

你会发现
setaf/setab和setf/setb功能各采用一个数值参数。终端硬件可以随意Map这些,但RGB值表示颜色空间中的正常位置。

Color       #define       Value       RGB
                black     COLOR_BLACK       0     0, 0, 0
                red       COLOR_RED         1     max,0,0
                green     COLOR_GREEN       2     0,max,0
                yellow    COLOR_YELLOW      3     max,max,0
                blue      COLOR_BLUE        4     0,0,max
                magenta   COLOR_MAGENTA     5     max,0,max
                cyan      COLOR_CYAN        6     0,max,max
                white     COLOR_WHITE       7     max,max,max

setf/setb的参数值在历史上对应于不同的Map,即,

Color       #define       Value       RGB
                black     COLOR_BLACK       0     0, 0, 0
                blue      COLOR_BLUE        1     0,0,max
                green     COLOR_GREEN       2     0,max,0
                cyan      COLOR_CYAN        3     0,max,max
                red       COLOR_RED         4     max,0,0
                magenta   COLOR_MAGENTA     5     max,0,max
                yellow    COLOR_YELLOW      6     max,max,0
                white     COLOR_WHITE       7     max,max,max

相关问题