From 87d60febafdb2533ca468724ab5d1bf38f5bb338 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Fri, 5 Feb 2016 22:19:48 +0100 Subject: [PATCH] fix neovim color mode --- autoload/airline/builder.vim | 2 +- autoload/airline/extensions/tabline.vim | 2 +- autoload/airline/highlighter.vim | 15 ++++++++------- autoload/airline/init.vim | 7 +++++++ plugin/airline.vim | 3 ++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index 6e2a0e5..217fda9 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -77,7 +77,7 @@ function! s:should_change_group(group1, group2) endif let color1 = airline#highlighter#get_highlight(a:group1) let color2 = airline#highlighter#get_highlight(a:group2) - if has('gui_running') || has('nvim') || (has("termtruecolor") && &guicolors == 1) + if g:airline_gui_mode ==# 'gui' return color1[1] != color2[1] || color1[0] != color2[0] else return color1[3] != color2[3] || color1[2] != color2[2] diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index b0d5eee..8f2f959 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -12,7 +12,7 @@ endif function! airline#extensions#tabline#init(ext) - if has('nvim') || has('gui_running') + if has('gui_running') set guioptions-=e endif diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index c586978..d9ade3e 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -17,14 +17,15 @@ function! s:gui2cui(rgb, fallback) endfunction function! s:get_syn(group, what) - " need to pass in mode, known to break on 7.3.547 - let mode = has('nvim') || has('gui_running') || (has("termtruecolor") && &guicolors == 1) ? 'gui' : 'cterm' - let color = synIDattr(synIDtrans(hlID(a:group)), a:what, mode) + 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) if empty(color) || color == -1 - let color = synIDattr(synIDtrans(hlID('Normal')), a:what, mode) + let color = synIDattr(synIDtrans(hlID('Normal')), a:what, g:airline_gui_mode) endif if empty(color) || color == -1 - if has('nvim') || has('gui_running') || (has("termtruecolor") && &guicolors == 1) + if g:airline_gui_mode ==# 'gui' let color = a:what ==# 'fg' ? '#000000' : '#FFFFFF' else let color = a:what ==# 'fg' ? 0 : 1 @@ -36,7 +37,7 @@ endfunction function! s:get_array(fg, bg, opts) let fg = a:fg let bg = a:bg - return has('nvim') || has('gui_running') || (has("termtruecolor") && &guicolors == 1) + return g:airline_gui_mode ==# 'gui' \ ? [ fg, bg, '', '', join(a:opts, ',') ] \ : [ '', '', fg, bg, join(a:opts, ',') ] endfunction @@ -44,7 +45,7 @@ endfunction function! airline#highlighter#get_highlight(group, ...) let fg = s:get_syn(a:group, 'fg') let bg = s:get_syn(a:group, 'bg') - let reverse = has('nvim') || has('gui_running') || (has("termtruecolor") && &guicolors == 1) + let reverse = g:airline_gui_mode ==# 'gui' \ ? synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'gui') \ : synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm') \|| synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'term') diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 40244dd..470c2c9 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -27,6 +27,7 @@ function! airline#init#bootstrap() call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) call s:check_defined('g:airline_exclude_filetypes', []) call s:check_defined('g:airline_exclude_preview', 0) + call s:check_defined('g:airline_gui_mode', airline#init#gui_mode()) call s:check_defined('g:airline_mode_map', {}) call extend(g:airline_mode_map, { @@ -92,6 +93,12 @@ function! airline#init#bootstrap() unlet g:airline#init#bootstrapping endfunction +function! airline#init#gui_mode() + return ((has('nvim') && exists('$NVIM_TUI_ENABLE_TRUE_COLOR')) + \ || has('gui_running') || (has("termtruecolor") && &guicolors == 1)) ? + \ 'gui' : 'cterm' +endfunction + function! airline#init#sections() let spc = g:airline_symbols.space if !exists('g:airline_section_a') diff --git a/plugin/airline.vim b/plugin/airline.vim index d4385c4..32ddcbf 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -43,6 +43,7 @@ endfunction function! s:on_colorscheme_changed() call s:init() + let g:airline_gui_mode = airline#init#gui_mode() if !s:theme_in_vimrc call airline#switch_matching_theme() endif @@ -77,7 +78,7 @@ function! s:airline_toggle() \ | call on_window_changed() autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter') - autocmd ColorScheme * call on_colorscheme_changed() + autocmd GUIEnter,ColorScheme * call on_colorscheme_changed() autocmd VimEnter,WinEnter,BufWinEnter,FileType,BufUnload,VimResized * \ call on_window_changed()