mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5001 from justinmk/t_colors
TUI: infer 256 colors more liberally; listen to unibilium in other cases
This commit is contained in:
commit
c402f6e7a9
@ -414,7 +414,7 @@ EXTERN int provider_call_nesting INIT(= 0);
|
|||||||
EXTERN char_u hash_removed;
|
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
|
* When highlight_match is TRUE, highlight a match, starting at the cursor
|
||||||
|
@ -276,7 +276,6 @@ int main(int argc, char **argv)
|
|||||||
printf(_("%d files to edit\n"), GARGCOUNT);
|
printf(_("%d files to edit\n"), GARGCOUNT);
|
||||||
|
|
||||||
full_screen = true;
|
full_screen = true;
|
||||||
t_colors = 256;
|
|
||||||
check_tty(¶ms);
|
check_tty(¶ms);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1671,8 +1670,6 @@ static bool do_user_initialization(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Source startup scripts
|
/// Source startup scripts
|
||||||
///
|
|
||||||
/// @param[in]
|
|
||||||
static void source_startup_scripts(const mparm_T *const parmp)
|
static void source_startup_scripts(const mparm_T *const parmp)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
@ -4404,6 +4404,7 @@ bool get_tty_option(char *name, char **value)
|
|||||||
|
|
||||||
if (is_tty_option(name)) {
|
if (is_tty_option(name)) {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
// XXX: All other t_* options were removed in 3baba1e7.
|
||||||
*value = xstrdup("");
|
*value = xstrdup("");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -135,6 +135,8 @@ static void terminfo_start(UI *ui)
|
|||||||
data->ut = unibi_dummy();
|
data->ut = unibi_dummy();
|
||||||
}
|
}
|
||||||
fix_terminfo(data);
|
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
|
// Enter alternate screen and clear
|
||||||
unibi_out(ui, unibi_enter_ca_mode);
|
unibi_out(ui, unibi_enter_ca_mode);
|
||||||
unibi_out(ui, unibi_clear_screen);
|
unibi_out(ui, unibi_clear_screen);
|
||||||
@ -786,6 +788,7 @@ static void fix_terminfo(TUIData *data)
|
|||||||
unibi_term *ut = data->ut;
|
unibi_term *ut = data->ut;
|
||||||
|
|
||||||
const char *term = os_getenv("TERM");
|
const char *term = os_getenv("TERM");
|
||||||
|
const char *colorterm = os_getenv("COLORTERM");
|
||||||
if (!term) {
|
if (!term) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -831,10 +834,10 @@ static void fix_terminfo(TUIData *data)
|
|||||||
#define XTERM_SETAB \
|
#define XTERM_SETAB \
|
||||||
"\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m"
|
"\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m"
|
||||||
|
|
||||||
if (os_getenv("COLORTERM") != NULL
|
if ((colorterm && strstr(colorterm, "256"))
|
||||||
&& (!strcmp(term, "xterm") || !strcmp(term, "screen"))) {
|
|| strstr(term, "256")
|
||||||
// probably every modern terminal that sets TERM=xterm supports 256
|
|| strstr(term, "xterm")) {
|
||||||
// colors(eg: gnome-terminal). Also do it when TERM=screen.
|
// Assume TERM~=xterm or COLORTERM~=256 supports 256 colors.
|
||||||
unibi_set_num(ut, unibi_max_colors, 256);
|
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_foreground, XTERM_SETAF);
|
||||||
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB);
|
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local Screen = require('test.functional.ui.screen')
|
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 execute = helpers.execute
|
||||||
|
|
||||||
local function init_session(...)
|
local function init_session(...)
|
||||||
@ -15,10 +15,6 @@ local function init_session(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe('startup defaults', function()
|
describe('startup defaults', function()
|
||||||
before_each(function()
|
|
||||||
clear()
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe(':filetype', function()
|
describe(':filetype', function()
|
||||||
local function expect_filetype(expected)
|
local function expect_filetype(expected)
|
||||||
local screen = Screen.new(48, 4)
|
local screen = Screen.new(48, 4)
|
||||||
|
@ -301,3 +301,63 @@ describe('tui focus event handling', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user