mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Add mode 2031 support to automatically report dark or light theme. tmux
will guess the theme from the background colour on terminals which do not themselves support the escape sequence. Written by Jonathan Slenders, GitHub issue 4353.
This commit is contained in:
40
colour.c
40
colour.c
@ -182,6 +182,46 @@ colour_tostring(int c)
|
||||
return ("invalid");
|
||||
}
|
||||
|
||||
/* Convert background colour to theme. */
|
||||
enum client_theme
|
||||
colour_totheme(int c)
|
||||
{
|
||||
int r, g, b, brightness;
|
||||
|
||||
if (c == -1)
|
||||
return (THEME_UNKNOWN);
|
||||
|
||||
if (c & COLOUR_FLAG_RGB) {
|
||||
r = (c >> 16) & 0xff;
|
||||
g = (c >> 8) & 0xff;
|
||||
b = (c >> 0) & 0xff;
|
||||
|
||||
brightness = r + g + b;
|
||||
if (brightness > 382)
|
||||
return (THEME_LIGHT);
|
||||
return (THEME_DARK);
|
||||
}
|
||||
|
||||
if (c & COLOUR_FLAG_256)
|
||||
return (colour_totheme(colour_256toRGB(c)));
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
case 90:
|
||||
return (THEME_DARK);
|
||||
case 7:
|
||||
case 97:
|
||||
return (THEME_LIGHT);
|
||||
default:
|
||||
if (c >= 0 && c <= 7)
|
||||
return (colour_totheme(colour_256toRGB(c)));
|
||||
if (c >= 90 && c <= 97)
|
||||
return (colour_totheme(colour_256toRGB(8 + c - 90)));
|
||||
break;
|
||||
}
|
||||
return (THEME_UNKNOWN);
|
||||
}
|
||||
|
||||
/* Convert colour from string. */
|
||||
int
|
||||
colour_fromstring(const char *s)
|
||||
|
Reference in New Issue
Block a user