Merge pull request #28156 from bfredl/attr_extend

refactor(tests): allow to extend the new base set of attrs
This commit is contained in:
bfredl 2024-04-03 13:39:08 +02:00 committed by GitHub
commit 1b55ed58ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 252 additions and 281 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1171,6 +1171,10 @@ describe('builtin popupmenu', function()
[6] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, [6] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
[7] = { background = Screen.colors.Yellow }, -- Search [7] = { background = Screen.colors.Yellow }, -- Search
[8] = { foreground = Screen.colors.Red }, [8] = { foreground = Screen.colors.Red },
kn = { foreground = Screen.colors.Red, background = Screen.colors.Magenta },
ks = { foreground = Screen.colors.Red, background = Screen.colors.Grey },
xn = { foreground = Screen.colors.White, background = Screen.colors.Magenta },
xs = { foreground = Screen.colors.Black, background = Screen.colors.Grey },
}) })
screen:attach({ ext_multigrid = multigrid }) screen:attach({ ext_multigrid = multigrid })
end) end)
@ -4477,23 +4481,15 @@ describe('builtin popupmenu', function()
hi PmenuExtra guifg=White guibg=Magenta hi PmenuExtra guifg=White guibg=Magenta
hi PmenuExtraSel guifg=Black guibg=Grey hi PmenuExtraSel guifg=Black guibg=Grey
]]) ]])
local attrs = screen:get_default_attr_ids()
attrs.kn = { foreground = Screen.colors.Red, background = Screen.colors.Magenta }
attrs.ks = { foreground = Screen.colors.Red, background = Screen.colors.Grey }
attrs.xn = { foreground = Screen.colors.White, background = Screen.colors.Magenta }
attrs.xs = { foreground = Screen.colors.Black, background = Screen.colors.Grey }
feed('iaw<C-X><C-u>') feed('iaw<C-X><C-u>')
screen:expect( screen:expect([[
[[
aword1^ | aword1^ |
{s:aword1 }{ks:W }{xs:extra text 1 }{1: }| {s:aword1 }{ks:W }{xs:extra text 1 }{1: }|
{n:aword2 }{kn:W }{xn:extra text 2 }{1: }| {n:aword2 }{kn:W }{xn:extra text 2 }{1: }|
{n:aword3 }{kn:W }{xn:extra text 3 }{1: }| {n:aword3 }{kn:W }{xn:extra text 3 }{1: }|
{1:~ }|*3 {1:~ }|*3
{2:-- }{5:match 1 of 3} | {2:-- }{5:match 1 of 3} |
]], ]])
attrs
)
end) end)
end) end)
end end

View File

@ -255,6 +255,17 @@ function Screen:set_default_attr_ids(attr_ids)
self._default_attr_ids = attr_ids self._default_attr_ids = attr_ids
end end
function Screen:add_extra_attr_ids(extra_attr_ids)
local attr_ids = vim.deepcopy(Screen._global_default_attr_ids)
for id, attr in pairs(extra_attr_ids) do
if type(id) == 'number' and id < 100 then
error('extra attr ids should be at least 100 or be strings')
end
attr_ids[id] = attr
end
self._default_attr_ids = attr_ids
end
function Screen:get_default_attr_ids() function Screen:get_default_attr_ids()
return deepcopy(self._default_attr_ids) return deepcopy(self._default_attr_ids)
end end