mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-05-17 22:09:40 +08:00
convert the highlighter into a singleton.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running')
|
||||
let s:separators = {}
|
||||
|
||||
function! s:gui2cui(rgb, fallback)
|
||||
if a:rgb == ''
|
||||
@@ -42,38 +43,31 @@ function! s:exec_separator(dict, from, to, inverse, suffix)
|
||||
call airline#highlighter#exec(group, colors)
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#new()
|
||||
let highlighter = {}
|
||||
let highlighter._separators = {}
|
||||
|
||||
function! highlighter.load_theme()
|
||||
call self.highlight(['inactive'])
|
||||
call self.highlight(['normal'])
|
||||
endfunction
|
||||
|
||||
function! highlighter.add_separator(from, to, inverse)
|
||||
let self._separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
||||
endfunction
|
||||
|
||||
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}#palette[mode]')
|
||||
let dict = g:airline#themes#{g:airline_theme}#palette[mode]
|
||||
for kvp in items(dict)
|
||||
call airline#highlighter#exec(kvp[0].suffix, kvp[1])
|
||||
endfor
|
||||
|
||||
" TODO: optimize this
|
||||
for sep in items(self._separators)
|
||||
call <sid>exec_separator(dict, sep[1][0], sep[1][1], sep[1][2], suffix)
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
return highlighter
|
||||
function! airline#highlighter#load_theme()
|
||||
call airline#highlighter#highlight(['inactive'])
|
||||
call airline#highlighter#highlight(['normal'])
|
||||
endfunction
|
||||
|
||||
function! airline#highlighter#add_separator(from, to, inverse)
|
||||
let s:separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
||||
endfunction
|
||||
|
||||
function! airline#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}#palette[mode]')
|
||||
let dict = g:airline#themes#{g:airline_theme}#palette[mode]
|
||||
for kvp in items(dict)
|
||||
call airline#highlighter#exec(kvp[0].suffix, kvp[1])
|
||||
endfor
|
||||
|
||||
" TODO: optimize this
|
||||
for sep in items(s:separators)
|
||||
call <sid>exec_separator(dict, sep[1][0], sep[1][1], sep[1][2], suffix)
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user