2013-08-18 01:35:06 +08:00
|
|
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
2013-08-17 20:50:07 +08:00
|
|
|
|
|
|
|
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running')
|
|
|
|
|
|
|
|
function! airline#highlighter#exec(group, colors)
|
|
|
|
let colors = a:colors
|
|
|
|
if s:is_win32term
|
|
|
|
let colors = map(a:colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val')
|
|
|
|
endif
|
|
|
|
exec printf('hi %s %s %s %s %s %s %s %s',
|
|
|
|
\ a:group,
|
2013-08-17 23:12:01 +08:00
|
|
|
\ get(colors, 0, '') != '' ? 'guifg='.colors[0] : '',
|
|
|
|
\ get(colors, 1, '') != '' ? 'guibg='.colors[1] : '',
|
|
|
|
\ get(colors, 2, '') != '' ? 'ctermfg='.colors[2] : '',
|
|
|
|
\ get(colors, 3, '') != '' ? 'ctermbg='.colors[3] : '',
|
|
|
|
\ get(colors, 4, '') != '' ? 'gui='.colors[4] : '',
|
|
|
|
\ get(colors, 4, '') != '' ? 'cterm='.colors[4] : '',
|
|
|
|
\ get(colors, 4, '') != '' ? 'term='.colors[4] : '')
|
2013-08-17 20:50:07 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-08-18 07:31:51 +08:00
|
|
|
function! s:exec_separator(dict, from, to, invert)
|
2013-08-17 20:50:07 +08:00
|
|
|
let l:from = airline#themes#get_highlight(a:from)
|
|
|
|
let l:to = airline#themes#get_highlight(a:to)
|
|
|
|
let group = a:from.'_to_'.a:to
|
2013-08-18 07:31:51 +08:00
|
|
|
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3], a:invert ? 'inverse' : '' ]
|
2013-08-18 01:35:06 +08:00
|
|
|
let a:dict[group] = colors
|
|
|
|
call airline#highlighter#exec(group, colors)
|
2013-08-17 20:50:07 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#highlighter#new()
|
|
|
|
let highlighter = {}
|
2013-08-18 05:10:06 +08:00
|
|
|
let highlighter._separators = {}
|
|
|
|
let highlighter._mode_init = {}
|
2013-08-18 01:35:06 +08:00
|
|
|
|
|
|
|
function! highlighter.load_theme()
|
2013-08-18 05:10:06 +08:00
|
|
|
let self._mode_init = {}
|
2013-08-18 01:35:06 +08:00
|
|
|
call self.highlight(['inactive'])
|
|
|
|
call self.highlight(['normal'])
|
|
|
|
endfunction
|
2013-08-17 23:12:01 +08:00
|
|
|
|
2013-08-18 07:31:51 +08:00
|
|
|
function! highlighter.add_separator(from, to, invert)
|
|
|
|
let self._separators[a:from.a:to] = [a:from, a:to, a:invert]
|
2013-08-17 23:12:01 +08:00
|
|
|
endfunction
|
2013-08-17 20:50:07 +08:00
|
|
|
|
|
|
|
function! highlighter.highlight(modes)
|
|
|
|
" draw the base mode, followed by any overrides
|
|
|
|
let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val')
|
|
|
|
let suffix = a:modes[0] == 'inactive' ? '_inactive' : ''
|
|
|
|
for mode in mapped
|
|
|
|
if exists('g:airline#themes#{g:airline_theme}#{mode}')
|
2013-08-18 01:35:06 +08:00
|
|
|
let dict = g:airline#themes#{g:airline_theme}#{mode}
|
|
|
|
for kvp in items(dict)
|
|
|
|
call airline#highlighter#exec(kvp[0].suffix, kvp[1])
|
2013-08-17 20:50:07 +08:00
|
|
|
endfor
|
2013-08-17 23:12:01 +08:00
|
|
|
|
2013-08-18 01:35:06 +08:00
|
|
|
" initialize separator colors for this mode if necessary
|
2013-08-18 05:10:06 +08:00
|
|
|
if !has_key(self._mode_init, mode)
|
|
|
|
let self._mode_init[mode] = 1
|
|
|
|
for sep in items(self._separators)
|
2013-08-18 07:31:51 +08:00
|
|
|
call <sid>exec_separator(dict, sep[1][0].suffix, sep[1][1].suffix, sep[1][2])
|
2013-08-18 01:35:06 +08:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endif
|
2013-08-17 20:50:07 +08:00
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
return highlighter
|
|
|
|
endfunction
|
|
|
|
|