【问题标题】:Color codes for tput setftput setf 的颜色代码
【发布时间】:2019-02-23 05:38:23
【问题描述】:

我正在采购包含此内容的文件

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"

我收到以下输出:

将红色显示为蓝色,黄色显示为青色,反之亦然。是网站上的代码错误还是我使用错误并意外生成了正确的颜色映射?

【问题讨论】:

  • 您似乎混淆了setaf/setab 颜色和setf/setb 颜色。详情见man 5 terminfo
  • @DavidC.Rankin 这有帮助,谢谢。我检查了 man bash 因为我不知道该查看哪个页面并且(令人惊讶的惊喜)没有找到任何东西,因此使用了草率撰写的文章。
  • 发生在我们所有人身上。我只是从过去的某个地方回忆起terminfo 是该去的地方。祝你的脚本好运。

标签: bash shell


【解决方案1】:

如果您使用的是tput 命令,那么从逻辑开始

$ man tput

SEE ALSO 将带您前往

$ man terminfo

你会发现

setaf/setab 和 setf/setb 功能采用单个数字参数 更换每个。 终端硬件是 随意映射这些,但 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 的参数值历来对应不同的 映射,即,

                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

【讨论】:

  • 你也可以看看这个gist 看看颜色在行动
猜你喜欢
  • 1970-01-01
  • 2013-11-11
  • 2018-08-30
  • 2013-09-24
  • 2020-12-25
  • 1970-01-01
  • 2016-11-28
  • 1970-01-01
  • 2014-05-20
相关资源
最近更新 更多