tui: Assume 256 colors in most cases.

Assume 256 colors if:
  - $TERM contains "xterm" or "256"
  - $COLORTERM contains "256"

Closes #2912
This commit is contained in:
Justin M. Keyes 2016-07-03 01:17:26 -04:00
parent fab62141c8
commit c002310787

View File

@ -788,6 +788,7 @@ static void fix_terminfo(TUIData *data)
unibi_term *ut = data->ut;
const char *term = os_getenv("TERM");
const char *colorterm = os_getenv("COLORTERM");
if (!term) {
goto end;
}
@ -833,10 +834,10 @@ static void fix_terminfo(TUIData *data)
#define XTERM_SETAB \
"\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m"
if (os_getenv("COLORTERM") != NULL
&& (!strcmp(term, "xterm") || !strcmp(term, "screen"))) {
// probably every modern terminal that sets TERM=xterm supports 256
// colors(eg: gnome-terminal). Also do it when TERM=screen.
if ((colorterm && strstr(colorterm, "256"))
|| strstr(term, "256")
|| strstr(term, "xterm")) {
// Assume TERM~=xterm or COLORTERM~=256 supports 256 colors.
unibi_set_num(ut, unibi_max_colors, 256);
unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF);
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB);