convert the highlighter into a singleton.
This commit is contained in:
parent
f6d8a981b6
commit
0e6035f75c
@ -4,7 +4,6 @@
|
||||
let g:airline_statusline_funcrefs = get(g:, 'airline_statusline_funcrefs', [])
|
||||
|
||||
let s:sections = ['a','b','c','gutter','x','y','z','warning']
|
||||
let s:highlighter = airline#highlighter#new()
|
||||
let s:inactive_funcrefs = []
|
||||
|
||||
function! airline#add_statusline_func(name)
|
||||
@ -27,7 +26,7 @@ function! airline#add_inactive_statusline_func(name)
|
||||
endfunction
|
||||
|
||||
function! airline#load_theme()
|
||||
call s:highlighter.load_theme()
|
||||
call airline#highlighter#load_theme()
|
||||
call airline#extensions#load_theme()
|
||||
endfunction
|
||||
|
||||
@ -116,7 +115,7 @@ function! airline#update_statusline()
|
||||
endfunction
|
||||
|
||||
function! s:invoke_funcrefs(context, funcrefs)
|
||||
let builder = airline#builder#new(a:context, s:highlighter)
|
||||
let builder = airline#builder#new(a:context)
|
||||
let err = airline#util#exec_funcrefs(a:funcrefs, builder, a:context)
|
||||
if err == 0
|
||||
call setwinvar(a:context.winnr, '&statusline', airline#get_statusline(builder, a:context.winnr, a:context.active))
|
||||
@ -152,7 +151,7 @@ function! airline#check_mode()
|
||||
|
||||
let mode_string = join(l:mode)
|
||||
if get(w:, 'airline_lastmode', '') != mode_string
|
||||
call s:highlighter.highlight(l:mode)
|
||||
call airline#highlighter#highlight(l:mode)
|
||||
let w:airline_lastmode = mode_string
|
||||
endif
|
||||
return ''
|
||||
|
@ -10,7 +10,7 @@ endfunction
|
||||
|
||||
function! s:prototype.add_section(group, contents)
|
||||
if self._curgroup != ''
|
||||
call self._highlighter.add_separator(self._curgroup, a:group, self._side)
|
||||
call airline#highlighter#add_separator(self._curgroup, a:group, self._side)
|
||||
let self._line .= '%#'.self._curgroup.'_to_'.a:group.'#'
|
||||
let self._line .= self._side ? g:airline_left_sep : g:airline_right_sep
|
||||
endif
|
||||
@ -30,10 +30,9 @@ function! s:prototype.build()
|
||||
return self._line
|
||||
endfunction
|
||||
|
||||
function! airline#builder#new(context, highlighter)
|
||||
function! airline#builder#new(context)
|
||||
let builder = copy(s:prototype)
|
||||
let builder._context = a:context
|
||||
let builder._highlighter = a:highlighter
|
||||
let builder._side = 1
|
||||
let builder._curgroup = ''
|
||||
let builder._line = '%{airline#check_mode()}'
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user