Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The color did not display well when inactivate the terminal window #2305

Open
xianyinxin opened this issue Dec 13, 2020 · 3 comments
Open

The color did not display well when inactivate the terminal window #2305

xianyinxin opened this issue Dec 13, 2020 · 3 comments

Comments

@xianyinxin
Copy link

xianyinxin commented Dec 13, 2020

I improved the scheme solarized to support the terminal mode by referring to vim-airline/vim-airline-themes#225 and vim-airline/vim-airline-themes#235. After I fixed the issue, all works fine except that when inactivate the terminal window, the "bash name field" show a black line as shown in the actual screenshot below.

After some debug, i found when i commented out the below code, it works well.

function! airline#extensions#term#inactive_apply(...) abort
  if getbufvar(a:2.bufnr, '&buftype') ==? 'terminal'
    call a:1.add_section_spaced('airline_a', s:section_a)
    call a:1.add_section_spaced('airline_b', s:neoterm_id(a:2.bufnr))
"    call a:1.add_section('airline_term', s:spc.s:termname(a:2.bufnr))
    call a:1.split()
    call a:1.add_section('airline_y', '')
    call a:1.add_section_spaced('airline_z', s:section_z)
    return 1
  endif
endfunction

Below is my modification for the solarized scheme where i set the "airline_term" the same as "airline_c" in inactive mode(which is not work):

diff --git a/autoload/airline/themes/solarized.vim b/autoload/airline/themes/solarized.vim
index 4f47265..1a30208 100644
--- a/autoload/airline/themes/solarized.vim
+++ b/autoload/airline/themes/solarized.vim
@@ -138,8 +138,10 @@ function! airline#themes#solarized#refresh()
         \ [s:IA[0].g, s:IA[1].g, s:IA[0].t, s:IA[1].t, s:IA[2]],
         \ [s:IA[0].g, s:IA[1].g, s:IA[0].t, s:IA[1].t, s:IA[2]],
         \ [s:IA[0].g, s:IA[1].g, s:IA[0].t, s:IA[1].t, s:IA[2]])
+
   let g:airline#themes#solarized#palette.inactive_modified = {
-        \ 'airline_c': [s:NMi[0].g, '', s:NMi[0].t, '', s:NMi[2]]}
+        \ 'airline_c': [s:NMi[0].g, '', s:NMi[0].t, '', s:NMi[2]],
+        \ 'airline_term': [s:NMi[0].g, '', s:NMi[0].t, '', s:NMi[2]]}

   let g:airline#themes#solarized#palette.normal = airline#themes#generate_color_map(
         \ [s:N1[0].g, s:N1[1].g, s:N1[0].t, s:N1[1].t, s:N1[2]],
@@ -174,6 +176,21 @@ function! airline#themes#solarized#refresh()
   let g:airline#themes#solarized#palette.insert_modified.airline_warning =
         \ g:airline#themes#solarized#palette.normal.airline_warning

+  let g:airline#themes#solarized#palette.terminal = airline#themes#generate_color_map(
+        \ [s:I1[0].g, s:I1[1].g, s:I1[0].t, s:I1[1].t, s:I1[2]],
+        \ [s:I2[0].g, s:I2[1].g, s:I2[0].t, s:I2[1].t, s:I2[2]],
+        \ [s:I3[0].g, s:I3[1].g, s:I3[0].t, s:I3[1].t, s:I3[2]])
+
+  let g:airline#themes#solarized#palette.terminal.airline_warning =
+        \ g:airline#themes#solarized#palette.normal.airline_warning
+
+  let g:airline#themes#solarized#palette.terminal_modified = {
+        \ 'airline_term': [s:IM[0].g, s:IM[1].g,
+        \ s:IM[0].t, s:IM[1].t, s:IM[2]]}
+
+  let g:airline#themes#solarized#palette.terminal_modified.airline_warning =
+        \ g:airline#themes#solarized#palette.normal.airline_warning
+
   let g:airline#themes#solarized#palette.visual = airline#themes#generate_color_map(
         \ [s:V1[0].g, s:V1[1].g, s:V1[0].t, s:V1[1].t, s:V1[2]],
         \ [s:V2[0].g, s:V2[1].g, s:V2[0].t, s:V2[1].t, s:V2[2]],

I'm newbie to the vimscript, so i don't know what's the root cause.

cc @kmoschcau

environment

  • vim: 8.2
  • vim-airline: 0.11
  • OS: macOS Big Sur
  • Have you reproduced with a minimal vimrc: no
  • What is your airline configuration:
    if you are using terminal:
  • terminal: iterm2
  • $TERM variable: xterm-256color
  • color configuration (:set t_Co?):
    if you are using Neovim:
  • does it happen in Vim: no

