highlighter: handle color names when converting into msdos codes

the highlighter code tries to convert the RGB colors into appropriate
color codes for the MSDOS palette. Unfortunately, it does not consider
color names and tries to split those into a list of 3 RGB codes. This
failes for names shorter 6 characters, causing a list index out of
bounds error.

Fix this by making sure, that the color code should start with '#' and
in case it does not, assume it is a color name and simple return the
name in that case.

closes #2350
This commit is contained in:
Christian Brabandt
2021-03-09 13:50:18 +01:00
parent a262ec6ce4
commit 09dbd09ed3

View File

@@ -18,6 +18,9 @@ function! s:gui2cui(rgb, fallback) abort
return a:fallback return a:fallback
elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1 elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1
return a:rgb return a:rgb
elseif a:rgb[0] !~ '#'
" a:rgb contains colorname
return a:rgb
endif endif
let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)') let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)')
return airline#msdos#round_msdos_colors(rgb) return airline#msdos#round_msdos_colors(rgb)