From c00231078790e7f700b820a96f69387c42518a10 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 3 Jul 2016 01:17:26 -0400 Subject: [PATCH] tui: Assume 256 colors in most cases. Assume 256 colors if: - $TERM contains "xterm" or "256" - $COLORTERM contains "256" Closes #2912 --- src/nvim/tui/tui.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index ea10130056..d220df508a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -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);