Tmux - Tmux 真彩色无法正常工作

Tmux - Tmux true color is not working properly

我现在使用 tmux 有一段时间了,

我使用 vim 进行编码,并且仅当我将 vim 与 tmux 一起使用时,我才注意到与配色方案相关的一些缺陷。

两个终端都支持 256 色,当我 运行 这个:tput colors

当我测试我的终端以查看是否支持真彩色时,结果如下:

curl -s https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh | bash

终端的输出是这样的:

但是当我在 tmux 中 运行 时:

我已经检查了 echo $TERM 的结果,但它们都是 return 这个:

xterm-256color

所以我真的很困惑这里可能是什么问题=\

有什么想法吗?

非常感谢!

可能你在设置的时候忽略了这一点(可以看出你忽略了Tc):

commit 427b8204268af5548d09b830e101c59daa095df9
Author: nicm <nicm>
Date:   Fri Jan 29 11:13:56 2016 +0000

    Support for RGB colour, using the extended cell mechanism to avoid
    wasting unnecessary space. The 'Tc' flag must be set in the external
    TERM entry (using terminal-overrides or a custom terminfo entry), if not
    tmux will map to the closest of the 256 or 16 colour palettes.

    Mostly from Suraj N Kurapati, based on a diff originally by someone else.

在tmux.conf中:

# Enable RGB colour if running in xterm(1)
set-option -sa terminal-overrides ",xterm*:Tc"

联机帮助页中:

TERMINFO EXTENSIONS
     tmux understands some unofficial extensions to terminfo(5):
...
     Tc      Indicate that the terminal supports the ‘direct colour’ RGB
             escape sequence (for example, \e[38;2;255;255;255m).

             If supported, this is used for the OSC initialize colour escape 
             sequence (which may be enabled by adding the ‘initc’ and ‘ccc’  
             capabilities to the tmux terminfo(5) entry).

关于 -s-gmanual page 说:

set-option [-agoqsuw] [-t target-session | target-window] option value (alias: set)
Set a window option with -w (equivalent to the set-window-option command), a server option with -s, otherwise a session option. If -g is given, the global session or window option is set. The -u flag unsets an option, so a session inherits the option from the global options (or with -g, restores a global option to the default).

The -o flag prevents setting an option that is already set and the -q flag suppresses errors about unknown or ambiguous options.

With -a, and if the option expects a string or a style, value is appended to the existing setting.

据我了解, 使用 -s 意味着新连接(由服务器创建)将获得此设置,这在 shell 初始化中很有用,而 -g 使其更改对于 shell 来说太晚了初始化。

延伸阅读: