2013-08-17 13:35:06 -04:00
|
|
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
2013-08-17 08:50:07 -04:00
|
|
|
|
|
|
|
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running')
|
|
|
|
|
2013-08-20 21:27:00 -04:00
|
|
|
function! s:gui2cui(rgb, fallback)
|
|
|
|
if a:rgb == ''
|
|
|
|
return a:fallback
|
|
|
|
endif
|
|
|
|
let rgb = map(matchlist(a:rgb, '#\(..\)\(..\)\(..\)')[1:3], '0 + ("0x".v:val)')
|
|
|
|
let rgb = [rgb[0] > 127 ? 4 : 0, rgb[1] > 127 ? 2 : 0, rgb[2] > 127 ? 1 : 0]
|
|
|
|
return rgb[0]+rgb[1]+rgb[2]
|
|
|
|
endfunction
|
|
|
|
|
2013-08-17 08:50:07 -04:00
|
|
|
function! airline#highlighter#exec(group, colors)
|
|
|
|
let colors = a:colors
|
|
|
|
if s:is_win32term
|
2013-08-20 21:27:00 -04:00
|
|
|
let colors[2] = s:gui2cui(get(colors, 0, ''), get(colors, 2, ''))
|
|
|
|
let colors[3] = s:gui2cui(get(colors, 1, ''), get(colors, 3, ''))
|
2013-08-17 08:50:07 -04:00
|
|
|
endif
|
|
|
|
exec printf('hi %s %s %s %s %s %s %s %s',
|
|
|
|
\ a:group,
|
2013-08-17 11:12:01 -04: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 08:50:07 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-08-19 21:56:13 -04:00
|
|
|
function! s:exec_separator(dict, from, to, inverse)
|
2013-08-17 08:50:07 -04: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-20 17:27:13 -04:00
|
|
|
if a:inverse
|
|
|
|
let colors = [ l:from[1], l:to[1], l:from[3], l:to[3] ]
|
|
|
|
else
|
|
|
|
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ]
|
|
|
|
endif
|
2013-08-17 13:35:06 -04:00
|
|
|
let a:dict[group] = colors
|
|
|
|
call airline#highlighter#exec(group, colors)
|
2013-08-17 08:50:07 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#highlighter#new()
|
|
|
|
let highlighter = {}
|
2013-08-17 17:10:06 -04:00
|
|
|
let highlighter._separators = {}
|
2013-08-17 13:35:06 -04:00
|
|
|
|
|
|
|
function! highlighter.load_theme()
|
|
|
|
call self.highlight(['inactive'])
|
|
|
|
call self.highlight(['normal'])
|
|
|
|
endfunction
|
2013-08-17 11:12:01 -04:00
|
|
|
|
2013-08-19 21:56:13 -04:00
|
|
|
function! highlighter.add_separator(from, to, inverse)
|
|
|
|
let self._separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
2013-08-17 11:12:01 -04:00
|
|
|
endfunction
|
2013-08-17 08:50:07 -04: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
|
2013-08-17 20:59:49 -04:00
|
|
|
if exists('g:airline#themes#{g:airline_theme}#palette[mode]')
|
|
|
|
let dict = g:airline#themes#{g:airline_theme}#palette[mode]
|
2013-08-17 13:35:06 -04:00
|
|
|
for kvp in items(dict)
|
|
|
|
call airline#highlighter#exec(kvp[0].suffix, kvp[1])
|
2013-08-17 08:50:07 -04:00
|
|
|
endfor
|
2013-08-17 11:12:01 -04:00
|
|
|
|
2013-08-18 01:34:26 -04:00
|
|
|
" TODO: optimize this
|
|
|
|
for sep in items(self._separators)
|
2013-08-19 21:56:13 -04:00
|
|
|
call <sid>exec_separator(dict, sep[1][0].suffix, sep[1][1].suffix, sep[1][2])
|
2013-08-18 01:34:26 -04:00
|
|
|
endfor
|
2013-08-17 13:35:06 -04:00
|
|
|
endif
|
2013-08-17 08:50:07 -04:00
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
return highlighter
|
|
|
|
endfunction
|
|
|
|
|