diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index f424f35..b811dfa 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -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 exec_separator({}, a:from, a:to, a:inverse, '') endfunction function! airline#highlighter#highlight(modes) diff --git a/autoload/airline/themes.vim b/autoload/airline/themes.vim index 0d9158d..770b476 100644 --- a/autoload/airline/themes.vim +++ b/autoload/airline/themes.vim @@ -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) diff --git a/t/highligher.vim b/t/highligher.vim new file mode 100644 index 0000000..658e816 --- /dev/null +++ b/t/highligher.vim @@ -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 + diff --git a/t/themes.vim b/t/themes.vim index d37c8fa..cc814ab 100644 --- a/t/themes.vim +++ b/t/themes.vim @@ -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