Skip to content

Colours come out with when running in NeoVim with termguicolors. #36

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

Closed
xfbs opened this issue May 21, 2019 · 8 comments
Closed

Colours come out with when running in NeoVim with termguicolors. #36

xfbs opened this issue May 21, 2019 · 8 comments

Comments

@xfbs
Copy link
Contributor

xfbs commented May 21, 2019

For some reason, when using NeoVim, and having set termguicolors enabled, the colors don't come out right. Here's what I mean:

This is in NeoVim, with notermguicolors set. Looks as it should.
notermguicolors

This is in NeoVim, with termguicolors set. Looks slightly wrong. Note especially the reddish colour of the "bright_white".
termguicolors

@roosta
Copy link
Member

roosta commented May 21, 2019

Could this be related to #35? I'll have a look at this later today.

@xfbs
Copy link
Contributor Author

xfbs commented May 21, 2019

As it turns out, this does not seem to be a bug with srcery! So here's what (I think) I figured out. Normally, when running Vim, the colorscheme loads something like

hi Normal ctermfg=15 ctermbg=0 guifg=#FCE8C3 guibg=#1C1B19

What Vim does with this is that it takes the ctermfg and ctermbg values and uses it to color text, by sending ANSI escape sequences like this:

printf "\033[38;5;15mforeground color\033[0m"

There are 256 colors available to use like this. This works. The guibg and guifg values are only used for GUI clients. However, in NeoVim, if I set termguicolors, then it does something a bit different. It uses the hex color values for the GUI in the terminal. Some terminals support arbitrary RBG colors using a different ANSI escape sequence. The foreground color, #FCE8C3, would be encoded like this:

printf "\033[38;2;252;232;195mTEST TEST TEST\033[0m"

However, this is not supported by Terminal.app. I'm guessing that tmux sensed this and basically faked the colours by converting them to the 256 color space, which lead to them being off? Not entirely sure.

@roosta
Copy link
Member

roosta commented May 22, 2019

Could be it, Emacs does something similar when presented with color hexes in terminal. It tries to conform it to the 256 color space. I'm not sure its tmux that's doing it, I'm guessing its Neovim. Either way this is expected behavior. Have you tried the same thing in a true color terminal?

@xfbs
Copy link
Contributor Author

xfbs commented May 22, 2019

I actually confirmed it's tmux that is mapping the 24-bit colors. If I run NeoVim in a 24-bit capable terminal, it works fine with both termguicolors and notermguicolors:

Screenshot 2019-05-22 at 19 46 18

Screenshot 2019-05-22 at 19 46 24

I found a script to generate a rainbow, and it looks like this:

Screenshot 2019-05-22 at 19 29 35

However, when running it in tmux, the output looks like such:

Screenshot 2019-05-22 at 19 29 27

It's possible to force tmux not to do this. Tmux is actually the reason that running NeoVim in Terminal.app with termguicolors worked in first place: Terminal.app doesn't support 24-bit colors. So I guess the takeaway is: don't use termguicolors. However:

If you have a 24-bit capable terminal emulator and you want to use 24-bit colors

Force tmux to pass through 24-bit color codes (unless it detects that your terminal does this)

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

Tell vim to use 24-bit colors

set termguicolors

I also had to set TERM manually. It's kinda messy. But it works:

Screenshot 2019-05-22 at 19 55 33

Screenshot 2019-05-22 at 19 55 24

Maybe this could be useful to someone? Not sure. Interesting to learn how this stuff all works, tho.

@MindTooth
Copy link
Member

MindTooth commented May 22, 2019

This is with Terminal.app? With kitty I have no issues AFAIK. The rainbow shows fine.

With kitty I only set:

set -g default-terminal 'xterm-kitty'

Ed1t: You know the motto: learn by doing. 😉

@roosta
Copy link
Member

roosta commented May 22, 2019

turns out I got this snippet in my tmux conf

set -ga terminal-overrides ",xterm-termite:Tc"
set -g default-terminal "tmux-256color"

no issue with the rainbow. Seems I just copy pasted this from the arch linux wiki, and promptly forgot about it. Should we add a note in the readme about this maybe?

@MindTooth
Copy link
Member

That code is a standard snippet I've seen a couple of places.. A notice could help more people to detect it.

@roosta
Copy link
Member

roosta commented May 23, 2019

fa4a618 Added, close this?

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

3 participants