Skip to content

Commit

Permalink
vim-patch:9.1.0106: Visual highlight hard to read with 'termguicolors'
Browse files Browse the repository at this point in the history
Problem:  Visual highlight hard to read with 'termguicolors'
          (Maxim Kim)
Solution: Set Visual GUI foreground to black (with background=light)
          and lightgrey (with background=dark)
          (Maxim Kim)

fixes: vim/vim#14024
closes: vim/vim#14025

vim/vim@34e4a05

Co-authored-by: Maxim Kim <habamax@gmail.com>
  • Loading branch information
zeertzjq and habamax committed Feb 15, 2024
1 parent 440ce0d commit 31b3c62
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 91 deletions.
4 changes: 2 additions & 2 deletions runtime/colors/vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ if vim.o.background == 'light' then
hi('SpellRare', { sp = 'Magenta', undercurl = true, ctermbg = 'LightMagenta' })
hi('TabLine', { bg = 'LightGrey', underline = true, ctermfg = 'Black', ctermbg = 'LightGrey', cterm = { underline = true } })
hi('Title', { fg = 'Magenta', bold = true, ctermfg = 'DarkMagenta' })
hi('Visual', { bg = 'LightGrey', ctermfg = 'Black', ctermbg = 'Grey' })
hi('Visual', { fg = 'Black', bg = 'LightGrey', ctermfg = 'Black', ctermbg = 'Grey' })
hi('WarningMsg', { fg = 'Red', ctermfg = 'DarkRed' })
hi('Comment', { fg = 'Blue', ctermfg = 'DarkBlue' })
hi('Constant', { fg = 'Magenta', ctermfg = 'DarkRed' })
Expand Down Expand Up @@ -270,7 +270,7 @@ else
hi('SpellRare', { sp = 'Magenta', undercurl = true, ctermbg = 'Magenta' })
hi('TabLine', { bg = 'DarkGrey', underline = true, ctermfg = 'White', ctermbg = 'DarkGrey', cterm = { underline = true } })
hi('Title', { fg = 'Magenta', bold = true, ctermfg = 'LightMagenta' })
hi('Visual', { bg = '#575757', ctermfg = 'Black', ctermbg = 'Grey' })
hi('Visual', { fg = 'LightGrey', bg = '#575757', ctermfg = 'Black', ctermbg = 'Grey' })
hi('WarningMsg', { fg = 'Red', ctermfg = 'LightRed' })
hi('Comment', { fg = '#80a0ff', ctermfg = 'Cyan' })
hi('Constant', { fg = '#ffa0a0', ctermfg = 'Magenta' })
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ex_cmds/cmd_map_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('mappings with <Cmd>', function()
[2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
[3] = { bold = true, foreground = Screen.colors.SeaGreen4 },
[4] = { bold = true },
[5] = { background = Screen.colors.LightGrey },
[5] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
[6] = { foreground = Screen.colors.Blue1 },
[7] = { bold = true, reverse = true },
[8] = { background = Screen.colors.WebGray },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/breakindent_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('breakindent', function()
]])
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { bold = true, reverse = true }, -- StatusLine
[3] = { reverse = true }, -- StatusLineNC
[4] = { bold = true }, -- ModeMsg
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/display_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('display', function()
screen:attach()
screen:set_default_attr_ids({
[1] = { bold = true }, -- ModeMsg
[2] = { background = Screen.colors.LightGrey }, -- Visual
[2] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[3] = { background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue }, -- SignColumn
})

Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/highlight_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Visual selection highlight', function()
local screen = Screen.new(60, 6)
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { bold = true }, -- ModeMsg
})
screen:attach()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/listlbr_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('listlbr', function()
local screen = Screen.new(60, 6)
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { background = Screen.colors.Red, foreground = Screen.colors.White }, -- ErrorMsg
})
screen:attach()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/listlbr_utf8_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('linebreak', function()
local screen = Screen.new(60, 8)
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { bold = true }, -- ModeMsg
})
screen:attach()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/matchparen_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('matchparen', function()
screen:attach()
screen:set_default_attr_ids({
[1] = { bold = true },
[2] = { background = Screen.colors.LightGrey },
[2] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black },
})

