neovim icon indicating copy to clipboard operation
neovim copied to clipboard

Uses `set_a_foreground` and `set_a_background` for invalid colour indexes

Open leonerd opened this issue 9 years ago • 4 comments

I'm trying to debug a problem a user has relating to terminal rendering, and I'm looking over a script log of neovim's output. One thing that initially troubles me is there are places in the log where it sends

SGR 310
SGR 312
SGR 314

These aren't known to libvterm, nor can I find reference to them in any terminal docs I have to hand.

Looking more closely at the places they appear, it seems they're intended as colour formatting; e.g.

{ESC (B}{SGR *}{SGR 36}{SGR 48}0
{ESC (B}{SGR *}{SGR 312}{SGR 48}]

A careful reading of the set_a_foreground terminfo entry reveals a likely candidate:

set_a_foreground=\E[3%p1%dm

The parameter gets printed verbatim, as if in a call to

printf("\e[3%dm", param);

at which point we can surmise that these are coming from set_a_foreground called with a parameter value of 10, 12 or 14.

This is outside the range that should be allowed, because the terminfo starts by declaring

max_colors#8

It is important that set_a_foreground and set_a_background are not invoked with a number outside the range allowed by max_colors, or weird things may result.

leonerd avatar Oct 15 '15 13:10 leonerd

I think the errant code is the part around here: https://github.com/neovim/neovim/blob/master/src/nvim/tui/tui.c#L287

leonerd avatar Oct 15 '15 13:10 leonerd

Thanks.

I thought it was responsibility of terminfo to deal with color numbers outside the range. In my xterm-256color terminfo set_a_foreground is defined as \E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m which I assumed was a formula to fix the color number based on the supported colors.

tarruda avatar Oct 15 '15 13:10 tarruda

Ah, your terminfo probably claims max_colors#256 in that case. Yours is indeed splitting the range into 0-7 => SGR 30-37, 8-15 => SGR 90-97, 16-255 => SGR 35;8;16-255

leonerd avatar Oct 15 '15 13:10 leonerd

See #6673 for where nvim fixes up known wrong terminfo entries to have more complete colour setting capabilities.

jdebp avatar May 04 '17 20:05 jdebp