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

Guard setting g:terminal_ansi_colors for <=256 colors terminal emulators #66

Closed
craigmac opened this issue Jan 19, 2022 · 3 comments
Closed

Comments

@craigmac
Copy link

I'm using the latest MacVim which also provides a /Applications/MacVim.app/Contents/bin/vim TUI version. The issue is that on Terminal.app using that TUI when we open a :term the colors are off because even though :version reports '+termguicolors' Terminal.app cannot do that. My suggestion would be to guard setting the ansi colors somehow. I have Terminal.app using the Apprentice palette as well, that's how I noticed the difference when opening a terminal buffer (blue becomes purple-y)
For now, I've just commented out the defined terminal ansi colors in apprentice.vim and let my terminal palette (set to Apprentice) handle it. I'm not sure how you'd fix it, I first thought about adding:

if has('termguicolors')
...
endif

But in my example above it would still pass. Maybe you'd have to do something like:

if has('termguicolors') && !$TERM_PROGRAM =~# 'Apple_Terminal'
...
endif

But then you might end up having to add a bunch of exceptions like this.

@romainl
Copy link
Owner

romainl commented Jan 19, 2022

It looks like we use the same binary in the same terminal emulator. That is quite convenient ;-).

Capture d’écran 2022-01-19 à 20 54 22

In the screenshot above, both Terminal.app windows are started with a custom profile intended to match default 256c xterm.

On the right window is the output of one of those shell scripts that you can find online. The jarring colors are, as expected, those defined at the terminal emulator level.

On the left, you have Vim with Apprentice and the same shell script executed in :term. The colors are, as far as I can tell, those defined in g:terminal_ansi_colors.

This is really surprising to me because:

  • Terminal.app is not supposed to support true colors,

  • I don't have termguicolors set,

  • it goes against the doc:

    In GUI mode or with 'termguicolors', the 16 ANSI colors used by default in new
    terminal windows may be configured using the variable
    g:terminal_ansi_colors, which should be a list of 16 color names or
    hexadecimal color codes, similar to those accepted by |highlight-guifg|. When
    not using GUI colors, the terminal window always uses the 16 ANSI colors of
    the underlying terminal.

Since I am not in "GUI mode" and termguicolors is not set, I would expect g:terminal_ansi_colors to be flat out ignored. Furthermore, with g:terminal_ansi_colors defined as a list of hexadecimal values and my terminal emulator not supporting true colors, how in all hell is Vim managing to display those hexadecimal values? Is it because they happen to all match with the xterm palette?

After experiencing with:

:let g:terminal_ansi_colors = [ '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF', '#11AAFF' ]

I get this output:

Capture d’écran 2022-01-19 à 21 17 55

where #11AAFF appears to be averaged to #00AFFF, which would be the hexadecimal notation of the closest color in the xterm palette. So it looks like the doc is not quite up-to-date with what is really going on : g:terminal_ansi_colors IS honored outside of the described conditions.

Weird.

I guess something like this would work:

has('termguicolors') && &termguicolors == 1

@romainl
Copy link
Owner

romainl commented Jan 20, 2022

@craigmac I just pushed a fix to master, could you try it?

@craigmac
Copy link
Author

Works as intended, thank you for putting so much time into looking at this, much appreciated!

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

2 participants