tmux 调色板如何工作?

law*_*nce 165 tmux

我正在尝试将某些内容设置为灰色,但不知道如何设置。手册页中关于颜色的唯一信息是:

message-bg colour
  Set status line message background colour, where colour is one of:
  black, red, green, yellow, blue, magenta, cyan, white, colour0 to
  colour255 from the 256-colour palette, or default.
Run Code Online (Sandbox Code Playgroud)

我还发现了一篇迭代颜色的博客文章,但我不能完全理解它,并且不想整天坐在终端猜测颜色数字,直到它起作用为止。

cYr*_*rus 254

您可以使用此bash代码段获取列表:

for i in {0..255}; do
    printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"
done
Run Code Online (Sandbox Code Playgroud)

然后colourxxxtmux.

  • 我的 `tmux` (1.6) 甚至接受像 `colour12` 这样的颜色(注意“u”)。 (7认同)

Edd*_*ker 119

我发现这张图片很有启发性。

在此处输入图片说明

  • 您可以使用 `for i in {0..255} 创建它;做 printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; 如果 !((($i + 1) % 8)); 然后回声; 菲; 完成` (32认同)
  • 使用“for i in {0..255}”生成在“colour15”之后对颜色进行分组的替代输出;printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; 如果 !(( ($i - 3) % 6 )); 然后回声;菲 ; 完成`。 (2认同)

小智 25

在 Subversion(将是 tmux 1.5)中,您还可以使用 #abcdef 十六进制样式的颜色,这些颜色映射到最近的 256 调色板条目。您需要引号,因为它被视为字符串,而常规颜色名称被视为命名常量。另请注意,3 个字母的速记 (#f00) 无效。

例子:

set pane-active-border-bg red # no quotes for name
set pane-active-border-bg "#ff0000" # quotes for rgb
Run Code Online (Sandbox Code Playgroud)

  • 设置选项消息-bg“#abcdef”;引号是必要的。 (6认同)

小智 15

在 tmux 3.2(2021 年 4 月发布)之前,tmux 仅支持 256 调色板的国际(英式)拼写,例如

"colour121"
Run Code Online (Sandbox Code Playgroud)

而不是在美国的拼写是下降的u

"color121"
Run Code Online (Sandbox Code Playgroud)

如果您使用 tmux 3.2 或更高版本,则可以任意拼写。


小智 7

我一直在使用xterm-color-table.vim脚本。任何 256 色终端颜色表都可以使用。


air*_*ike 7

基于@cYrus 的回答,我编写了一个脚本将颜色的输出分成 N 列,其中 N 是第一个参数

# colors.sh

#!/bin/bash
if [ -z $1 ]; then
    BREAK=4
else
    BREAK=$1
fi
for i in {0..255} ; do
    printf "\x1b[38;5;${i}mcolour${i} \t"
    if [ $(( i % $BREAK )) -eq $(($BREAK-1)) ] ; then
        printf "\n"
    fi
done
Run Code Online (Sandbox Code Playgroud)

尝试将其保存到名为 colors.sh 的文件中,然后 ./colors.sh 4

别忘了chmod +x colors.sh先。

  • 脚本 [show-256-colors.sh](https://gist.github.com/ivanbrennan/8ce10a851851e5f04728d8da900ef1c5) 也可用于显示背景颜色。 (4认同)