[vim/vim] terminal: Better approximation for 256 colors (#1895)

174 views
Skip to first unread message

K.Takata

unread,
Jul 30, 2017, 2:57:51 AM7/30/17
to vim/vim, Subscribed

After the patch 8.0.0791, yellow color in a :terminal changed to brown on unix-like systems. (t_Co is set to 256.)

I wrote some scripts to test ANSI color sequences: https://gist.github.com/k-takata/2d4f562bacf8bae6691973a540970117
When I run color16.sh and color24.sh in the gist, I get the following results:
color-cygwin-vim

After applying this PR, the result becomes:
color-cygwin-vim-patched


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/1895

Commit Summary

  • Better approximation for 256 colors

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Kazunobu Kuriyama

unread,
Jul 30, 2017, 5:58:25 AM7/30/17
to vim/vim, Subscribed

Since 72 = 3 x 16 + 2 x 4 + 0 x 1 + 16 and 130 = 3 x 36 + 1 + 6 + 0 x 1 + 16, it follows from the formulae given in COLORS AND GRAPHICS of urxvt(1), Index 72 for 88-color terminals and Index 130 for 256-color terminals correspond to #bf8000 and #802b00, respectively, in terms of Vim's guifg/guibg specifications.

On the other hand, according to /usr/X11R6/share/X11/app-defaults/XTerm-color, the default color for the resource color3 (the 3rd ANSI color) is yellow3, which /usr/X11R6/share/X11/rgb.txt specifies as 205 205 0, i.e., #cdcd00.

Using the formulae mentioned above, simple computation tells us that the best approximation of #cdcd00 is Index 76 for 88-color terminals and Index 226 for 256-color terminals.

Those indices happen to be the same as the color of Index 3 (Usually, #ffff00. Often user configurable, though) due to computation rounding.

So, if colors are chosen depending on what we have on truecolor terminal, it is likely that yellow and its bright or dark variant will be made indistinguishable on 88-color and/or 256 terminals. I'm wondering if the proposed changes take that into account.

Bram Moolenaar

unread,
Jul 30, 2017, 2:42:11 PM7/30/17
to vim/vim, Subscribed

Looking at the colors256.sh output in a shell and a terminal window, using a 256 color xterm, looks good before the change and wrong after the change.
I guess we should do something different only when the terminal supports more than 256 colors, or when 'termguicolors' is set.

K.Takata

unread,
Jul 30, 2017, 11:35:54 PM7/30/17
to vim/vim, Subscribed

looks good before the change and wrong after the change.

Hmm. I have added new scripts to the gist.
Looks wrong both before and after the change on mintty using color256_block.sh.

Outside vim:
color-mintty

Inside vim without the change:
color-vim

At least, indices 3, 7 and 8 look wrong. Especially, index 3 looks very different without the change.

Kazunobu Kuriyama

unread,
Jul 31, 2017, 5:25:36 AM7/31/17
to vim/vim, Subscribed

Especially, index 3 looks very different without the change.

Now I seemt to get your point. That wasn't actually an issue on color approximation...

There's a good reason for the difference.

For text editors, what matters is not having a nice color pattern looking good to someone, but providing a good set of 16 different colors for everyone to easily tell one from the others at sight.

For giving an explanation in detail, imagine you are working with a terminal of a single yollowish color foregound with a monotonic dark background, and the foreground color is known to be either Index 3 color (= yellow, or dark yellow) or Index 11 color (= light yellow, or yellow, respectively), but you aren't told which is used on the terminal. Now guess which color is used.

If you can always distinguish Putty's Index 3 color from its Index 11 color at first glance, that's great. But I do think most people have to think more than once for sure to identify the color with its index number (i.e., its darkness or brightness). Even if one has better eyes than ordinary people, he can be mistaken due to the display brightness and/or the ambient light.

Yellow is a color of such characteristics, as shown well in the color strip one before the last one in the screen shots you gave. If those yellows are presentend in a line like that, people can easily tell which is brighter or darker than the others by comparison. But if one of them is singled out for guess, it surely gets hard for people to tell the difference.

In contrast, I'm pretty sure most people can distinguish Vim's Index 3 color from its Index 11 color quite easily at sight, and that's all about colors for text editors.

Conveying ideas through colors without asking users to gaze at colored objects is an important design goal of syntax highlighting and color schemes.

Accordingly, a set of colors should be chosen to fulfill that goal primarily; giving a good look in a color pattern should be of secondary importance.

That's why I'm thinking Vim's color set is better than that of Putty with respect to not only Index 3 color but also Indice 7 and 8 colors, and that hence no change is needed unless a better color set is proposed.

K.Takata

unread,
Sep 7, 2017, 11:17:20 PM9/7/17
to vim/vim, Subscribed

It seems that there's no general way to fix this.
Mapping between color indexes to RGB values seems to depend on each terminal emulator.
Closing for now.

K.Takata

unread,
Sep 7, 2017, 11:17:31 PM9/7/17
to vim/vim, Subscribed

Closed #1895.

Reply all
Reply to author
Forward
0 new messages