Tmux - Tmux真彩色未正常工作

34

我已经使用tmux有一段时间了,

我使用vim进行编码,并且注意到只有当我与tmux一起使用vim时才会出现一些与颜色方案相关的缺陷。

当我运行此命令时,两个终端都支持256种颜色:tput colors

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

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

终端输出的是这样的: 在此输入图片描述

但当我在tmux中运行时,结果是这样的: 在此输入图片描述

我已经检查了echo $TERM的结果,但它们都返回相同的值:

xterm-256color

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

有什么想法吗?

非常感谢!


对我来说,在我的 .bashrc 文件中设置 alias tmux='tmux -2' 解决了这个问题。 - jaaq
1个回答

46

或许在设置时您忽略了以下内容(可以看出您忽略了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"

在man手册中:

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-g手册页面中写道:

set-option [-agoqsuw] [-t target-session | target-window] option value (别名: set)
使用-w设置窗口选项(等同于set-window-option命令),使用-s设置服务器选项,否则设置会话选项。如果给出-g,则设置全局会话或窗口选项。-u标志取消一个选项,这样会话就可以从全局选项继承该选项(或使用-g将全局选项恢复为默认值)。

-o标志防止设置已经设置的选项,-q标志抑制有关未知或模糊选项的错误。

使用-a,如果选项需要字符串或样式,则将值附加到现有设置。

据我所知,使用-s意味着新连接(由服务器创建)将获得此设置,这在shell初始化中很有用,而-g使其更改过晚,无法在shell初始化时生效。
进一步阅读:

5
请问你能否解释一下 set-option -sa terminal-overrides ",xterm*:Tc"set-option -ga terminal-overrides ",xterm-256color:Tc" 之间的区别(大多数博客似乎都建议使用后者),到目前为止,您建议的片段 set-option -sa terminal-overrides ",xterm*:Tc" 是唯一对我起作用的东西。 - Otis Wright
1
“-sa”而不是“-ga”确实是使真彩色对我起作用的关键因素。谢谢! - joar
1
-s 是一个服务器选项,-g 是一个全局会话选项(与仅影响当前会话的非全局会话选项相对)。这个 SO 回答 更好地解释了它。 - Chris
4
似乎现在(从tmux 3开始,可能更早)使用RGB选项比使用Tc tmux扩展更受推荐。具体用法可参考 https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-rgb-colour。 - bric3
手册中说 tmux 理解一些非官方的 terminfo(5) 扩展: 来源,并列出了 Tc,但如果您查看 terminfo 手册,则会发现有一个 RGB 条目 来源。关于这个话题还有更多内容:https://gist.github.com/XVilka/8346728 - bric3
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接