move highlighter code to correct place and test.
This commit is contained in:
parent
4b33adee42
commit
f6900aeb0a
|
@ -13,6 +13,44 @@ function! s:gui2cui(rgb, fallback)
|
|||
return rgb[0]+rgb[1]+rgb[2]
|
||||
endfunction
|
||||
|
||||
function! s:get_syn(group, what)
|
||||
" need to pass in mode, known to break on 7.3.547
|
||||
let mode = has('gui_running') ? 'gui' : 'cterm'
|
||||
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, mode)
|
||||
if empty(color) || color == -1
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, mode)
|
||||
endif
|
||||
if empty(color) || color == -1
|
||||
if has('gui_running')
|
||||
let color = a:what ==# 'fg' ? '#000000' : '#FFFFFF'
|
||||
else
|
||||
let color = a:what ==# 'fg' ? 0 : 1
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
endfunction
|
||||
|
||||
function! s:get_array(fg, bg, opts)
|
||||
let fg = a:fg
|
||||
let bg = a:bg
|
||||
return has('gui_running')
|
||||
\ ? [ fg, bg, '', '', join(a:opts, ',') ]
|
||||
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight(group, ...)
|
||||
let fg = s:get_syn(a:group, 'fg')
|
||||
let bg = s:get_syn(a:group, 'bg')
|
||||
let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', has('gui_running') ? 'gui' : 'term')
|
||||
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#get_highlight2(fg, bg, ...)
|
||||
let fg = s:get_syn(a:fg[0], a:fg[1])
|
||||
let bg = s:get_syn(a:bg[0], a:bg[1])
|
||||
return s:get_array(fg, bg, a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#exec(group, colors)
|
||||
let colors = a:colors
|
||||
if s:is_win32term
|
||||
|
@ -50,6 +88,7 @@ endfunction
|
|||
|
||||
function! airline#highlighter#add_separator(from, to, inverse)
|
||||
let s:separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
||||
call <sid>exec_separator({}, a:from, a:to, a:inverse, '')
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#highlight(modes)
|
||||
|
|
|
@ -15,42 +15,12 @@ function! airline#themes#generate_color_map(section1, section2, section3, file)
|
|||
\ }
|
||||
endfunction
|
||||
|
||||
function! s:get_syn(group, what)
|
||||
" need to pass in mode, known to break on 7.3.547
|
||||
let mode = has('gui_running') ? 'gui' : 'cterm'
|
||||
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, mode)
|
||||
if empty(color) || color == -1
|
||||
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, mode)
|
||||
endif
|
||||
if empty(color) || color == -1
|
||||
if has('gui_running')
|
||||
let color = a:what ==# 'fg' ? '#000000' : '#FFFFFF'
|
||||
else
|
||||
let color = a:what ==# 'fg' ? 0 : 1
|
||||
endif
|
||||
endif
|
||||
return color
|
||||
endfunction
|
||||
|
||||
function! s:get_array(fg, bg, opts)
|
||||
let fg = a:fg
|
||||
let bg = a:bg
|
||||
return has('gui_running')
|
||||
\ ? [ fg, bg, '', '', join(a:opts, ',') ]
|
||||
\ : [ '', '', fg, bg, join(a:opts, ',') ]
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight(group, ...)
|
||||
let fg = s:get_syn(a:group, 'fg')
|
||||
let bg = s:get_syn(a:group, 'bg')
|
||||
let reverse = synIDattr(synIDtrans(hlID(a:group)), 'reverse', has('gui_running') ? 'gui' : 'term')
|
||||
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
||||
return call('airline#highlighter#get_highlight', [a:group] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#get_highlight2(fg, bg, ...)
|
||||
let fg = s:get_syn(a:fg[0], a:fg[1])
|
||||
let bg = s:get_syn(a:bg[0], a:bg[1])
|
||||
return s:get_array(fg, bg, a:000)
|
||||
return call('airline#highlighter#get_highlight2', [a:fg, a:bg] + a:000)
|
||||
endfunction
|
||||
|
||||
function! airline#themes#patch(palette)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
describe 'highlighter'
|
||||
it 'should create separator highlight groups'
|
||||
hi Foo1 ctermfg=1 ctermbg=2
|
||||
hi Foo2 ctermfg=3 ctermbg=4
|
||||
call airline#highlighter#add_separator('Foo1', 'Foo2', 0)
|
||||
let hl = airline#highlighter#get_highlight('Foo1_to_Foo2')
|
||||
Expect hl == [ '', '', '4', '2', '' ]
|
||||
end
|
||||
end
|
||||
|
|
@ -25,5 +25,13 @@ describe 'themes'
|
|||
Expect colors[2] == '222'
|
||||
Expect colors[3] == '103'
|
||||
end
|
||||
|
||||
it 'should pass args through correctly'
|
||||
let hl = airline#themes#get_highlight('Foo', 'bold', 'italic')
|
||||
Expect hl == ['', '', 0, 1, 'bold,italic']
|
||||
|
||||
let hl = airline#themes#get_highlight2(['Foo','bg'], ['Foo','fg'], 'italic', 'bold')
|
||||
Expect hl == ['', '', 1, 0, 'italic,bold']
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue