vim-airline/autoload/airline/builder.vim

63 lines
1.8 KiB
VimL
Raw Normal View History

2013-08-16 01:12:02 +00:00
" MIT license. Copyright (c) 2013 Bailey Ling.
2013-08-17 12:50:07 +00:00
" vim: et ts=2 sts=2 sw=2 fdm=indent
2013-08-16 01:12:02 +00:00
2013-08-17 12:50:07 +00:00
function! airline#builder#new(active, highlighter)
2013-08-16 01:12:02 +00:00
let builder = {}
let builder._sections = []
let builder._active = a:active
2013-08-17 12:50:07 +00:00
let builder._highlighter = a:highlighter
2013-08-16 01:12:02 +00:00
function! builder.split(gutter)
call add(self._sections, ['|', a:gutter])
endfunction
function! builder.add_section(group, contents)
2013-08-16 02:02:32 +00:00
call add(self._sections, ['airline_'.a:group, a:contents])
2013-08-16 01:12:02 +00:00
endfunction
function! builder.add_raw(text)
call add(self._sections, ['_', a:text])
endfunction
function! builder._group(group)
2013-08-17 12:50:07 +00:00
return self._active ? a:group : a:group.'_inactive'
2013-08-16 01:12:02 +00:00
endfunction
function! builder.build()
2013-08-16 02:17:59 +00:00
let line = '%{airline#check_mode()}'
2013-08-16 01:12:02 +00:00
let side = 0
let prev_group = ''
for section in self._sections
if section[0] == '|'
let side = 1
let line .= '%#'.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]))
2013-08-16 01:12:02 +00:00
let line .= side == 0
\ ? '%#'.self._group(section[0]).'_to_'.self._group(prev_group).'#'
\ : '%#'.self._group(prev_group).'_to_'.self._group(section[0]).'#'
2013-08-16 01:12:02 +00:00
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
2013-08-17 12:50:07 +00:00
let line .= '%#'.self._group(section[0]).'#'.section[1]
2013-08-16 01:12:02 +00:00
let prev_group = section[0]
endfor
return {
\ 'statusline': line,
\ }
2013-08-16 01:12:02 +00:00
endfunction
return builder
endfunction