-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Advertise directcolor support in Neovim terminal #24717
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
If the outer terminal claims to support truecolor through the $COLORTERM environment variable, then it should not be modified by Nvim just because 'termguicolors' is unset. If an application running in :terminal writes a direct color sequence (i.e. CSI 38 ; 2 ; <r> ; <g> ; <b> m) that sequence is forwarded directly to the outer terminal emulator, where it is displayed in truecolor if the terminal supports it, regardless of the value of 'termguicolors'. The only affect that 'termguicolors' has on colors for applications in :terminal is how the 16 ANSI colors are displayed (when 'termguicolors' is set, the ANSI colors are set with g:terminal_color_x; otherwise, they are forwarded directly to the outer terminal). Ref: neovim#13315 Fixes: neovim#24717
This may not actually be true, looking into it further. @hpjansson In any case, this issue can be closed because Nvim does advertise direct color support via the |
Great, so the resolution is that it's the user's responsibility, then. Thanks for the clarification. |
No I don't think so, unless I'm misunderstanding. From your issue:
It does do this, via the |
Lines 3985 to 3991 in 88887a7
The problem is with "only if it was set in the parent terminal at all". Unfortunately, that can't always be relied on. E.g. openssh preserves local$ echo $TERM $COLORTERM
vte-direct truecolor
local$ ssh remote
remote$ echo $TERM $COLORTERM
vte-direct
remote$ nvim
# :terminal
remote-nvim$ echo $TERM $COLORTERM
xterm-256color The user can work around it either by setting |
I'm trying to think of an example where setting If If the user has I didn't see any discussion in #13315 around the reasoning for only setting But we could try it out and see what (if anything) breaks. |
$COLORTERM is set in the terminal emulator based on the value of 'termguicolors' ("truecolor" if &tgc is set, 256 otherwise), but ONLY if $COLORTERM is also set in the parent terminal emulator. This is an unnecessary restriction that can cause issues in some cases. For instance, $COLORTERM is stripped by default by OpenSSH, so is not present in an SSH session. The terminal emulator still supports 24 bit color, so the presence of $COLORTERM is not a very reliable indicator. Instead, setting it unconditionally based on 'termguicolors' uses the user's own preferences to infer if 24-bit color is supported. If 'termguicolors' is set in a terminal that does not support true color then the colors in Nvim will already look bad. Enabling them for applications in the terminal emulator will not make it any worse. Fixes: neovim#24717
Thanks a lot, @gpanders! From |
$COLORTERM is set in the terminal emulator based on the value of 'termguicolors' ("truecolor" if &tgc is set, 256 otherwise), but ONLY if $COLORTERM is also set in the parent terminal emulator. This is an unnecessary restriction that can cause issues in some cases. For instance, $COLORTERM is stripped by default by OpenSSH, so is not present in an SSH session. The terminal emulator still supports 24 bit color, so the presence of $COLORTERM is not a very reliable indicator. Instead, setting it unconditionally based on 'termguicolors' uses the user's own preferences to infer if 24-bit color is supported. If 'termguicolors' is set in a terminal that does not support true color then the colors in Nvim will already look bad. Enabling them for applications in the terminal emulator will not make it any worse. Do not set COLORTERM to 256 if 'termguicolors' is not enabled, because the underlying terminal may not support 256 colors. $TERM is set to xterm-256color by default, which is sufficient to allow applications running in :terminal to determine 256 color support. Fixes: neovim#24717
$COLORTERM is set in the terminal emulator based on the value of 'termguicolors' ("truecolor" if &tgc is set, 256 otherwise), but ONLY if $COLORTERM is also set in the parent terminal emulator. This is an unnecessary restriction that can cause issues in some cases. For instance, $COLORTERM is stripped by default by OpenSSH, so is not present in an SSH session. The terminal emulator still supports 24 bit color, so the lack of $COLORTERM is not a reliable indicator. When an application runs in Nvim's :terminal it thus has no way to know whether or not true color is supported. Instead, setting it unconditionally based on 'termguicolors' uses the user's own preferences to infer if 24-bit color is supported, rather than depending on the (unreliable) presence of $COLORTERM. If 'termguicolors' is set in a terminal that does not support true color then the colors in Nvim will already look bad. Enabling them for applications in the terminal emulator will not make it any worse. If 'termguicolors' is not set then the value of $COLORTERM from the parent terminal (if any) is forwarded to Nvim's :terminal. Fixes: neovim#24717
$COLORTERM is set in the terminal emulator based on the value of 'termguicolors' ("truecolor" if &tgc is set, 256 otherwise), but ONLY if $COLORTERM is also set in the parent terminal emulator. This is an unnecessary restriction that can cause issues in some cases. For instance, $COLORTERM is stripped by default by OpenSSH, so is not present in an SSH session. The terminal emulator still supports 24 bit color, so the lack of $COLORTERM is not a reliable indicator. When an application runs in Nvim's :terminal it thus has no way to know whether or not true color is supported. Instead, setting it unconditionally based on 'termguicolors' uses the user's own preferences to infer if 24-bit color is supported, rather than depending on the (unreliable) presence of $COLORTERM. If 'termguicolors' is set in a terminal that does not support true color then the colors in Nvim will already look bad. Enabling them for applications in the terminal emulator will not make it any worse. If 'termguicolors' is not set then the value of $COLORTERM from the parent terminal (if any) is forwarded to Nvim's :terminal. Fixes: #24717
Problem
The Neovim terminal (
:terminal
) does not appear to advertise directcolor support anywhere whentermguicolors
is set. This makes it impossible for CLI programs to unambiguously determine whether directcolor sequences can be used when running in the Nvim terminal.Steps to reproduce:
nvim
.chafa
, from its master branch.unset COLORTERM NVIM_TUI_ENABLE_TRUE_COLOR
(the former may not be present, and it's my understanding that the latter is deprecated).export TERM=vte
. This step probably doesn't matter as long as you indicate an outer terminal that has directcolor support.nvim
.:terminal
in Nvim and hiti
.chafa test.png
.chafa
has no way to determine whether the Nvim terminal supports directcolor, so will only use 256 colors. If you try to use directcolor, the output will look corrupted.set termguicolors
toinit.vim
.chafa
will still use only 256 colors, because it can't determine from the environment that directcolor support is now available.chafa -c full test.png
and observe that correct directcolor output is possible if forced.Additionally, the inner
TERM
is set toxterm-256color
in both cases and there appears to be no other environment variables indicating directcolor support.COLORTERM
almost does the job, but Neovim doesn't set it unconditionally.Expected behavior
Neovim should make it possible for CLI programs to differentiate 256-color from directcolor
:terminal
environments. The exact mechanism is of lesser importance, but I guess it could either export a different TERM string or set some other environment variable. The goal is to produce optimal output in Neovim without extra prompting from the user.It could also be resolved with some policy, e.g. "it's the user's responsibility to ensure
COLORTERM
is set".A quick test with vim 9.0.1632 showed that it exports
COLORS=16777216
when outerTERM=xterm-direct2
.The text was updated successfully, but these errors were encountered: