fix &background value detection

This commit is contained in:
itchyny
2017-11-28 21:30:41 +09:00
parent c5a3060d1a
commit 76e374334c
7 changed files with 43 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
" Filename: autoload/lightline/colorscheme.vim
" Author: itchyny
" License: MIT License
" Last Change: 2015/03/18 08:37:17.
" Last Change: 2017/11/28 21:25:13.
" =============================================================================
let s:save_cpo = &cpo
@@ -224,5 +224,32 @@ function! lightline#colorscheme#flatten(p) abort
return a:p
endfunction
if has('gui_running')
function! lightline#colorscheme#background() abort
return &background
endfunction
else
" &background is set inappropriately when the colorscheme sets ctermbg of the Normal group
function! lightline#colorscheme#background() abort
let bg_color = synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
if bg_color !=# ''
if bg_color < 8 || 232 <= bg_color && bg_color < 244
return 'dark'
elseif 8 <= bg_color && bg_color < 16 || 244 <= bg_color
return 'light'
endif
endif
let fg_color = synIDattr(synIDtrans(hlID('Normal')), 'fg', 'cterm')
if fg_color !=# ''
if fg_color < 8 || 232 <= fg_color && fg_color < 244
return 'light'
elseif 8 <= fg_color && fg_color < 16 || 244 <= fg_color
return 'dark'
endif
endif
return &background
endfunction
endif
let &cpo = s:save_cpo
unlet s:save_cpo