convert the highlighter into a singleton.

This commit is contained in:
Bailey Ling
2013-08-24 09:40:20 -04:00
parent f6d8a981b6
commit 0e6035f75c
3 changed files with 32 additions and 40 deletions

View File

@@ -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()}'

View File

@@ -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