mirror of
https://github.com/vim-airline/vim-airline-themes.git
synced 2024-12-04 16:03:34 +08:00
make theme switching more robust, better autocomplete, and reset inactive highlights
This commit is contained in:
parent
16447a6aa9
commit
6b94397105
|
@ -1,6 +1,5 @@
|
|||
" vim: ts=2 sts=2 sw=2 fdm=indent
|
||||
let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running')
|
||||
let s:inactive_colors = g:airline#themes#{g:airline_theme}#inactive "also lazy loads the theme
|
||||
|
||||
let s:airline_highlight_map = {
|
||||
\ 'mode' : 'Al2',
|
||||
|
@ -13,17 +12,27 @@ let s:airline_highlight_map = {
|
|||
let s:airline_highlight_groups = keys(s:airline_highlight_map)
|
||||
|
||||
function! airline#exec_highlight(group, colors)
|
||||
let colors = a:colors
|
||||
if s:is_win32term
|
||||
let colors = map(a:colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val')
|
||||
endif
|
||||
exec printf('hi %s %s %s %s %s %s %s %s',
|
||||
\ a:group,
|
||||
\ a:colors[0] != '' ? 'guifg='.a:colors[0] : '',
|
||||
\ a:colors[1] != '' ? 'guibg='.a:colors[1] : '',
|
||||
\ a:colors[2] != '' ? 'ctermfg='.a:colors[2] : '',
|
||||
\ a:colors[3] != '' ? 'ctermbg='.a:colors[3] : '',
|
||||
\ a:colors[4] != '' ? 'gui='.a:colors[4] : '',
|
||||
\ a:colors[4] != '' ? 'cterm='.a:colors[4] : '',
|
||||
\ a:colors[4] != '' ? 'term='.a:colors[4] : '')
|
||||
\ colors[0] != '' ? 'guifg='.colors[0] : '',
|
||||
\ colors[1] != '' ? 'guibg='.colors[1] : '',
|
||||
\ colors[2] != '' ? 'ctermfg='.colors[2] : '',
|
||||
\ colors[3] != '' ? 'ctermbg='.colors[3] : '',
|
||||
\ colors[4] != '' ? 'gui='.colors[4] : '',
|
||||
\ colors[4] != '' ? 'cterm='.colors[4] : '',
|
||||
\ colors[4] != '' ? 'term='.colors[4] : '')
|
||||
endfunction
|
||||
|
||||
function! airline#load_theme(name)
|
||||
let g:airline_theme = a:name
|
||||
let inactive_colors = g:airline#themes#{g:airline_theme}#inactive "also lazy loads the theme
|
||||
call airline#exec_highlight('airline_inactive', inactive_colors.mode)
|
||||
call airline#highlight(['normal'])
|
||||
endfunction
|
||||
call airline#exec_highlight('airline_inactive', s:inactive_colors.mode)
|
||||
|
||||
function! airline#highlight(modes)
|
||||
" always draw the base mode, and then override any/all of the colors with _override
|
||||
|
@ -32,9 +41,6 @@ function! airline#highlight(modes)
|
|||
for key in s:airline_highlight_groups
|
||||
if exists('g:airline#themes#{g:airline_theme}#{mode}[key]')
|
||||
let colors = g:airline#themes#{g:airline_theme}#{mode}[key]
|
||||
if s:is_win32term
|
||||
let colors = map(colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val')
|
||||
endif
|
||||
call airline#exec_highlight(s:airline_highlight_map[key], colors)
|
||||
endif
|
||||
endfor
|
||||
|
|
|
@ -36,3 +36,7 @@ let g:airline#themes#dark#visual_modified = {
|
|||
\ 'info_separator': [ '#ff5f00' , '#5f005f' , 202 , 53 , '' ] ,
|
||||
\ 'statusline': [ '#ffffff' , '#5f005f' , 255 , 53 , '' ] ,
|
||||
\ }
|
||||
|
||||
function! airline#themes#dark#get(key, modes)
|
||||
return g:airline#themes#dark#normal[key]
|
||||
endfunction
|
||||
|
|
|
@ -39,7 +39,7 @@ function! s:init()
|
|||
if !s:airline_initialized
|
||||
call airline#extensions#load()
|
||||
call airline#update_externals()
|
||||
call airline#highlight(['normal'])
|
||||
call airline#load_theme(g:airline_theme)
|
||||
call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}')
|
||||
call s:check_defined('g:airline_section_b', '%{g:airline_externals_fugitive}')
|
||||
call s:check_defined('g:airline_section_c', g:airline_externals_bufferline)
|
||||
|
@ -51,16 +51,11 @@ function! s:init()
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! s:change_theme(name)
|
||||
let g:airline_theme = a:name
|
||||
let load = g:airline#themes#{a:name}#normal
|
||||
call airline#highlight(['normal'])
|
||||
endfunction
|
||||
function! s:get_airline_themes(a, l, p)
|
||||
let files = split(globpath(&rtp, "autoload/airline/themes/*"), "\n")
|
||||
let files = split(globpath(&rtp, 'autoload/airline/themes/'.a:a.'*'), "\n")
|
||||
return map(files, 'fnamemodify(v:val, ":t:r")')
|
||||
endfunction
|
||||
command! -nargs=1 -complete=customlist,<sid>get_airline_themes AirlineTheme call <sid>change_theme(<f-args>)
|
||||
command! -nargs=1 -complete=customlist,<sid>get_airline_themes AirlineTheme call airline#load_theme(<f-args>)
|
||||
|
||||
augroup airline
|
||||
au!
|
||||
|
|
Loading…
Reference in New Issue
Block a user