mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 21:25:04 -07:00
UI: always use contrete colors for default_colors_set
But add an escape hatch needed for external TUI, so it still can use terminal emulator defaults.
This commit is contained in:
parent
36378c33c6
commit
baf93d9606
@ -35,6 +35,7 @@ a dictionary with these (optional) keys:
|
|||||||
`ext_linegrid` Use new revision of the grid events. |ui-linegrid|
|
`ext_linegrid` Use new revision of the grid events. |ui-linegrid|
|
||||||
`ext_multigrid` Use per-window grid based events. |ui-multigrid|
|
`ext_multigrid` Use per-window grid based events. |ui-multigrid|
|
||||||
`ext_hlstate` Use detailed highlight state. |ui-hlstate|
|
`ext_hlstate` Use detailed highlight state. |ui-hlstate|
|
||||||
|
`ext_termcolors` Use external default colors.
|
||||||
|
|
||||||
Specifying a non-existent option is an error. UIs can check the |api-metadata|
|
Specifying a non-existent option is an error. UIs can check the |api-metadata|
|
||||||
`ui_options` key for supported options. Additionally Nvim (currently) requires
|
`ui_options` key for supported options. Additionally Nvim (currently) requires
|
||||||
@ -239,6 +240,13 @@ numerical highlight `id`:s to the actual attributes.
|
|||||||
special colors respectively. `cterm_fg` and `cterm_bg` specifies the
|
special colors respectively. `cterm_fg` and `cterm_bg` specifies the
|
||||||
default color codes to use in a 256-color terminal.
|
default color codes to use in a 256-color terminal.
|
||||||
|
|
||||||
|
The rgb values will always be valid colors, by default. If no
|
||||||
|
colors have been set, they will default to black and white, depending
|
||||||
|
on 'background'. By setting the `ext_termcolors` option, instead
|
||||||
|
-1 will be used for unset colors. This is mostly useful for a
|
||||||
|
TUI implementation, where using the terminal emulators builitn
|
||||||
|
defaults are expected.
|
||||||
|
|
||||||
Note: unlike the corresponding events in the first revision, the
|
Note: unlike the corresponding events in the first revision, the
|
||||||
screen is not always cleared after sending this event. The GUI has to
|
screen is not always cleared after sending this event. The GUI has to
|
||||||
repaint the screen with changed background color itself.
|
repaint the screen with changed background color itself.
|
||||||
|
@ -210,8 +210,9 @@ static void ui_set_option(UI *ui, bool init, String name, Object value,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->rgb = value.data.boolean;
|
ui->rgb = value.data.boolean;
|
||||||
// A little drastic, but only legacy uis need to use this option
|
// A little drastic, but only takes effect for legacy uis. For linegrid UI
|
||||||
if (!init) {
|
// only changes metadata for nvim_list_uis(), no refresh needed.
|
||||||
|
if (!init && !ui->ui_ext[kUILinegrid]) {
|
||||||
ui_refresh();
|
ui_refresh();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -355,6 +356,12 @@ static void remote_ui_default_colors_set(UI *ui, Integer rgb_fg,
|
|||||||
Integer rgb_bg, Integer rgb_sp,
|
Integer rgb_bg, Integer rgb_sp,
|
||||||
Integer cterm_fg, Integer cterm_bg)
|
Integer cterm_fg, Integer cterm_bg)
|
||||||
{
|
{
|
||||||
|
if (!ui->ui_ext[kUITermColors]) {
|
||||||
|
bool dark = (*p_bg == 'd');
|
||||||
|
rgb_fg = rgb_fg != -1 ? rgb_fg : (dark ? 0xFFFFFF : 0x000000);
|
||||||
|
rgb_bg = rgb_bg != -1 ? rgb_bg : (dark ? 0x000000 : 0xFFFFFF);
|
||||||
|
rgb_sp = rgb_sp != -1 ? rgb_sp : 0xFF0000;
|
||||||
|
}
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
ADD(args, INTEGER_OBJ(rgb_fg));
|
ADD(args, INTEGER_OBJ(rgb_fg));
|
||||||
ADD(args, INTEGER_OBJ(rgb_bg));
|
ADD(args, INTEGER_OBJ(rgb_bg));
|
||||||
|
@ -310,6 +310,9 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active)
|
|||||||
ui->option_set(ui, cstr_as_string((char *)ui_ext_names[ext]),
|
ui->option_set(ui, cstr_as_string((char *)ui_ext_names[ext]),
|
||||||
BOOLEAN_OBJ(active));
|
BOOLEAN_OBJ(active));
|
||||||
}
|
}
|
||||||
|
if (ext == kUITermColors) {
|
||||||
|
ui_default_colors_set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
|
void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
|
||||||
|
@ -18,6 +18,7 @@ typedef enum {
|
|||||||
kUILinegrid,
|
kUILinegrid,
|
||||||
kUIMultigrid,
|
kUIMultigrid,
|
||||||
kUIHlState,
|
kUIHlState,
|
||||||
|
kUITermColors,
|
||||||
kUIExtCount,
|
kUIExtCount,
|
||||||
} UIExtension;
|
} UIExtension;
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ EXTERN const char *ui_ext_names[] INIT(= {
|
|||||||
"ext_linegrid",
|
"ext_linegrid",
|
||||||
"ext_multigrid",
|
"ext_multigrid",
|
||||||
"ext_hlstate",
|
"ext_hlstate",
|
||||||
|
"ext_termcolors",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1278,6 +1278,7 @@ describe('API', function()
|
|||||||
ext_linegrid = screen._options.ext_linegrid or false,
|
ext_linegrid = screen._options.ext_linegrid or false,
|
||||||
ext_multigrid = false,
|
ext_multigrid = false,
|
||||||
ext_hlstate=false,
|
ext_hlstate=false,
|
||||||
|
ext_termcolors=false,
|
||||||
height = 4,
|
height = 4,
|
||||||
rgb = true,
|
rgb = true,
|
||||||
width = 20,
|
width = 20,
|
||||||
|
@ -256,13 +256,13 @@ describe('TUI', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('shows up in nvim_list_uis', function()
|
it('shows up in nvim_list_uis', function()
|
||||||
feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(v))})\013')
|
feed_data(':echo map(nvim_list_uis(), {k,v -> sort(items(filter(v, {k,v -> k[:3] !=# "ext_" })))})\013')
|
||||||
screen:expect([=[
|
screen:expect([=[
|
||||||
[[['ext_cmdline', v:false], ['ext_hlstate', v:fals|
|
|
|
||||||
e], ['ext_linegrid', v:true], ['ext_multigrid', v:|
|
{4:~ }|
|
||||||
false], ['ext_popupmenu', v:false], ['ext_tabline'|
|
{5: }|
|
||||||
, v:false], ['ext_wildmenu', v:false], ['height', |
|
[[['height', 6], ['rgb', v:false], ['width', 50]]]|
|
||||||
6], ['rgb', v:false], ['width', 50]]] |
|
|
|
||||||
{10:Press ENTER or type command to continue}{1: } |
|
{10:Press ENTER or type command to continue}{1: } |
|
||||||
{3:-- TERMINAL --} |
|
{3:-- TERMINAL --} |
|
||||||
]=])
|
]=])
|
||||||
|
@ -27,6 +27,7 @@ describe('ui receives option updates', function()
|
|||||||
ext_linegrid=false,
|
ext_linegrid=false,
|
||||||
ext_hlstate=false,
|
ext_hlstate=false,
|
||||||
ext_multigrid=false,
|
ext_multigrid=false,
|
||||||
|
ext_termcolors=false,
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(...)
|
clear(...)
|
||||||
|
@ -960,3 +960,46 @@ end)
|
|||||||
describe("Screen (line-based)", function()
|
describe("Screen (line-based)", function()
|
||||||
screen_tests(true)
|
screen_tests(true)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('Screen default colors', function()
|
||||||
|
local screen
|
||||||
|
local function startup(light, termcolors)
|
||||||
|
local extra = (light and ' background=light') or ''
|
||||||
|
|
||||||
|
local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
|
||||||
|
'--cmd', 'set shortmess+=I noswapfile belloff= noshowcmd noruler'..extra,
|
||||||
|
'--embed'}
|
||||||
|
local screen_nvim = spawn(nvim_argv)
|
||||||
|
set_session(screen_nvim)
|
||||||
|
screen = Screen.new()
|
||||||
|
screen:attach(termcolors and {rgb=true,ext_termcolors=true} or {rgb=true})
|
||||||
|
end
|
||||||
|
|
||||||
|
it('are dark per default', function()
|
||||||
|
startup(false, false)
|
||||||
|
screen:expect{condition=function()
|
||||||
|
eq({rgb_bg=0, rgb_fg=Screen.colors.White, rgb_sp=Screen.colors.Red,
|
||||||
|
cterm_bg=0, cterm_fg=0}, screen.default_colors)
|
||||||
|
end}
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can be set to light', function()
|
||||||
|
startup(true, false)
|
||||||
|
screen:expect{condition=function()
|
||||||
|
eq({rgb_bg=Screen.colors.White, rgb_fg=0, rgb_sp=Screen.colors.Red,
|
||||||
|
cterm_bg=0, cterm_fg=0}, screen.default_colors)
|
||||||
|
end}
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can be handled by external terminal', function()
|
||||||
|
startup(false, true)
|
||||||
|
screen:expect{condition=function()
|
||||||
|
eq({rgb_bg=-1, rgb_fg=-1, rgb_sp=-1, cterm_bg=0, cterm_fg=0}, screen.default_colors)
|
||||||
|
end}
|
||||||
|
|
||||||
|
startup(true, true)
|
||||||
|
screen:expect{condition=function()
|
||||||
|
eq({rgb_bg=-1, rgb_fg=-1, rgb_sp=-1, cterm_bg=0, cterm_fg=0}, screen.default_colors)
|
||||||
|
end}
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user