sainnhe / gruvbox-material

Gruvbox with Material Palette
MIT License
1.83k stars 164 forks source link

Variant always dark in neovim #171

Closed adben27 closed 1 year ago

adben27 commented 1 year ago

I have done the following steps before reporting this issue:

Operating system/version

Fedora 37

Terminal emulator/version

kitty 0.26.5

$TERM environment variable

xterm-kitty

Tmux version

No response

Feature matrix


coc: health#coc#check
========================================================================
  - OK: nvim version satisfied
  - OK: Environment check passed
  - OK: Javascript bundle build/index.js found
  - OK: Service started

man: require("man.health").check()
========================================================================
  - OK: plugin/man.vim not in $VIMRUNTIME
  - OK: autoload/man.vim not in $VIMRUNTIME

nvim: health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: RelWithDebInfo

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $COLORTERM='truecolor'

provider: health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: xsel

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "/usr/bin/python3"
  - INFO: Executable: /usr/bin/python3
  - INFO: Python version: 3.11.2
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - OK: no $VIRTUAL_ENV

## Ruby provider (optional)
  - INFO: Ruby: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
  - WARNING: `neovim-ruby-host` not found.
    - ADVICE:
      - Run `gem install neovim` to ensure the neovim RubyGem is installed.
      - Run `gem environment` to ensure the gem bin directory is in $PATH.
      - If you are using rvm/rbenv/chruby, try "rehashing".
      - See :help |g:ruby_host_prog| for non-standard gem installations.
      - You may disable this provider (and warning) by adding `let g:loaded_ruby_provider = 0` to your init.vim

## Node.js provider (optional)
  - INFO: Node.js: v18.15.0
  - WARNING: Missing "neovim" npm (or yarn, pnpm) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim
      - Run in shell (if you use pnpm): pnpm install -g neovim
      - You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim

## Perl provider (optional)
  - WARNING: "Neovim::Ext" cpan module is not installed
    - ADVICE:
      - See :help |provider-perl| for more information.
      - You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim

vim.lsp: require("vim.lsp.health").check()
========================================================================
  - INFO: LSP log level : WARN
  - INFO: Log path: /home/adsys/.local/state/nvim/lsp.log
  - INFO: Log size: 0 KB

vim.treesitter: require("vim.treesitter.health").check()
========================================================================
  - INFO: Runtime ABI version : 14

Minimal vimrc that can reproduce this bug.

call plug#begin()
Plug 'sainnhe/gruvbox-material'
Plug 'itchyny/lightline.vim'
call plug#end()

if has('termguicolors')
   set termguicolors
endif
colorscheme gruvbox-material

set laststatus=2
set noshowmode
let g:lightline={}
let g:lightline.colorscheme = 'gruvbox_material'

Steps to reproduce this bug using minimal vimrc

  1. "Link" init.vim to .vimrc with

    set runtimepath^=~/.vim runtimepath+=~/.vim/after
    let &packpath = &runtimepath
    source ~/.vimrc
  2. Launch vim and see that the theme of lightline is correct. Screenshot from 2023-04-03 10-44-31

  3. Launch nvim and see that the theme is dark even if background is light Screenshot from 2023-04-03 10-44-20

Expected behavior

Having lightline light theme when background is light.

Actual behavior

The lightline theme is dark even if background is light

antoineco commented 1 year ago

You need set background=light in your vimrc. Neovim defaults to "dark".

antoineco commented 1 year ago

In case this doesn't work, or if you prefer the light/dark background to be determined automatically, I recommend using an autocmd as the one below to reload lightline upon colorscheme changes (this will also be executed during the initial loading of the colorscheme):

-- Reload lightline on colorscheme change.
-- Must be declared before executing ':colorscheme'.
grpid = vim.api.nvim_create_augroup('lightline_reload_colorscheme', {})
vim.api.nvim_create_autocmd('ColorScheme', {
  group = grpid,
  pattern = '*',
  command = 'call nviminit#lightline#SetColorscheme() | ' ..
            'call nviminit#lightline#Reload()'
})

Where the two functions from the command are something like:

https://github.com/antoineco/dotfiles/blob/91d0e4b7/nvim/autoload/nviminit/lightline.vim

adben27 commented 1 year ago

First, thanks for your answer. But I wonder if you could help me on this.

I want to set background depending on the kitty theme (it's changed with the GNOME extension Night Theme Switcher at sunset/rise time)

So, i found a way to extract only the name of the current kitty theme, but i just can't figure out how to make it work. I'm quite a noob at vimscript.

So, here is my idea.

let ${KITTY_THEME}={grep -Po '## name: \K[^"]*' ~/.config/kitty/current-theme.conf}
if(KITTY_THEME == 'Gruvbox Material Light Medium') 
    set background=light
else
    set background=dark
endif
antoineco commented 1 year ago

A similar use case is described in details here: https://arslan.io/2021/02/15/automatic-dark-mode-for-terminal-applications/

I think you should be able to achieve something similar with your setup.