rakr / vim-one

Adaptation of one-light and one-dark colorschemes for Vim
MIT License
1.99k stars 197 forks source link

Loading vim-one resets background light #21

Closed mnacamura closed 7 years ago

mnacamura commented 7 years ago

Somehow loading vim-one, specifically executing hi Normal ... inside the script, resets background light even if I set it dark.

Below I describe the method to reproduce this problem.

Reprodcution

NeoVim version

NVIM 0.1.7
Build type: RelWithDebInfo
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim-20161208-67773-1y796t8/neovim-0.1.7/build/config -I/tmp/neovim-20161208-67773-1y796t8/neovim-0.1.7/src -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/usr/include -I/tmp/neovim-20161208-67773-1y796t8/neovim-0.1.7/build/src/nvim/auto -I/tmp/neovim-20161208-67773-1y796t8/neovim-0.1.7/build/include
Compiled by mnacamura@suzon.local

Optional features included (+) or not (-): +acl   +iconv    -jemalloc +tui
For differences from Vim, see :help vim-differences

      システム vimrc: "$VIM/sysinit.vim"
       省略時の $VIM: "/usr/local/Cellar/neovim/0.1.7/share/nvim"

Minimal configuration

> tree .config/nvim
.config/nvim
├── autoload
│   └── plug.vim
├── init.vim
└── plugged
    └── vim-one
        ├── README.md
        ├── autoload
        │   └── airline
        │       └── themes
        │           └── one.vim
        ├── colors
        │   └── one.vim
        └── screenshots
            ├── insert-dark.png
            ├── insert-light.png
            ├── logo.png
            ├── normal-dark.png
            ├── normal-light.png
            ├── one.png
            ├── replace-dark.png
            ├── replace-light.png
            ├── visual-dark.png
            └── visual-light.png

8 directories, 15 files

In init.vim, I put the following:

set tgc  " This line is not necessary for reproduction 
call plug#begin('~/.config/nvim/plugged')
Plug 'rakr/vim-one'
call plug#end()
set bg=dark
colo one

Then I added some debug messages to color/one.vim:

diff --git a/colors/one.vim b/colors/one.vim
index b555a8d..0c1e6ea 100644
--- a/colors/one.vim
+++ b/colors/one.vim
@@ -225,7 +225,9 @@ if has('gui_running') || &t_Co == 88 || &t_Co == 256
       exec 'hi ' . a:group . ' guifg=#' . a:fg . ' ctermfg=' . <SID>rgb(a:fg)
     endif
     if a:bg !=? ''
+      if a:group ==# 'Normal' | echom "Before hi Normal ...:" &bg | endif
       exec 'hi ' . a:group . ' guibg=#' . a:bg . ' ctermbg=' . <SID>rgb(a:bg)
+      if a:group ==# 'Normal' | echom "After hi Normal ...:" &bg | endif
     endif
     if a:attr !=? ''
       exec 'hi ' . a:group . ' gui=' . l:attr . ' cterm=' . l:attr
@@ -334,7 +336,9 @@ if has('gui_running') || &t_Co == 88 || &t_Co == 256
   call <sid>X('WarningMsg',   s:hue_5,         '',               '')
   call <sid>X('TooLong',      s:hue_5,         '',               '')
   call <sid>X('WildMenu',     s:syntax_fg,     s:mono_3,         '')
+  echom "Before call <SID>X('Normal', ...):" &bg
   call <sid>X('Normal',       s:syntax_fg,     s:syntax_bg,      '')
+  echom "After call <SID>X('Normal', ...):" &bg
   call <sid>X('SignColumn',   '',              s:mono_3,         '')
   call <sid>X('Special',      s:hue_2,         '',               '')
   " }}}

Output

> nvim
Before call <SID>X('Normal', ...): dark
Before hi Normal ...: dark
After hi Normal ...: light
After call <SID>X('Normal', ...): light
rakr commented 7 years ago

Hi @mnacamura, I have investigated this and this is related to the way Vim works when you set the ctermbg for the Normal highlight. Vim "automatically" determines the best background. The colours for vim-one are approximated and somehow, even though the terminal background for Normal is approximated to 16 (dark colour), Vim switches to light.

So IMO, this is not a bug related to the colorscheme itself but more to the way Vim determines the background "automagically".

You can see this behaviour by selecting any colorscheme and type the following command:

:hi Normal ctermbg=16 | echom &bg

mnacamura commented 7 years ago

Hi @rakr, thank you for your detailed explanation. I didn't know that vim does such magic. I agree that this is an issue of vim itself rather than that of colorscheme. This issue could be closed.

Personally I do not use vim without gui color, so I decided to turn off cterm support to avoid this issue: https://github.com/mnacamura/vim-one/commit/2a18b49f49debf133d552c35f2edf7ebfb7d8829

ahmedelgabri commented 7 years ago

Is there is any way to fix this issue in the main repo? it is very annoying, especially when using something like Goyo https://github.com/junegunn/goyo.vim. On exit it always resets to Light