clean up builder a bit, use inverse

This commit is contained in:
Bailey Ling 2013-08-17 23:31:51 +00:00
parent 9c02d87f17
commit f49038fba6
2 changed files with 23 additions and 39 deletions

View File

@ -1,18 +1,28 @@
" MIT license. Copyright (c) 2013 Bailey Ling.
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
let s:prototype = {}
function! s:prototype.split(gutter)
call add(self._sections, ['|', a:gutter])
let self._side = 0
let self._line .= '%#'.self._group(self._curgroup).'#'.a:gutter
endfunction
function! s:prototype.add_section(group, contents)
call add(self._sections, [a:group, a:contents])
if self._curgroup != ''
call self._highlighter.add_separator(self._group(self._curgroup), self._group(a:group), self._side)
let self._line .= '%#'.self._group(self._curgroup).'_to_'.self._group(a:group).'#'
let self._line .= self._side
\ ? self._active ? g:airline_left_sep : g:airline_left_alt_sep
\ : self._active ? g:airline_right_sep : g:airline_right_alt_sep
endif
let self._line .= '%#'.self._group(a:group).'#'.a:contents
let self._curgroup = a:group
endfunction
function! s:prototype.add_raw(text)
call add(self._sections, ['_', a:text])
let self._line .= a:text
endfunction
function! s:prototype._group(group)
@ -20,36 +30,7 @@ function! s:prototype._group(group)
endfunction
function! s:prototype.build()
let line = '%{airline#check_mode()}'
let side = 0
let prev_group = ''
for section in self._sections
if section[0] == '|'
let side = 1
let line .= '%#'.self._group(prev_group).'#'.section[1]
let prev_group = ''
continue
endif
if section[0] == '_'
let line .= section[1]
continue
endif
if prev_group != ''
call self._highlighter.add_separator(self._group(prev_group), self._group(section[0]))
let line .= side == 0
\ ? '%#'.self._group(section[0]).'_to_'.self._group(prev_group).'#'
\ : '%#'.self._group(prev_group).'_to_'.self._group(section[0]).'#'
let line .= side == 0
\ ? self._active ? g:airline_left_sep : g:airline_left_alt_sep
\ : self._active ? g:airline_right_sep : g:airline_right_alt_sep
endif
let line .= '%#'.self._group(section[0]).'#'.section[1]
let prev_group = section[0]
endfor
return line
return self._line
endfunction
function! airline#builder#new(active, highlighter)
@ -57,6 +38,9 @@ function! airline#builder#new(active, highlighter)
let builder._sections = []
let builder._active = a:active
let builder._highlighter = a:highlighter
let builder._side = 1
let builder._curgroup = ''
let builder._line = '%{airline#check_mode()}'
return builder
endfunction

View File

@ -19,11 +19,11 @@ function! airline#highlighter#exec(group, colors)
\ get(colors, 4, '') != '' ? 'term='.colors[4] : '')
endfunction
function! s:exec_separator(dict, from, to)
function! s:exec_separator(dict, from, to, invert)
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
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ]
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3], a:invert ? 'inverse' : '' ]
let a:dict[group] = colors
call airline#highlighter#exec(group, colors)
endfunction
@ -39,8 +39,8 @@ function! airline#highlighter#new()
call self.highlight(['normal'])
endfunction
function! highlighter.add_separator(from, to)
let self._separators[a:from.a:to] = [a:from, a:to]
function! highlighter.add_separator(from, to, invert)
let self._separators[a:from.a:to] = [a:from, a:to, a:invert]
endfunction
function! highlighter.highlight(modes)
@ -58,7 +58,7 @@ function! airline#highlighter#new()
if !has_key(self._mode_init, mode)
let self._mode_init[mode] = 1
for sep in items(self._separators)
call <sid>exec_separator(dict, sep[1][0].suffix, sep[1][1].suffix)
call <sid>exec_separator(dict, sep[1][0].suffix, sep[1][1].suffix, sep[1][2])
endfor
endif
endif