feat(ui): allow to set the highlight namespace per window

- reimplement 'winhl' in terms of highlight namespaces
- check for EOF in screen tests (to indicate a likely crash)
This commit is contained in:
bfredl
2022-07-25 10:16:33 +02:00
parent f7cfca49d6
commit d879331b0d
30 changed files with 596 additions and 244 deletions

View File

@@ -3,9 +3,10 @@ local Screen = require('test.functional.ui.screen')
local os = require('os')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local command, exec = helpers.command, helpers.exec
local eval, exc_exec = helpers.eval, helpers.exc_exec
local eval = helpers.eval
local feed_command, eq = helpers.feed_command, helpers.eq
local curbufmeths = helpers.curbufmeths
local meths = helpers.meths
describe('colorscheme compatibility', function()
before_each(function()
@@ -1787,6 +1788,7 @@ describe("'winhighlight' highlight", function()
[26] = {background = Screen.colors.Red},
[27] = {background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1},
[28] = {bold = true, foreground = Screen.colors.Brown},
[29] = {foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true};
})
command("hi Background1 guibg=DarkBlue")
command("hi Background2 guibg=DarkGreen")
@@ -1820,7 +1822,7 @@ describe("'winhighlight' highlight", function()
]])
end)
it('handles invalid values', function()
it('handles undefined groups', function()
command("set winhl=Normal:Background1")
screen:expect([[
{1:^ }|
@@ -1833,19 +1835,44 @@ describe("'winhighlight' highlight", function()
|
]])
eq('Vim(set):E474: Invalid argument: winhl=xxx:yyy',
exc_exec("set winhl=xxx:yyy"))
eq('Normal:Background1', eval('&winhl'))
command("set winhl=xxx:yyy")
eq('xxx:yyy', eval('&winhl'))
screen:expect{grid=[[
{1:^ }|
{2:~ }|
{2:~ }|
{2:~ }|
{2:~ }|
{2:~ }|
{2:~ }|
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]], unchanged=true}
]]}
end)
it('can be changed to define different groups', function()
command("set winhl=EndOfBuffer:Background1")
screen:expect{grid=[[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]]}
command("set winhl=Normal:ErrorMsg")
screen:expect{grid=[[
{15:^ }|
{29:~ }|
{29:~ }|
{29:~ }|
{29:~ }|
{29:~ }|
{29:~ }|
|
]]}
end)
it('works local to the window', function()
@@ -2270,4 +2297,145 @@ describe("'winhighlight' highlight", function()
|
]])
end)
it("can override syntax groups", function()
command('syntax on')
command('syntax keyword Foobar foobar')
command('syntax keyword Article the')
command('hi Foobar guibg=#FF0000')
command('hi Article guifg=#00FF00 gui=bold')
insert('the foobar was foobar')
screen:expect([[
{25:the} {26:foobar} was {26:fooba}|
{26:^r} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
command('split')
command('set winhl=Foobar:Background1,Article:ErrorMsg')
screen:expect{grid=[[
{15:the} {1:foobar} was {1:fooba}|
{1:^r} |
{0:~ }|
{3:[No Name] [+] }|
{25:the} {26:foobar} was {26:fooba}|
{26:r} |
{4:[No Name] [+] }|
|
]]}
end)
end)
describe('highlight namespaces', function()
local screen
local ns1, ns2
before_each(function()
clear()
screen = Screen.new(25,10)
screen:attach()
screen:set_default_attr_ids {
[1] = {foreground = Screen.colors.Blue, bold = true};
[2] = {background = Screen.colors.DarkGrey};
[3] = {italic = true, foreground = Screen.colors.DarkCyan, background = Screen.colors.DarkOrange4};
[4] = {background = Screen.colors.Magenta4};
[5] = {background = Screen.colors.Magenta4, foreground = Screen.colors.Crimson};
[6] = {bold = true, reverse = true};
[7] = {reverse = true};
}
ns1 = meths.create_namespace 'grungy'
ns2 = meths.create_namespace 'ultrared'
meths.set_hl(ns1, 'Normal', {bg='DarkGrey'})
meths.set_hl(ns1, 'NonText', {bg='DarkOrange4', fg='DarkCyan', italic=true})
meths.set_hl(ns2, 'Normal', {bg='DarkMagenta'})
meths.set_hl(ns2, 'NonText', {fg='Crimson'})
end)
it('can be used globally', function()
screen:expect{grid=[[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]]}
meths.set_hl_ns(ns1)
screen:expect{grid=[[
{2:^ }|
{3:~ }|
{3:~ }|
{3:~ }|
{3:~ }|
{3:~ }|
{3:~ }|
{3:~ }|
{3:~ }|
|
]]}
meths.set_hl_ns(ns2)
screen:expect{grid=[[
{4:^ }|
{5:~ }|
{5:~ }|
{5:~ }|
{5:~ }|
{5:~ }|
{5:~ }|
{5:~ }|
{5:~ }|
|
]]}
meths.set_hl_ns(0)
screen:expect{grid=[[
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]]}
end)
it('can be used per window', function()
local win1 = meths.get_current_win()
command 'split'
local win2 = meths.get_current_win()
command 'split'
meths.win_set_hl_ns(win1, ns1)
meths.win_set_hl_ns(win2, ns2)
screen:expect{grid=[[
^ |
{1:~ }|
{6:[No Name] }|
{4: }|
{5:~ }|
{7:[No Name] }|
{2: }|
{3:~ }|
{7:[No Name] }|
|
]]}
end)
end)