exec([[
Expand Down
4 changes: 2 additions & 2 deletions test/functional/legacy/search_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ describe('Search highlight', function()
screen:set_default_attr_ids({
[1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[2] = { bold = true }, -- ModeMsg, Search
[3] = { background = Screen.colors.LightGrey }, -- Visual
[3] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[4] = { background = Screen.colors.Yellow, bold = true }, -- Search
[5] = { background = Screen.colors.LightGrey, bold = true }, -- Visual + Search
[5] = { background = Screen.colors.LightGrey, bold = true, foreground = Screen.colors.Black },
})
screen:attach()
exec([[
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/statusline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('statusline', function()
it('showcmdloc=statusline works', function()
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { bold = true }, -- MoreMsg
[3] = { bold = true, reverse = true }, -- StatusLine
[5] = { background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue }, -- Folded
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/tabline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('tabline', function()
it('showcmdloc=tabline works', function()
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { background = Screen.colors.LightGrey }, -- Visual
[1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
[2] = { bold = true }, -- MoreMsg, TabLineSel
[3] = { reverse = true }, -- TabLineFill
[4] = { background = Screen.colors.LightGrey, underline = true }, -- TabLine
Expand Down
2 changes: 1 addition & 1 deletion test/functional/legacy/visual_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Visual highlight', function()
screen:set_default_attr_ids({
[0] = { foreground = Screen.colors.Blue, bold = true }, -- NonText
[1] = { bold = true }, -- ModeMsg
[2] = { background = Screen.colors.LightGrey }, -- Visual
[2] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, -- Visual
})
screen:attach()
end)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ui/bufhl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Buffer highlighting', function()
[10] = { foreground = Screen.colors.Red },
[11] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
[12] = { foreground = Screen.colors.Blue1 },
[13] = { background = Screen.colors.LightGrey },
[13] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
[14] = { background = Screen.colors.Gray90 },
[15] = { background = Screen.colors.Gray90, bold = true, foreground = Screen.colors.Brown },
[16] = { foreground = Screen.colors.Magenta, background = Screen.colors.Gray90 },
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ui/cmdline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local function new_screen(opt)
[5] = { bold = true, foreground = Screen.colors.SeaGreen4 },
[6] = { foreground = Screen.colors.Magenta },
[7] = { bold = true, foreground = Screen.colors.Brown },
[8] = { background = Screen.colors.LightGrey },
[8] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
[9] = { bold = true },
[10] = { background = Screen.colors.Yellow1 },
})
Expand Down
53 changes: 28 additions & 25 deletions test/functional/ui/decorations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,14 @@ describe('extmark decorations', function()
[23] = {foreground = Screen.colors.Magenta1, background = Screen.colors.LightGrey};
[24] = {bold = true};
[25] = {background = Screen.colors.LightRed};
[26] = {background=Screen.colors.DarkGrey, foreground=Screen.colors.LightGrey};
[27] = {background = Screen.colors.Plum1};
[26] = {background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey};
[27] = {background = Screen.colors.LightGrey, foreground = Screen.colors.Black};
[28] = {underline = true, foreground = Screen.colors.SlateBlue};
[29] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightGray, underline = true};
[30] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGray, underline = true};
[29] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightGrey, underline = true};
[30] = {foreground = Screen.colors.DarkCyan, background = Screen.colors.LightGrey, underline = true};
[31] = {underline = true, foreground = Screen.colors.DarkCyan};
[32] = {underline = true};
[33] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray};
[33] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey};
[34] = {background = Screen.colors.Yellow};
[35] = {background = Screen.colors.Yellow, bold = true, foreground = Screen.colors.Blue};
[36] = {foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.Red};
Expand All @@ -824,6 +824,7 @@ describe('extmark decorations', function()
[41] = {bold = true, reverse = true};
[42] = {undercurl = true, special = Screen.colors.Red};
[43] = {background = Screen.colors.Yellow, undercurl = true, special = Screen.colors.Red};
[44] = {background = Screen.colors.LightMagenta};
}

ns = api.nvim_create_namespace 'test'
Expand Down Expand Up @@ -1017,7 +1018,7 @@ describe('extmark decorations', function()
screen:expect{grid=[[
ababababababababababababababababababababab{4:01234567}|
{1:++}{4:89}abababababababababababababababababababa{4:0123456}|
{1:++}^a{18:babab}ababababababababababababababababababababab|
{1:++}^a{27:babab}ababababababababababababababababababababab|
{1:++}abababababababababababababababababababababababab|
{1:++}ababab |
{24:-- VISUAL --} |
Expand All @@ -1027,7 +1028,7 @@ describe('extmark decorations', function()
screen:expect{grid=[[
ababababababababababababababababababababab{4:01234567}|
{1:++}{4:89}abababababababababababababababababababa{4:0123456}|
{1:++}{18:ababa}^bababababababababababababababababababababab|
{1:++}{27:ababa}^bababababababababababababababababababababab|
{1:++}abababababababababababababababababababababababab|
{1:++}ababab |
{24:-- VISUAL --} |
Expand All @@ -1036,8 +1037,8 @@ describe('extmark decorations', function()
feed('gk')
screen:expect{grid=[[
ababababababababababababababababababababab{4:01234567}|
{1:++}{4:89}aba^b{18:ababababababababababababababababababababab}|
{1:++}{18:a}{4:89}babababababababababababababababababababababab|
{1:++}{4:89}aba^b{27:ababababababababababababababababababababab}|
{1:++}{27:a}{4:89}babababababababababababababababababababababab|
{1:++}abababababababababababababababababababababababab|
{1:++}ababab |
{24:-- VISUAL --} |
Expand All @@ -1046,7 +1047,7 @@ describe('extmark decorations', function()
feed('o')
screen:expect{grid=[[
ababababababababababababababababababababab{4:01234567}|
{1:++}{4:89}aba{18:bababababababababababababababababababababab}|
{1:++}{4:89}aba{27:bababababababababababababababababababababab}|
{1:++}^a{4:89}babababababababababababababababababababababab|
{1:++}abababababababababababababababababababababababab|
{1:++}ababab |
Expand Down Expand Up @@ -1185,6 +1186,7 @@ describe('extmark decorations', function()
]]}

command 'hi Blendy guibg=Red blend=30'
command 'hi! Visual guifg=NONE guibg=LightGrey'
api.nvim_buf_set_extmark(0, ns, 1, 5, { virt_text={{'blendy text - here', 'Blendy'}}, virt_text_pos='overlay', hl_mode='blend'})
api.nvim_buf_set_extmark(0, ns, 2, 5, { virt_text={{'combining color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='combine'})
api.nvim_buf_set_extmark(0, ns, 3, 5, { virt_text={{'replacing color', 'Blendy'}}, virt_text_pos='overlay', hl_mode='replace'})
Expand Down Expand Up @@ -1800,7 +1802,7 @@ describe('extmark decorations', function()
end

screen:expect{grid=[[
{27: } |
{44: } |
XXX |*2
^XXX HELLO |
XXX |*7
Expand Down Expand Up @@ -1901,7 +1903,8 @@ describe('extmark decorations', function()
feed('gg')
command('set ft=lua')
command('syntax on')
api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_mode = 'combine', hl_group = 'Visual' })
command('hi default MyMark guibg=LightGrey')
api.nvim_buf_set_extmark(0, ns, 0, 0, { end_col = 3, hl_mode = 'combine', hl_group = 'MyMark' })
command('hi default MyLine gui=underline')
command('sign define CurrentLine linehl=MyLine')
fn.sign_place(6, 'Test', 'CurrentLine', '', { lnum = 1 })
Expand Down Expand Up @@ -1964,18 +1967,19 @@ describe('extmark decorations', function()
it('highlight applies to a full TAB on line with matches #20885', function()
screen:try_resize(50, 3)
api.nvim_buf_set_lines(0, 0, -1, true, {'\t-- match1', ' -- match2'})
fn.matchadd('Underlined', 'match')
api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 1, end_col = 0, hl_group = 'Visual' })
api.nvim_buf_set_extmark(0, ns, 1, 0, { end_row = 2, end_col = 0, hl_group = 'Visual' })
fn.matchadd('NonText', 'match')
api.nvim_buf_set_extmark(0, ns, 0, 0, { end_row = 1, end_col = 0, hl_group = 'Search' })
api.nvim_buf_set_extmark(0, ns, 1, 0, { end_row = 2, end_col = 0, hl_group = 'Search' })
screen:expect{grid=[[
{18: ^ -- }{29:match}{18:1} |
{18: -- }{29:match}{18:2} |
{34: ^ -- }{35:match}{34:1} |
{34: -- }{35:match}{34:2} |
|
]]}
end)

pending('highlight applies to a full TAB in visual block mode', function()
screen:try_resize(50, 8)
command('hi! Visual guifg=NONE guibg=LightGrey')
api.nvim_buf_set_lines(0, 0, -1, true, {'asdf', '\tasdf', '\tasdf', '\tasdf', 'asdf'})
api.nvim_buf_set_extmark(0, ns, 0, 0, {end_row = 5, end_col = 0, hl_group = 'Underlined'})
screen:expect([[
Expand Down Expand Up @@ -2339,11 +2343,10 @@ describe('extmark decorations', function()

local url = 'https://example.com'

local attrs = screen:get_default_attr_ids()
table.insert(attrs, {
url = url,
screen:set_default_attr_ids({
e = { bold = true, foreground = Screen.colors.Blue },
u = { url = url },
})
screen:set_default_attr_ids(attrs)

api.nvim_buf_set_extmark(0, ns, 1, 4, {
end_col = 14,
Expand All @@ -2352,7 +2355,7 @@ describe('extmark decorations', function()

screen:expect{grid=[[
for _,item in ipairs(items) do |
{44:local text}, hl_id_cell, count = unpack(item) |
{u:local text}, hl_id_cell, count = unpack(item) |
if hl_id_cell ~= nil then |
hl_id = hl_id_cell |
end |
Expand All @@ -2363,8 +2366,8 @@ describe('extmark decorations', function()
colpos = colpos+1 |
end |
en^d |
{1:~ }|
{1:~ }|
{e:~ }|
{e:~ }|
|
]]}
end)
Expand All @@ -2383,7 +2386,7 @@ describe('decorations: inline virtual text', function()
[4] = {background = Screen.colors.Red1, foreground = Screen.colors.Gray100};
[5] = {background = Screen.colors.Red1, bold = true};
[6] = {foreground = Screen.colors.DarkCyan};
[7] = {background = Screen.colors.LightGrey};
[7] = {background = Screen.colors.LightGrey, foreground = Screen.colors.Black};
[8] = {bold = true};
[9] = {background = Screen.colors.Plum1};
[10] = {foreground = Screen.colors.SlateBlue};
Expand Down
8 changes: 4 additions & 4 deletions test/functional/ui/float_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ describe('float window', function()
[24] = {foreground = Screen.colors.Black, background = Screen.colors.Grey80};
[25] = {blend = 100, background = Screen.colors.Gray0};
[26] = {blend = 80, background = Screen.colors.Gray0};
[27] = {background = Screen.colors.LightGray};
[28] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGray};
[27] = {foreground = Screen.colors.Black, background = Screen.colors.LightGrey};
[28] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey};
}
screen:set_default_attr_ids(attrs)
end)
Expand Down Expand Up @@ -7448,8 +7448,8 @@ describe('float window', function()
[10] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 0},
[11] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 80},
[12] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend = 30},
[13] = {background = Screen.colors.LightGray, blend = 30},
[14] = {foreground = Screen.colors.Grey0, background = Screen.colors.Grey88},
[13] = {foreground = Screen.colors.Black, background = Screen.colors.LightGray, blend = 30},
[14] = {foreground = Screen.colors.Black, background = Screen.colors.Grey88},
[15] = {foreground = tonumber('0x939393'), background = Screen.colors.Grey88},
[16] = {background = Screen.colors.Grey90};
[17] = {blend = 100};
Expand Down
8 changes: 4 additions & 4 deletions test/functional/ui/fold_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('folded lines', function()
[13] = { foreground = Screen.colors.Red, background = Screen.colors.LightGrey },
[14] = { background = Screen.colors.Red },
[15] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.Red },
[16] = { background = Screen.colors.LightGrey },
[16] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
[17] = { background = Screen.colors.Yellow, foreground = Screen.colors.Red },
[18] = {
background = Screen.colors.LightGrey,
Expand Down Expand Up @@ -2254,7 +2254,7 @@ describe('folded lines', function()
end)

it('Folded and Visual highlights are combined #19691', function()
command('hi! Visual guibg=Red')
command('hi! Visual guifg=NONE guibg=Red')
insert([[
" foofoofoofoofoofoo
" 口 {{{1
Expand Down Expand Up @@ -2563,7 +2563,7 @@ describe('folded lines', function()
eq('▶--\tsentence composed by', fn.foldtextresult(3))
eq('▶--\tin his cave.', fn.foldtextresult(5))

command('hi! Visual guibg=Red')
command('hi! Visual guifg=NONE guibg=Red')
feed('V2k')
if multigrid then
screen:expect([[
Expand Down Expand Up @@ -2677,7 +2677,7 @@ describe('folded lines', function()
]])
end

command('hi! Visual guibg=Red')
command('hi! Visual guifg=NONE guibg=Red')
feed('V2k')
if multigrid then
screen:expect([[
Expand Down

0 comments on commit 31b3c62

Please sign in to comment.