Skip to content

Commit

Permalink
Unconditionally define GUI colors in 256-colors terminals.
Browse files Browse the repository at this point in the history
Some users have complained that setting `termguicolors` *after* loading
the color scheme does not make GUI colors immediately available: rather,
reloading the color scheme is required. Initially, I thought that there
was no sensible use case for setting `termguicolors` after loading
a color scheme, but that is not the case apparently. The most compelling
reason for having GUI colors defined in all sufficiently capable
terminals is Vim's `:gui` command. This is what user jeanluc2020
reported [here](vim/colorschemes#54):

>I sometimes start vim, editing a file, and later realize this will be
>a longer editing session and I want to have my terminal back during that
>session without jumping in and out of vim or suspending it all the time,
>so i type ":gui" to continue working on the file.

This commit implements a quick fix that should solve this issue. This
solution is suboptimal, however, because `gui` and `cterm` definitions
are still kept separate. Ideally, one would want to define each
highlight group only once. But then, is it necessary to define `cterm`
attributes when running in the GUI?
  • Loading branch information
lifepillar committed Feb 8, 2022
1 parent e89d634 commit d6aed21
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions autoload/colortemplate.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2375,9 +2375,15 @@ fun! s:print_header(bufnr)
endif
endf

fun! s:finish_endif(bufnr)
call s:put(a:bufnr, 'unlet s:t_Co' . (s:uses_italics() ? ' s:italics' : ''))
fun! s:finish_endif(bufnr, variant)
if s:is_gui(a:variant)
call s:put(a:bufnr, "if has('gui_running')")
endif
call s:put(a:bufnr, 'unlet s:t_Co' .. (s:uses_italics() ? ' s:italics' : ''))
call s:put(a:bufnr, 'finish')
if s:is_gui(a:variant)
call s:put(a:bufnr, "endif")
endif
call s:put(a:bufnr, 'endif')
endf

Expand Down Expand Up @@ -2480,7 +2486,7 @@ endf
fun! s:print_colorscheme(bufnr, variant)
call s:put(a:bufnr, '')
if s:is_gui(a:variant)
call s:put(a:bufnr, "if (has('termguicolors') && &termguicolors) || has('gui_running')")
call s:put(a:bufnr, "if s:t_Co >= 256 || has('gui_running')")
else
call s:put(a:bufnr, 'if s:t_Co >= ' . a:variant)
endif
Expand All @@ -2499,7 +2505,7 @@ fun! s:print_colorscheme(bufnr, variant)
let l:background = s:has_dark() ? 'dark' : 'light'
call s:print_colorscheme_defs(a:bufnr, a:variant, l:background)
endif
call s:finish_endif(a:bufnr) " endif termguicolors/t_Co
call s:finish_endif(a:bufnr, a:variant) " endif termguicolors/t_Co
endf

fun! s:generate_colorscheme(outdir, overwrite)
Expand Down

0 comments on commit d6aed21

Please sign in to comment.