actual behavior

actural

expected behavior

expected

screen shot (if possible)

@kmoschcau
Copy link
Contributor

I am not quite sure what is causing this. It could be that you have the order of overwriting operations wrong or that you are copying a reference to a map somewhere. For reference you can have a look how I set up mine, because that one works: https://github.com/kmoschcau/nvim-config/blob/master/autoload/airline/themes/material.vim

@edujtm
Copy link

edujtm commented Feb 21, 2021

I had a similar problem to yours while using the gruvbox colorscheme and managed to fix it by using the patch described in vim-airline/vim-airline-themes#180, maybe it will help you as well.

@anpgab
Copy link

anpgab commented Nov 24, 2023

TL;DR: The thing with OP's patch is, airline does not use the added terminal_inactive entry of a theme's palette. The entries (modes) that matter are terminal, visual_modified, normal_modified, inactive and inactive_modified. Adding proper airline_term entry to these dictionaries could be a better solution.

Explained:

According to documentation in airline's default theme dark.vim, a vim buffer's mode is one of normal | insert | replace | visual | terminal | inactive. Airline maps these mode names to clusters of highlight groups (which are defined as items in dictionary palette), and applies corresponding set of colors in different buffer(window) modes.

For a vim terminal window, when the job running inside it receives user's keystrokes, airline recognizes the window as in terminal mode. Once Ctrl-W N is pressed and the window goes to Terminal-Normal mode (:h t_CTRL-W_N), airline treats it as in normal_modified mode - an override/derivative of normal, having its own key in palette. If we begin visual selecting, the terminal window is in visual_modified mode. And finally if the cursor moves to another buffer, the terminal window becomes inactive. There seems no "terminal_modified" mode in airline, so adding such a key in palette does NOT help.

And then comes the "bash name field", corresponding to the code line OP has commented out to make things work. The line sits in a function which "builds" the statusline section by section, and the line itself adds a section displaying the job's name, employing highlight group airline_term. Once commented out, this section is never created, thus not displaying the color defined by airline_term, no matter which mode the window is in. Note as OP's screenshot suggests, the job's name does not get displayed either.

So to fix the green-on-black display, the key is to get airline_term highlight group appropriately defined for every relevant mode in an airline theme's palette. Unfortunately, most airline themes have not yet been updated to cover this feature, which means airline_term's color is usually poorly defined and relies much on some "fallback" mechanism (see vim-airline-themes#224). E.g. the solarized theme has neither airline_term highlight group nor settings for terminal mode, resulting in OP's first screenshot (plus the normal-mode-like looking while one can "inserts" into terminal window).

The vimrc patch in vim-airline/vim-airline-themes#180 does work for most cases, yet on my computer the terminal window's inactive mode still differs from an ordinary buffer, refusing to turn grey...

Another straightforward way, apparently, is to manually add proper airline_term key to relevant modes' dictionaries. For solarized the patch below should make terminal window's statusline behavior almost identical to an ordinary buffer:

function! airline#themes#solarized#refresh()
  ... " Existing code
  " Fix terminal window
  " For 'terminal' mode, derive from 'insert' mode
  let g:airline#themes#solarized#palette.terminal = airline#themes#generate_color_map(
        \ [s:I1[0].g, s:I1[1].g, s:I1[0].t, s:I1[1].t, s:I1[2]],
        \ [s:I2[0].g, s:I2[1].g, s:I2[0].t, s:I2[1].t, s:I2[2]],
        \ [s:I3[0].g, s:I3[1].g, s:I3[0].t, s:I3[1].t, s:I3[2]])
  " Add 'airline_term' highlight group
  "  Treat it as an equivalent of 'airline_c'
  let g:airline#themes#solarized#palette.terminal.airline_term = 
      \ g:airline#themes#solarized#palette.terminal.airline_c
  " 'Terminal-Normal' as 'normal_modified'
  let g:airline#themes#solarized#palette.normal_modified.airline_term = 
      \ g:airline#themes#solarized#palette.normal_modified.airline_c
  " 'Visual' as 'visual_modified'
  let g:airline#themes#solarized#palette.visual_modified.airline_term = 
      \ g:airline#themes#solarized#palette.visual_modified.airline_c
  " 'inactive' is somewhat awkward, involving both 'inactive' & 'inactive_modified'
  let g:airline#themes#solarized#palette.inactive_modified.airline_term =
      \ g:airline#themes#solarized#palette.inactive_modified.airline_c
  let g:airline#themes#solarized#palette.inactive.airline_term =
      \ g:airline#themes#solarized#palette.inactive.airline_c
endfunction

One should be able to fix an arbitrary airline theme's terminal window statusline headache in a similar manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants