improved color mute/fixes

This commit is contained in:
Reed Esau
2014-01-04 14:20:29 -07:00
parent 44e11da566
commit 066839e0be
4 changed files with 68 additions and 33 deletions

View File

@@ -162,11 +162,13 @@ For console or GUI-based Vim:
configured via background configured via background
* `airline-theme` - plugin for theming your status bar * `airline-theme` - plugin for theming your status bar
* `sign-column-color-fix` - temporarily modifies colorscheme to force * `sign-column-color-fix` - temporarily modifies colorscheme to force
gutter background gutter background to match Normal background
* `diff-color-fix` - temporarily modifies colorscheme to force diff * `diff-color-fix` - temporarily modifies colorscheme to force diff
character color character color to a standard red/green/yellow
* `fold-column-color-mute` - temporarily modifies colorscheme to hide * `fold-column-color-mute` - temporarily modifies colorscheme to hide
indicators in foldcolumn indicators, matching Normal text background
* `number-column-color-mute` - temporarily modifies colorscheme to hide
numbers, matching Normal text background
The following options are for GUI-based Vim only (they will be ignored if The following options are for GUI-based Vim only (they will be ignored if
you're running a console-based Vim): you're running a console-based Vim):
@@ -181,7 +183,7 @@ Screen-related:
* `fullscreen` - if 1, force a switch to fullscreen * `fullscreen` - if 1, force a switch to fullscreen
* `fullscreen-background-color-fix` - optional change of color of the * `fullscreen-background-color-fix` - optional change of color of the
background (or border) to match text background background (or border) to match Normal text background
* `columns` and `lines` - youll mostly use these to manage the height * `columns` and `lines` - youll mostly use these to manage the height
and width the text area in `fullscreen` mode and width the text area in `fullscreen` mode
* `transparency` (0=opaque, 100=fully transparent) - view details of * `transparency` (0=opaque, 100=fully transparent) - view details of

View File

@@ -9,6 +9,40 @@
if exists("autoloaded_thematic") | finish | endif if exists("autoloaded_thematic") | finish | endif
let autoloaded_thematic = 1 let autoloaded_thematic = 1
function! s:normalColors(hi_grps)
call s:setColorsTo(a:hi_grps, 'Normal', 'fg', 'bg')
endfunction
function! s:invertColors(hi_grps)
call s:setColorsTo(a:hi_grps, 'Normal', 'bg', 'fg')
endfunction
function! s:muteColors(hi_grps)
call s:setColorsTo(a:hi_grps, 'Normal', 'bg', 'bg')
endfunction
function! s:setColorsTo(hi_grps, target_grp, target_fg, target_bg)
" modify the specified highlight groups based on another highlight group
if has('gui_running')
for l:hi_grp in a:hi_grps
execute 'hi! ' . l:hi_grp . ' guifg=' . a:target_fg . ' guibg=' . a:target_bg
endfor
else
" set the cterm colors iff colorscheme specifies fg and bg
" 'desert' does not, but 'bubblegum' does
let l:target_grp_fg = synIDattr(synIDtrans(hlID(a:target_grp)), 'fg')
let l:target_grp_bg = synIDattr(synIDtrans(hlID(a:target_grp)), 'bg')
let l:ok_fg = l:target_grp_fg !~ '^-1$\|^$'
let l:ok_bg = l:target_grp_bg !~ '^-1$\|^$'
if l:ok_fg && l:ok_bg
for l:hi_grp in a:hi_grps
let l:nu_fg = a:target_fg ==# 'fg' ? l:target_grp_fg : l:target_grp_bg
let l:nu_bg = a:target_bg ==# 'bg' ? l:target_grp_bg : l:target_grp_fg
execute 'hi! ' . l:hi_grp . ' ctermfg=' . l:nu_fg . ' ctermbg=' . l:nu_bg
endfor
endif
endif
endfunction
function! s:getThemeName(mode) function! s:getThemeName(mode)
let l:avail_names = sort(keys(g:thematic#themes)) let l:avail_names = sort(keys(g:thematic#themes))
@@ -94,7 +128,7 @@ function! s:airline(th)
endif endif
endfunction endfunction
function! thematic#init(mode) function! thematic#init(mode) abort
if len(g:thematic#themes) == 0 if len(g:thematic#themes) == 0
echohl WarningMsg | echo 'No themes found.' | echohl NONE echohl WarningMsg | echo 'No themes found.' | echohl NONE
finish finish
@@ -138,40 +172,39 @@ function! thematic#init(mode)
endif endif
" ------ Fix/mute colors ------ " ------ Fix/mute colors ------
let l:gui_running = has('gui_running') let l:gui_running = has('gui_running')
if thematic#getThemeValue(l:th, 'sign-column-color-fix', 0) if thematic#getThemeValue(l:th, 'sign-column-color-fix', 0)
" Ensure the gutter matches the text background " Ensure the gutter matches 'Normal' highlighting
if l:gui_running call s:normalColors(['SignColumn',])
hi! SignColumn guifg=fg guibg=bg
else
hi! SignColumn ctermfg=fg ctermbg=bg
endif
endif endif
if thematic#getThemeValue(l:th, 'diff-color-fix', 0) if thematic#getThemeValue(l:th, 'diff-color-fix', 0)
" Override diff colors " Override diff colors, in case the colorscheme's diff colors are awful
" Use also to fix sign column colors
if l:gui_running if l:gui_running
hi! DiffAdd guifg=darkgreen guibg=bg hi! DiffAdd guifg=DarkGreen guibg=bg
hi! DiffDelete guifg=darkorange guibg=bg hi! DiffDelete guifg=DarkRed guibg=bg
hi! DiffChange guifg=darkyellow guibg=bg hi! DiffChange guifg=DarkYellow guibg=bg
hi! DiffText guifg=fg guibg=bg hi! DiffText guifg=DarkCyan guibg=bg
else else
hi! DiffAdd cterm=bold ctermbg=bg ctermfg=119 call s:normalColors(['DiffAdd','DiffDelete','DiffChange','DiffText',])
hi! DiffDelete cterm=bold ctermbg=bg ctermfg=167 hi! DiffAdd ctermfg=DarkGreen
hi! DiffChange cterm=bold ctermbg=bg ctermfg=227 hi! DiffDelete ctermfg=DarkRed
hi! DiffText cterm=none ctermbg=fg ctermfg=fg hi! DiffChange ctermfg=DarkYellow
hi! DiffText ctermfg=DarkCyan
endif endif
endif endif
if thematic#getThemeValue(l:th, 'fold-column-color-mute', 0) if thematic#getThemeValue(l:th, 'fold-column-color-mute', 0)
" Ensure the fold column is blank, for non-distracted editing " Ensure the fold column is blank, for non-distracted editing
if l:gui_running call s:muteColors(['FoldColumn',])
hi! FoldColumn guifg=bg guibg=bg endif
else
hi! FoldColumn cterm=bold ctermbg=bg ctermfg=bg if thematic#getThemeValue(l:th, 'number-column-color-mute', 0)
endif " Ensure the number column is blank, for non-distracted editing
call s:muteColors(['LineNr', 'CursorLineNr',])
endif endif
" ------ Set statusline, ruler, airline_theme ------ " ------ Set statusline, ruler, airline_theme ------

View File

@@ -145,7 +145,7 @@ function! s:setGuifont(gf)
endfunction endfunction
function! thematic#gui#setFont(th) function! thematic#gui#setFont(th) abort
" attempt to preserve original font if not yet set " attempt to preserve original font if not yet set
if !has_key(g:thematic#original, 'typeface') if !has_key(g:thematic#original, 'typeface')
let l:typeface = s:getTypeface(&guifont, '') let l:typeface = s:getTypeface(&guifont, '')
@@ -171,7 +171,7 @@ function! thematic#gui#setFont(th)
endfunction endfunction
function! thematic#gui#setTransparency(th) function! thematic#gui#setTransparency(th) abort
let l:tr = thematic#getThemeValue(a:th, 'transparency', -1) let l:tr = thematic#getThemeValue(a:th, 'transparency', -1)
if l:tr > 100 if l:tr > 100
let l:tr = 100 let l:tr = 100
@@ -188,7 +188,7 @@ function! thematic#gui#setTransparency(th)
endfunction endfunction
function! thematic#gui#setLinespace(th) function! thematic#gui#setLinespace(th) abort
let l:ls = thematic#getThemeValue(a:th, 'linespace', -1) let l:ls = thematic#getThemeValue(a:th, 'linespace', -1)
if l:ls != -1 if l:ls != -1
try try
@@ -202,7 +202,7 @@ function! thematic#gui#setLinespace(th)
endfunction endfunction
function! thematic#gui#setFullscreen(th) function! thematic#gui#setFullscreen(th) abort
if has('fullscreen') if has('fullscreen')
" Because it can be jarring to see fullscreen disable, " Because it can be jarring to see fullscreen disable,
" we'll only enable it. " we'll only enable it.
@@ -226,7 +226,7 @@ endfunction
" If no explicit settings on lines and columns in " If no explicit settings on lines and columns in
" either the theme or the defaults, then leave alone. " either the theme or the defaults, then leave alone.
function! thematic#gui#setColumnsAndLines(th) function! thematic#gui#setColumnsAndLines(th) abort
let l:columns = thematic#getThemeValue(a:th, 'columns', 0) let l:columns = thematic#getThemeValue(a:th, 'columns', 0)
if l:columns > 0 if l:columns > 0
execute 'set columns=' . l:columns execute 'set columns=' . l:columns

View File

@@ -13,7 +13,7 @@ let g:loaded_thematic_gui = 1
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
function! thematic#gui#init(...) function! thematic#gui#init(...) abort
let l:th = a:0 ? a:1 : {} let l:th = a:0 ? a:1 : {}
call thematic#gui#setFont(l:th) call thematic#gui#setFont(l:th)
call thematic#gui#setTransparency(l:th) call thematic#gui#setTransparency(l:th)
@@ -22,7 +22,7 @@ function! thematic#gui#init(...)
call thematic#gui#setColumnsAndLines(l:th) call thematic#gui#setColumnsAndLines(l:th)
endfunction endfunction
function! thematic#gui#initFullscreen() function! thematic#gui#initFullscreen() abort
" Take control of fullscreen behavior from Vim, specifically to " Take control of fullscreen behavior from Vim, specifically to
" override its default behavior of maximizing columns and lines " override its default behavior of maximizing columns and lines
" in fullscreen Vim. " in fullscreen Vim.