Skip to content

Commit

Permalink
fix neovim color mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbra committed Feb 5, 2016
1 parent fdb74f5 commit 87d60fe
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion autoload/airline/builder.vim
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion autoload/airline/extensions/tabline.vim
Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions autoload/airline/highlighter.vim
Expand Up @@ -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
Expand All @@ -36,15 +37,15 @@ 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

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')
Expand Down
7 changes: 7 additions & 0 deletions autoload/airline/init.vim
Expand Up @@ -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, {
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion plugin/airline.vim
Expand Up @@ -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
Expand Down Expand Up @@ -77,7 +78,7 @@ function! s:airline_toggle()
\ | call <sid>on_window_changed()
autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter')

autocmd ColorScheme * call <sid>on_colorscheme_changed()
autocmd GUIEnter,ColorScheme * call <sid>on_colorscheme_changed()
autocmd VimEnter,WinEnter,BufWinEnter,FileType,BufUnload,VimResized *
\ call <sid>on_window_changed()

Expand Down

0 comments on commit 87d60fe

Please sign in to comment.