diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-07-03 01:55:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-03 01:55:09 -0400 |
commit | c402f6e7a9135490a9f05e4cac733e41c6815b2d (patch) | |
tree | 9e90c402b768cbd2bf013447d84ebcba19b79c08 | |
parent | f80eb768c75de2065626203de001738e1dda436e (diff) | |
parent | 173d366a5b0b5f0784a1da8aef4fe5d0cab7e1ec (diff) | |
download | rneovim-c402f6e7a9135490a9f05e4cac733e41c6815b2d.tar.gz rneovim-c402f6e7a9135490a9f05e4cac733e41c6815b2d.tar.bz2 rneovim-c402f6e7a9135490a9f05e4cac733e41c6815b2d.zip |
Merge #5001 from justinmk/t_colors
TUI: infer 256 colors more liberally; listen to unibilium in other cases
-rw-r--r-- | src/nvim/globals.h | 2 | ||||
-rw-r--r-- | src/nvim/main.c | 3 | ||||
-rw-r--r-- | src/nvim/option.c | 1 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 11 | ||||
-rw-r--r-- | test/functional/options/defaults_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 60 |
6 files changed, 70 insertions, 13 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 42fde50bee..7f91903106 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -414,7 +414,7 @@ EXTERN int provider_call_nesting INIT(= 0); EXTERN char_u hash_removed; -EXTERN int t_colors INIT(= 0); /* int value of T_CCO */ +EXTERN int t_colors INIT(= 256); // int value of T_CCO /* * When highlight_match is TRUE, highlight a match, starting at the cursor diff --git a/src/nvim/main.c b/src/nvim/main.c index a876a0ad21..5cd1dbb467 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -276,7 +276,6 @@ int main(int argc, char **argv) printf(_("%d files to edit\n"), GARGCOUNT); full_screen = true; - t_colors = 256; check_tty(¶ms); /* @@ -1671,8 +1670,6 @@ static bool do_user_initialization(void) } /// Source startup scripts -/// -/// @param[in] static void source_startup_scripts(const mparm_T *const parmp) FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/option.c b/src/nvim/option.c index 020a119fd3..a844c4ed80 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4404,6 +4404,7 @@ bool get_tty_option(char *name, char **value) if (is_tty_option(name)) { if (value) { + // XXX: All other t_* options were removed in 3baba1e7. *value = xstrdup(""); } return true; diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 50558e644a..d220df508a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -135,6 +135,8 @@ static void terminfo_start(UI *ui) data->ut = unibi_dummy(); } fix_terminfo(data); + // Set 't_Co' from the result of unibilium & fix_terminfo. + t_colors = unibi_get_num(data->ut, unibi_max_colors); // Enter alternate screen and clear unibi_out(ui, unibi_enter_ca_mode); unibi_out(ui, unibi_clear_screen); @@ -786,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; } @@ -831,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); diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index ed978cd17e..a36939b0bd 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq +local eval, eq = helpers.eval, helpers.eq local execute = helpers.execute local function init_session(...) @@ -15,10 +15,6 @@ local function init_session(...) end describe('startup defaults', function() - before_each(function() - clear() - end) - describe(':filetype', function() local function expect_filetype(expected) local screen = Screen.new(48, 4) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 91789d6575..4bae9a8d02 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -301,3 +301,63 @@ describe('tui focus event handling', function() ]]) end) end) + +-- These tests require `thelpers` because --headless/--embed +-- does not initialize the TUI. +describe("tui 't_Co' (terminal colors)", function() + local screen + + local function assert_term_colors(term, colorterm, maxcolors) + helpers.clear({env={TERM=term}, args={}}) + -- This is ugly because :term/termopen() forces TERM=xterm-256color. + -- TODO: Revisit this after jobstart/termopen accept `env` dict. + screen = thelpers.screen_setup(0, string.format( + [=[['sh', '-c', 'TERM=%s %s %s -u NONE -i NONE --cmd "silent set noswapfile"']]=], + term, + (colorterm ~= nil and "COLORTERM="..colorterm or ""), + helpers.nvim_prog)) + + thelpers.feed_data(":echo &t_Co\n") + screen:expect(string.format([[ + {1: } | + ~ | + ~ | + ~ | + [No Name] | + %-3s | + -- TERMINAL -- | + ]], tostring(maxcolors and maxcolors or ""))) + end + + it("unknown TERM sets empty 't_Co'", function() + assert_term_colors("yet-another-term", nil, nil) + end) + + it("unknown TERM with COLORTERM=screen-256color uses 256 colors", function() + assert_term_colors("yet-another-term", "screen-256color", 256) + end) + + it("TERM=linux uses 8 colors", function() + assert_term_colors("linux", nil, 8) + end) + + it("TERM=screen uses 8 colors", function() + assert_term_colors("screen", nil, 8) + end) + + it("TERM=screen COLORTERM=screen-256color uses 256 colors", function() + assert_term_colors("screen", "screen-256color", 256) + end) + + it("TERM=yet-another-term COLORTERM=screen-256color uses 256 colors", function() + assert_term_colors("screen", "screen-256color", 256) + end) + + it("TERM=xterm uses 256 colors", function() + assert_term_colors("xterm", nil, 256) + end) + + it("TERM=xterm-256color uses 256 colors", function() + assert_term_colors("xterm-256color", nil, 256) + end) +end) |