Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True color support not working in tmux #312

Closed
thomasjachmann opened this issue Feb 6, 2018 · 11 comments
Closed

True color support not working in tmux #312

thomasjachmann opened this issue Feb 6, 2018 · 11 comments

Comments

@thomasjachmann
Copy link

Got this on a Retina MacbookPro (2016) running macOS Sierra (10.12.6).

This is a follow-up for #306. After I was able to start tmux, I noticed it doesn't seem to know the terminal supports true colors, so it doesn't use the full palette.

in kitty (without tmux):
bildschirmfoto 2018-02-06 um 11 43 28

in tmux (inside kitty):
bildschirmfoto 2018-02-06 um 11 43 01

This works in other terminals with the same tmux configuration, maybe the terminfo misses some information about true color support?

@kovidgoyal
Copy link
Owner

terminfo does not have any information about truecolor support. The terminfo maintainer refused to add it. I have no idea what tmux uses to guess if a terminal support true color or not, you'd have to ask its maintainers. It might be a custom terminfo capability or it might be hardcoded. If the former, I can probably add it to kitty's terminfo, if the latter tmux will need to be changed.

@thomasjachmann
Copy link
Author

For documentation: After your answer, I remembered a way to tell tmux it should use true color support. You need to specify terminal-overrides in your tmux.conf:

set -ag terminal-overrides ",xterm-kitty:Tc"

You could also use xterm-* instead of xterm-kitty in order to set this for all xterm terminals.

@kovidgoyal
Copy link
Owner

You can do this in tmux:

set-option  -ga terminal-overrides  ",xterm-kitty:Tc"

@thomasjachmann
Copy link
Author

duplicate comment :D

@MindTooth
Copy link
Contributor

MindTooth commented May 15, 2018

NB! This is not the correct way. One should never set the default-terminal to anything else than screen|tmux. Use the 256 variant. Seems kitty supports 24-bit out of the box.

Either set

set -g default-terminal "screen-256color"

or with newer ncurses version

set -g default-terminal "tmux-256color"

DON'T DO

Don't know if something has changed, but I only need to set:

set -g default-terminal "xterm-kitty"

And so far I've had no issue.

@wookayin
Copy link

@MindTooth But that won't work if one uses another terminal emulator, would it? (e.g., sometimes kitty, sometimes iTerm2)

@MindTooth
Copy link
Contributor

MindTooth commented Mar 20, 2020

@MindTooth But that won't work if one uses another terminal emulator, would it? (e.g., sometimes kitty, sometimes iTerm2)

You're absolutly right. I've updated my original post. One should never use anything other than screen*|tmux* as default terminal inside tmux.

Seems kitty works with 24-bit color, but I've yet to make iTerm2 support it.


Adding tmux-256color on macOS

Following this post.

$ brew install ncurses
$ /usr/local/opt/ncurses/bin/infocmp tmux-256color > ~/tmux-256color.info
$ tic -xe tmux-256color tmux-256color.info
# This creates a complied entry in ~/.terminfo
$ infocmp tmux-256color | head
#       Reconstructed via infocmp from file: /Users/libin/.terminfo/74/tmux-256color
tmux-256color|tmux with 256 colors,

Maybe for italic in Vim

" Unable italic support in iTerm2
let &t_ZH="\e[3m"
let &t_ZR="\e[23m"

@tomasz-wiszkowski
Copy link

tomasz-wiszkowski commented Jun 11, 2021

Sharing solution for anyone interested. Just got it working.

infocmp -a xterm-kitty > xterm-kitty.terminfo
# The following are for tmux
echo '    setrgbb=\E[48;2;%p1%d;%p2%d;%p3%dm, ' >> xterm-kitty.terminfo
echo '    setrgbf=\E[38;2;%p1%d;%p2%d;%p3%dm, ' >> xterm-kitty.terminfo
# The following are for emacs
echo '    setb24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, ' >> xterm-kitty.terminfo
echo '    setf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, ' >> xterm-kitty.terminfo
tic -x -o ~/.terminfo xterm-kitty.terminfo

Please also note you need to add true color override to your .tmux.conf file:

set -g default-terminal "screen-256color"
set-option -ga terminal-overrides ",screen-256color:Tc"

Local term caps will take precedence over system-wide capabilities, so this should work.

Kitty already defines setaf and setab term caps, but this is not what tmux is looking for (setrgbf and setrgbb). tmux tries the other variant, and when it can't find proper descriptors, it falls back to next available mode (256color, next 16 color).

I completely understand Kovid in this matter: there's a lot of bad fragmentation here and the setrgb[fb] and set[fb]24 caps should not have been randomly invented, but alas, this is not an ideal world.

Last but not least: in case your shell does not report this correctly, add the following to your ~/.${SHELL}rc:

export COLORTERM=truecolor

this fixes issues with lots of apps that do not use terminfo/curses/... querying for terminal color support.

@kovidgoyal
Copy link
Owner

kitty's terminfo has had those capabilities for years 2ab6f57

@tomasz-wiszkowski
Copy link

tomasz-wiszkowski commented Jun 11, 2021

Thanks for bringing this up Kovid. I did not realize this and infocmp does not dump these keys by default.

Looking a bit deeper it looks to me that there is one minor update that would help in the documentation:

The documentation suggests to run:

infocmp xterm-kitty | ssh myserver tic -x -o \~/.terminfo /dev/stdin

but infocmp won't dump these keys by default:

% infocmp
#	Reconstructed via infocmp from file: /Applications/kitty.app/Contents/Resources/kitty/terminfo/78/xterm-kitty
xterm-kitty|KovIdTTY,
        ...
	rmcup=\E[?1049l, rmir=\E[4l, rmkx=\E[?1l, rmso=\E[27m,
	rmul=\E[24m, rs1=\E]\E\\\Ec, sc=\E7,
	setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
	setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
	sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
	sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
	smcup=\E[?1049h, smir=\E[4h, smkx=\E[?1h, smso=\E[7m,
	smul=\E[4m, tbc=\E[3g, tsl=\E]2;, u6=\E[%i%d;%dR, u7=\E[6n,
	u8=\E[?%[;0123456789]c, u9=\E[c, vpa=\E[%i%p1%dd,

so these keys don't get pushed to remote machine (cloud, headless workstations etc).

now infocmp -a does is what helps:

 infocmp -a
#	Reconstructed via infocmp from file: /Applications/kitty.app/Contents/Resources/kitty/terminfo/78/xterm-kitty
xterm-kitty|KovIdTTY,
        ...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, kRIT3=\E[1;3C, kRIT4=\E[1;4C,
	kRIT5=\E[1;5C, kRIT6=\E[1;6C, kRIT7=\E[1;7C, kUP=\E[1;2A,
	kUP3=\E[1;3A, kUP4=\E[1;4A, kUP5=\E[1;5A, kUP6=\E[1;6A,
	kUP7=\E[1;7A, rmxx=\E[29m,
	setrgbb=\E[48\:2\:%p1%d\:%p2%d\:%p3%dm,
	setrgbf=\E[38\:2\:%p1%d\:%p2%d\:%p3%dm, smxx=\E[9m,

Pretty sure lots of us here got caught by this.

would it make sense to update the documentation to suggest running:

infocmp -a xterm-kitty | ssh myserver tic -x -o \~/.terminfo /dev/stdin

please? I am pretty confident this is what we're universally running into...


Looks like emacs custom keys are not there. I'm not an emacs user so don't know how relevant this is, or if emacs caught up with setrgb[fb] by now...

@kovidgoyal
Copy link
Owner

Sure, done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants