fenetikm / falcon

A colour scheme for terminals, Vim and friends.
MIT License
726 stars 26 forks source link

Inactive colors behaving weirdly #16

Closed filipekiss closed 6 years ago

filipekiss commented 6 years ago

Hey @fenetikm, thank you so much for Falcon! I love the colors.

I've tried to move my setup to use Falcon all around (NeoVim + iTerm2 + TMUX) and something seems odd and I hope you can point me to a direction to see what I am doing wrong.

When I move to a pane that does not have NeoVim open, the color doesn't seem to change for the inactive one:

image

I've checked to see if the autocmd for the color change is working and it is. So I ran hi InactiveWindow guibg=yellow and then this happens:

image

And when I move focus out of NeoVim to another pane:

image (See how the last focused window at the bottom right corner is not yellow?)

So, two things: Is there a way to make the InactiveWindow bg be applied to the whole window/buffer and not just to the size of the file?

And second: Shouldn't all NeoVim buffers be marked as "inactive" when I'm on another Tmux pane?

Thank you so much for your help!

fenetikm commented 6 years ago

Yeah I really need to add in a bit more detail on how to set this up as it's a bit fiddly.

So to get the whole inactive / active thing going you need:

let g:falcon_lightline = 1 let g:lightline.colorscheme='falcon' let g:falcon_background = 0 let g:falcon_inactive = 1

colorscheme falcon


(the lightline stuff is optional)

Let me know if you have all of the above and how you go.
filipekiss commented 6 years ago

So I updated my NeoVim (built from source, latest commit) and checked for truecolor: image Everything seems to be ok. (Left is Terminal inside NeoVim and right is pure shell)

echo exists('+winhighlight') returns 1 and g:falcon_inactive is equal 1 (and g:falcon_background is 0);

I've imported the falcon theme into iTerm as mentioned in the Wiki. The Tmux Panes seem ok.

fenetikm commented 6 years ago

Oh, that was the other thing, need to be on a recent version of NeoVim (note to self). I am on v0.3.1.

filipekiss commented 6 years ago

I'm guessing my colors might be a bit off. Comparing my screenshot to the one on the README, I've noticed the current active tmux window should be orange and mine is grey (on TMUX, that is):

Mine README
image image

My NeoVim is v0.3.2:

Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20180822-82772-1ggjmf4/build/config -I/tmp/neovim-20180822-82772-1ggjmf4/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim-20180822-82772-1ggjmf4/build/src/nvim/auto -I/tmp/neovim-20180822-82772-1ggjmf4/build/include
Compiled by filipekiss@urbosa

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-012cd35/share/nvim"

Run :checkhealth for more info
fenetikm commented 6 years ago

hah, sorry, screenshot is slightly behind - I have gone back to grey.

fenetikm commented 6 years ago

in my tmux conf I currently have this:

source-file ~/Documents/Work/internal/vim/colors/falcon/tmux/falcon.tmux.conf

# the following is falcon colour specific
set -g status-left "#[fg=white] #S #[fg=#57575e]│ "
set -g status-right "#(~/.config/tmux/itunes_current_track.zsh) #[fg=#57575e]│ #(~/.config/tmux/tw_status.sh) #[fg=#57575e]│ #[fg=white]%d/%m/%Y %H:%M "
set -g status-right-length 200
fenetikm commented 6 years ago

So I am importing the falcon one then overwriting the status a bit since I have a script to show the itunes track and a taskwarrior script.

filipekiss commented 6 years ago

Yeah, I'm starting to guess it's more a NeoVim issue than a Falcon one.

Can you confirm something for me? Open a Tmux window, split it in two and open an empty Buffer on NeoVim and then focus the other pane. Does NeoVim change the bg color to the Inactive one?

fenetikm commented 6 years ago

Yeah, it works perfectly for me.

The key to the way it works is that NeoVim should only set the background for inactive buffers and leave the background unset otherwise, thus taking it's colour from Tmux which will be either the Tmux inactive colour or the Tmux active colour.

It used to be that there was no background set anywhere in falcon, however, I noted that had some issues in certain places so now, the background is set for Normal and NonText but is then unset via the plugin/falcon.vim file which looks at the settings.

So the tests I would run, would be:

fenetikm commented 6 years ago

I remember I had some interesting issues at one stage due to iTerm2 background being wrong (I have sinced moved away from iTerm2 for performance reasons).

fenetikm commented 6 years ago

Actually I have this in my config:

"turn off the cursorline when not in a window
autocmd InsertLeave,WinEnter * set cursorline
autocmd InsertEnter,WinLeave * set nocursorline
fenetikm commented 6 years ago

maybe that is forcing an extra redraw?

fenetikm commented 6 years ago

And also this for reloading files, probably not relevant:

" Reload when gaining focus
autocmd FocusGained,BufEnter * :silent! !
filipekiss commented 6 years ago

So, here's the deal:

Opened nvim outside tmux, just iTerm and split in 3 (Active Pane is bottom-right):

image

Then, I manually ran hi ActiveWindow guibg=NONE | hi InactiveWindow guibg=#151521 and it becomes like this (Active Pane is bottom-right):

image

Better, but if the bottom-right pane is the inactive one, only the first line stays inactive (Active Pane is top):

image

Same thing if I ran this inside tmux

filipekiss commented 6 years ago

Also I should note that I copied the autocmds you suggested before trying this, so they're definetely not the responsibles for doing this

fenetikm commented 6 years ago

can you possibly post a link to your nvim config?

fenetikm commented 6 years ago

it looks like to me that the falcon plugin (vs the colorscheme) isn't doing it's thing

fenetikm commented 6 years ago

essentially this code:

" NeoVim has support for changing background colour depending on active or not
if !exists('g:falcon_inactive')
  let g:falcon_inactive = 0
endif

if exists('+winhighlight') && g:falcon_inactive == 1
  hi ActiveWindow guibg=NONE | hi InactiveWindow guibg=#151521
  set winhighlight=Normal:ActiveWindow,NormalNC:InactiveWindow
endif

" Put in a background colour for gui
if !exists('g:falcon_background')
  let g:falcon_background = 1
endif

if !has("gui_running") || g:falcon_background == 0
  hi NonText guifg=#36363a ctermfg=237 guibg=NONE ctermbg=NONE gui=NONE cterm=NONE
  hi Normal guifg=#b4b4b9 ctermfg=249 guibg=NONE ctermbg=NONE gui=NONE cterm=NONE
endif
filipekiss commented 6 years ago

My vim config is kinda huge. I've disabled all plugins to see if something was conflicting but still no luck. I'm loading it via vim-plug. I'll try to run the plugin code manually and see if it works, hang on.

fenetikm commented 6 years ago

thanks

fenetikm commented 6 years ago

I am using plug, but I am just including it ala:

Plug '~/Documents/Work/internal/vim/colors/falcon'
filipekiss commented 6 years ago

I've put just this on my .vimrc:

set termguicolors
hi ActiveWindow guibg=NONE | hi InactiveWindow guibg=#151521    

and of course it works!. It's surely something I'm not setting up properly. Time to dive down the rabbit hole and try to find it!

Thank you for you help @fenetikm! As soon as I find out what's causing this I'll post a comment!

fenetikm commented 6 years ago

Great - progress!

If you look in the falcon repo, you will see that there is plugin/falcon.vim - my suggestion would be to check if that is being called and when. Also what the values are of the global variables, especially if it is hitting that line that you have just manually added in. Maybe pepper the code with echom statements or what have you.

Would be great if you can post back here and so I can write up a separate wiki page on getting this all working.

filipekiss commented 6 years ago

So, a few things I've picked up (and I wasn't really able to determine the issue yet):

