[vim/vim] terminal background color detection algorithm (Discussion #13933)

58 views
Skip to first unread message

Maxim Kim

unread,
Jan 30, 2024, 2:15:25 AM1/30/24
to vim/vim, Subscribed

Hi, does anyone remembers or knows about the algorithm being used to detect dark/light background of terminal?

https://github.com/vim/vim/blob/fef66301665027f1801a18d796f74584666f41ef/src/term.c#L6287-L6295

https://github.com/vim/vim/blob/fef66301665027f1801a18d796f74584666f41ef/src/term.c#L5776-L5776

It looks like nowadays it "almost always" incorrectly detects light background for terminals with black background color.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933@github.com>

Maxim Kim

unread,
Feb 4, 2024, 6:27:15 PM2/4/24
to vim/vim, Subscribed

https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8363791@github.com>

Maxim Kim

unread,
Feb 4, 2024, 7:49:29 PM2/4/24
to vim/vim, Subscribed

On windows terminal using WSL debian handle_osc is never called.

There is however term_bg_default function, I wonder if it is feasible to invert condition to default to dark background, assuming most of the terminals are dark?

https://github.com/vim/vim/blob/de7f5bde6c598d4da4ce5b30328eb458962ba60a/src/term.c#L3212-L3245


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8364095@github.com>

Maxim Kim

unread,
Feb 4, 2024, 8:17:46 PM2/4/24
to vim/vim, Subscribed

I have inverted it, and this might be a BREAKING change: #13977


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8364215@github.com>

Luca Saccarola

unread,
Feb 12, 2024, 12:06:10 PM2/12/24
to vim/vim, Subscribed

I was quite interested in this myself. I found this commit from neovim. There is an escape sequence that lets you support this. Should be called OSC. Also you might be interested in this issue that tracked some issues related to the feature.


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8444375@github.com>

Maxim Kim

unread,
Feb 12, 2024, 5:36:14 PM2/12/24
to vim/vim, Subscribed

Should be called OSC

Vim has it. The thing is, vim defaults to 'light' background and checks for the terminal OSC response which might fail/be incorrect.

To add to it, more than 1000 screendump tests are relying on background=light, and a lot of people got used to it.


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8447493@github.com>

Luca Saccarola

unread,
Feb 13, 2024, 1:29:03 AM2/13/24
to vim/vim, Subscribed

and a lot of people got used to it.

Who exactly? I see one person complaining in the PR but thats it.


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8449840@github.com>

Maxim Kim

unread,
Feb 13, 2024, 4:26:09 AM2/13/24
to vim/vim, Subscribed

There were on libera #vim


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8451362@github.com>

Maxim Kim

unread,
Feb 13, 2024, 4:54:27 AM2/13/24
to vim/vim, Subscribed

But PR is there for anyone to continue the journey.


Reply to this email directly, view it on GitHub,.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/13933/comments/8451660@github.com>

Reply all
Reply to author
Forward
0 new messages