2016-01-14 21:38:38 -05:00
|
|
|
" MIT License. Copyright (c) 2013-2016 Bailey Ling.
|
2013-08-17 13:35:06 -04:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
2013-08-17 08:50:07 -04:00
|
|
|
|
2015-03-06 09:42:04 -05:00
|
|
|
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') && (empty($CONEMUBUILD) || &term !=? 'xterm')
|
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
let s:separators = {}
|
2013-11-01 00:54:10 -04:00
|
|
|
let s:accents = {}
|
2013-08-17 08:50:07 -04:00
|
|
|
|
2013-08-20 21:27:00 -04:00
|
|
|
function! s:gui2cui(rgb, fallback)
|
|
|
|
if a:rgb == ''
|
|
|
|
return a:fallback
|
2016-01-27 14:06:22 -05:00
|
|
|
elseif match(a:rgb, '^\%(NONE\|[fb]g\)$') > -1
|
2016-01-27 13:12:54 -05:00
|
|
|
return a:rgb
|
2013-08-20 21:27:00 -04:00
|
|
|
endif
|
2016-01-27 14:06:22 -05:00
|
|
|
let rgb = map(split(a:rgb[1:], '..\zs'), '0 + ("0x".v:val)')
|
|
|
|
return airline#msdos#round_msdos_colors(rgb)
|
2013-08-20 21:27:00 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-09-01 22:57:32 -04:00
|
|
|
function! s:get_syn(group, what)
|
2016-02-05 16:19:48 -05:00
|
|
|
if !exists("g:airline_gui_mode")
|
|
|
|
let g:airline_gui_mode = airline#init#gui_mode()
|
|
|
|
endif
|
|
|
|
let color = synIDattr(synIDtrans(hlID(a:group)), a:what, g:airline_gui_mode)
|
2013-09-01 22:57:32 -04:00
|
|
|
if empty(color) || color == -1
|
2016-02-05 16:19:48 -05:00
|
|
|
let color = synIDattr(synIDtrans(hlID('Normal')), a:what, g:airline_gui_mode)
|
2013-09-01 22:57:32 -04:00
|
|
|
endif
|
|
|
|
if empty(color) || color == -1
|
2016-02-15 18:36:57 -05:00
|
|
|
let color = 'NONE'
|
2013-09-01 22:57:32 -04:00
|
|
|
endif
|
|
|
|
return color
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:get_array(fg, bg, opts)
|
2016-02-05 16:19:48 -05:00
|
|
|
return g:airline_gui_mode ==# 'gui'
|
2016-06-06 14:40:51 -04:00
|
|
|
\ ? [ a:fg, a:bg, '', '', join(a:opts, ',') ]
|
|
|
|
\ : [ '', '', a:fg, a:bg, join(a:opts, ',') ]
|
2013-09-01 22:57:32 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#highlighter#get_highlight(group, ...)
|
|
|
|
let fg = s:get_syn(a:group, 'fg')
|
|
|
|
let bg = s:get_syn(a:group, 'bg')
|
2016-02-05 16:19:48 -05:00
|
|
|
let reverse = g:airline_gui_mode ==# 'gui'
|
2014-06-29 09:27:53 -04:00
|
|
|
\ ? synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'gui')
|
|
|
|
\ : synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm')
|
|
|
|
\|| synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'term')
|
2013-09-01 22:57:32 -04:00
|
|
|
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#highlighter#get_highlight2(fg, bg, ...)
|
|
|
|
let fg = s:get_syn(a:fg[0], a:fg[1])
|
|
|
|
let bg = s:get_syn(a:bg[0], a:bg[1])
|
|
|
|
return s:get_array(fg, bg, a:000)
|
|
|
|
endfunction
|
|
|
|
|
2013-08-17 08:50:07 -04:00
|
|
|
function! airline#highlighter#exec(group, colors)
|
2016-01-28 11:27:17 -05:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
endif
|
2013-08-17 08:50:07 -04:00
|
|
|
let colors = a:colors
|
|
|
|
if s:is_win32term
|
2013-08-20 21:27:00 -04:00
|
|
|
let colors[2] = s:gui2cui(get(colors, 0, ''), get(colors, 2, ''))
|
|
|
|
let colors[3] = s:gui2cui(get(colors, 1, ''), get(colors, 3, ''))
|
2013-08-17 08:50:07 -04:00
|
|
|
endif
|
2016-01-28 11:27:17 -05:00
|
|
|
let old_hi = airline#highlighter#get_highlight(a:group)
|
|
|
|
if len(colors) == 4
|
|
|
|
call add(colors, '')
|
|
|
|
endif
|
|
|
|
if old_hi != colors
|
2016-06-06 14:41:33 -04:00
|
|
|
let cmd = printf('hi %s %s %s %s %s %s %s %s',
|
|
|
|
\ a:group, s:Get(colors, 0, 'guifg=', ''), s:Get(colors, 1, 'guibg=', ''),
|
|
|
|
\ s:Get(colors, 2, 'ctermfg=', ''), s:Get(colors, 3, 'ctermbg=', ''),
|
|
|
|
\ s:Get(colors, 4, 'gui=', ''), s:Get(colors, 4, 'cterm=', ''),
|
|
|
|
\ s:Get(colors, 4, 'term=', ''))
|
2016-01-28 11:27:17 -05:00
|
|
|
exe cmd
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Get(dict, key, prefix, default)
|
|
|
|
if get(a:dict, a:key, a:default) isnot# a:default
|
|
|
|
return a:prefix. get(a:dict, a:key)
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
2013-08-17 08:50:07 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-08-23 22:49:24 -04:00
|
|
|
function! s:exec_separator(dict, from, to, inverse, suffix)
|
2016-01-28 11:27:17 -05:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
endif
|
2013-08-23 22:49:24 -04:00
|
|
|
let l:from = airline#themes#get_highlight(a:from.a:suffix)
|
|
|
|
let l:to = airline#themes#get_highlight(a:to.a:suffix)
|
|
|
|
let group = a:from.'_to_'.a:to.a:suffix
|
2013-08-20 17:27:13 -04:00
|
|
|
if a:inverse
|
|
|
|
let colors = [ l:from[1], l:to[1], l:from[3], l:to[3] ]
|
|
|
|
else
|
|
|
|
let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ]
|
|
|
|
endif
|
2013-08-17 13:35:06 -04:00
|
|
|
let a:dict[group] = colors
|
|
|
|
call airline#highlighter#exec(group, colors)
|
2013-08-17 08:50:07 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
function! airline#highlighter#load_theme()
|
2016-01-28 11:27:17 -05:00
|
|
|
if pumvisible()
|
|
|
|
return
|
|
|
|
endif
|
2013-09-07 09:03:15 -04:00
|
|
|
for winnr in filter(range(1, winnr('$')), 'v:val != winnr()')
|
|
|
|
call airline#highlighter#highlight_modified_inactive(winbufnr(winnr))
|
|
|
|
endfor
|
2013-08-24 09:40:20 -04:00
|
|
|
call airline#highlighter#highlight(['inactive'])
|
|
|
|
call airline#highlighter#highlight(['normal'])
|
|
|
|
endfunction
|
2013-08-17 08:50:07 -04:00
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
function! airline#highlighter#add_separator(from, to, inverse)
|
|
|
|
let s:separators[a:from.a:to] = [a:from, a:to, a:inverse]
|
2013-09-01 22:57:32 -04:00
|
|
|
call <sid>exec_separator({}, a:from, a:to, a:inverse, '')
|
2013-08-24 09:40:20 -04:00
|
|
|
endfunction
|
2013-08-17 11:12:01 -04:00
|
|
|
|
2013-11-01 00:54:10 -04:00
|
|
|
function! airline#highlighter#add_accent(accent)
|
|
|
|
let s:accents[a:accent] = 1
|
|
|
|
endfunction
|
|
|
|
|
2013-09-07 09:00:10 -04:00
|
|
|
function! airline#highlighter#highlight_modified_inactive(bufnr)
|
|
|
|
if getbufvar(a:bufnr, '&modified')
|
|
|
|
let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c')
|
|
|
|
\ ? g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c : []
|
|
|
|
else
|
|
|
|
let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive.airline_c')
|
|
|
|
\ ? g:airline#themes#{g:airline_theme}#palette.inactive.airline_c : []
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !empty(colors)
|
|
|
|
call airline#highlighter#exec('airline_c'.(a:bufnr).'_inactive', colors)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
function! airline#highlighter#highlight(modes)
|
2013-09-27 21:36:44 -04:00
|
|
|
let p = g:airline#themes#{g:airline_theme}#palette
|
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
" 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)
|
2013-09-27 21:36:44 -04:00
|
|
|
let mode_colors = kvp[1]
|
|
|
|
call airline#highlighter#exec(kvp[0].suffix, mode_colors)
|
|
|
|
|
2013-11-01 00:54:10 -04:00
|
|
|
for accent in keys(s:accents)
|
|
|
|
if !has_key(p.accents, accent)
|
|
|
|
continue
|
|
|
|
endif
|
2013-09-27 21:36:44 -04:00
|
|
|
let colors = copy(mode_colors)
|
|
|
|
if p.accents[accent][0] != ''
|
|
|
|
let colors[0] = p.accents[accent][0]
|
|
|
|
endif
|
|
|
|
if p.accents[accent][2] != ''
|
|
|
|
let colors[2] = p.accents[accent][2]
|
|
|
|
endif
|
|
|
|
if len(colors) >= 5
|
|
|
|
let colors[4] = get(p.accents[accent], 4, '')
|
|
|
|
else
|
|
|
|
call add(colors, get(p.accents[accent], 4, ''))
|
|
|
|
endif
|
|
|
|
call airline#highlighter#exec(kvp[0].suffix.'_'.accent, colors)
|
|
|
|
endfor
|
2013-08-24 09:40:20 -04:00
|
|
|
endfor
|
2013-08-17 08:50:07 -04:00
|
|
|
|
2013-08-24 09:40:20 -04:00
|
|
|
" 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
|
2013-08-17 08:50:07 -04:00
|
|
|
endfunction
|
|
|
|
|