I'll try to run the colorscheme command somewhere else and see if it's the loading order that's causing this.

Ran :scriptnames and the plugin/falcon.vim is being loaded way before the color.vim and the color scheme itself

filipekiss commented 6 years ago

So I've managed to get it working by making the background check run at VimEnter:

diff --git i/plugin/falcon.vim w/plugin/falcon.vim
index d128335..fda9487 100644
--- i/plugin/falcon.vim
+++ w/plugin/falcon.vim
@@ -1,3 +1,8 @@
+if exists('g:loaded_falcon')
+  finish
+endif
+let g:loaded_falcon=1
+
 " required as colors will come from terminal without
 let g:fzf_colors =
 \ { 'fg':      ['fg', 'Comment'],
@@ -29,11 +34,16 @@ if !exists('g:falcon_background')
   let g:falcon_background = 1
 endif

-if !has("gui_running") || g:falcon_background == 0
+function! s:setColors(...)
   hi NonText guifg=#36363a ctermfg=237 guibg=NONE ctermbg=NONE gui=NONE cterm=NONE
   hi Normal guifg=#b4b4b9 ctermfg=249 guibg=NONE ctermbg=NONE gui=NONE cterm=NONE
+endfunction
+
+if !has("gui_running") || g:falcon_background == 0
+    autocmd VimEnter,FocusGained * call s:setColors()
 endif

+
 " NeoVim terminal colors
 if has ("nvim")
   let g:terminal_color_0 = '#000004'

This makes everything working as expected inside TMUX, but still not working outside TMUX. I'll let you know if I find anything else.

fenetikm commented 6 years ago

hrm, what is currently in your color.vim file?

I just made a minimal .vimrc:

set nocompatible " disable compatibility with vi
syntax enable "enable syntax highlighting

" Assumes vim-plug is installed.
call plug#begin()
Plug 'fenetikm/falcon'
call plug#end()

"enable 24bit support.
set termguicolors

" enables the active / inactive functionality.
let g:falcon_background = 0
let g:falcon_inactive = 1

colorscheme falcon

... and everything works fine. It's sounding like something clobbering the falcon plugin code... and so expected behaviour of sorts.

filipekiss commented 6 years ago

My color.vim has only this:

if has('termguicolors')
    set termguicolors
end

try
    colorscheme falcon
catch
    colorscheme ron
endtry

So here's the thing: In tmux it works fine but outside tmux it does not. My understanding is that TMUX is able to set the inactive pane BG to a certain color (and when the vim pane has it's BG set to NONE you see that color) whereas iTerm isn't able to do that. I really don't care about this since I never work outside TMUX but I'd be happy to continue debugging if you think it's worth.

fenetikm commented 6 years ago

Oh when you say it doesn't work outside of Tmux in iTerm - are you referring to iTerm splits? If that's the case then yeah, that isn't supported AFAIK.

I'll try modifying my falcon plugin to use an autocmd approach like you have above and then hopefully we can call it day ;)

filipekiss commented 6 years ago

No, I actually mean vim splits:

image

I'm guessing the command sare depending on it being loaded on a specific order. I've tried the vim syntax test and the groups for ActiveWindow and InactiveWindow were not being set properly withouth the autocmd (Just to be clear: If I make autocmd for both color setting options we have in the plugin, it works flawlessly).

If you wish I can open a pull-request with the autocmd patch :)

Thank you so much for your patience!

fenetikm commented 6 years ago

Ok, cool, thanks for the clarification.

All good re the PR - no need to bother.

I want to see it with my own eyes first ;)

fenetikm commented 6 years ago

Ok, develop branch now has the autocmd version. Also added in your guard statement which is always a good idea. I removed FocusGained - felt that might be a bit much.

Let me know what you think.

filipekiss commented 6 years ago

develop is hella fine! Working perfectly! Thank you. 🙏

fenetikm commented 6 years ago

phew - thanks for helping make falcon better 👍