b0o / incline.nvim

🎈 Floating statuslines for Neovim, winbar alternative
MIT License
759 stars 14 forks source link

[BUG] How To Work with Goyo? #30

Closed TheCedarPrince closed 1 year ago

TheCedarPrince commented 1 year ago

Hi @b0o ,

There is a small issue that I notice when I use this with the great plugin Goyo.vim. Currently, here is how my incline looks: image

As you can see, the incline bar is in the top right of each window with its background color matched to my colorscheme. Then I activate Goyo:

image

Incline disappears as expected which is cool! Then when I quit Goyo:

image

The window background color gets cleared and resets to what are incline's defaults.

How should I restore my configuration for incline after quitting Goyo?

Here is my Incline configuration:

require('incline').setup {
    debounce_threshold = {
        falling = 50,
        rising = 10
    },
    hide = {
        cursorline = false,
        focused_win = false,
        only_win = true -- Hide incline if only one window in tab
    },
    highlight = {
        groups = {
            InclineNormal = {
                default = true,
                group = "NormalFloat"
            },
            InclineNormalNC = {
                default = true,
                group = "NormalFloat"
            }
        }
    },
    ignore = {
        buftypes = "special",
        filetypes = {},
        floating_wins = true,
        unlisted_buffers = true,
        wintypes = "special"
    },
    render = function(props)
        local fname = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ':t')
        local colors = require('gruvbox.palette')

        if props.focused == true then
            return {
                {
                    fname,
                    guibg = colors.dark0_hard,
                    guifg = colors.light1
                }
            }
        else
            return {
                {
                    fname,
                    guibg = colors.dark0_hard,
                    guifg = colors.dark4
                }
            }
        end
    end,
    window = {
        margin = {
            horizontal = 1,
            vertical = 2
        },
        options = {
            signcolumn = "no",
            wrap = false
        },
        padding = 0,
        padding_char = " ",
        placement = {
            horizontal = "right",
            vertical = "top"
        },
        width = "fit",
        winhighlight = {
            active = {
                EndOfBuffer = "None",
                Normal = "InclineNormal",
                Search = "None"
            },
            inactive = {
                EndOfBuffer = "None",
                Normal = "InclineNormalNC",
                Search = "None"
            }
        },
        zindex = 50
    }
}

And here is my configuration for Goyo:

vim.g.goyo_width = '85%' -- Default width
vim.g.goyo_height = '90%' -- Default height

vim.cmd [[
function! s:goyo_enter()
  " Hides mode from showing
  set noshowmode 

  " Hides the sign column
  :set scl=no 

  " Hides lualine
  lua require"lualine".hide() 

  " ...
endfunction
function! s:goyo_leave()
  " Resets syntax highlighting (workaround for goyo bug)
  syntax off 
  syntax on 

  " Makes the signcolumn match the background colorscheme
  highlight clear SignColumn

  " Brings mode back
  set showmode 

  " Shows lualine again
  lua require"lualine".hide({unhide=true})

  " ...
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
]]

Thanks!

b0o commented 1 year ago

Interesting, thanks for the report. I am indeed able to reproduce this issue. I'll have a look into what's causing this.

TheCedarPrince commented 1 year ago

@b0o - thank you! And of course, this really isn't a bug with your plugin but more so just a compatibility issue with Goyo. Thanks for being willing to give this a shot! :smile:

b0o commented 1 year ago

So far, what I've discovered is that Goyo seems to clear certain highlight groups after it's disabled.

My incline highlight groups before running Goyo:

InclineNormal                     links to NormalFloat
InclineNormalNC                   links to NormalFloat
incline__guifg_b4a7de             guifg=#b4a7de
incline__guifg_white              guifg=White
incline__guibg_none__guifg_b4a7de guifg=#b4a7de
incline__gui_bolditalic           gui=bold,italic
incline__guibg_none__guifg_white  guifg=White
incline__guifg_51a0cf             guifg=#51a0cf

My incline highlight groups after toggling Goyo on and then off:

InclineNormal                     links to NormalFloat
InclineNormalNC                   links to NormalFloat
incline__guifg_b4a7de             cleared
incline__guifg_white              cleared
incline__guibg_none__guifg_b4a7de cleared
incline__gui_bolditalic           cleared
incline__guibg_none__guifg_white  cleared
incline__guifg_51a0cf             cleared

The next steps would be to determine why Goyo is clearing highlight groups it didn't create, and then either figure out how to avoid Goyo doing this, or detecting it and re-creating the highlights afterwards.

b0o commented 1 year ago

@TheCedarPrince For now, adding this line to your goyo_leave function should cause incline to re-create the highlights:

lua require'incline'.setup{}

(calling setup like this won't clear your pre-existing incline configuration)

Can you let me know if this works?

TheCedarPrince commented 1 year ago

Hey @b0o ! This works perfectly and completely restores all my original configurations to incline after exiting Goyo! Super excited as now I can use incline for my workflow completely and without problems. Really love the tool and am excited to keep using it. Thanks b0o -- I will close the issue for now. For those curious, here is my current Goyo configuration:

vim.g.goyo_width = '85%' -- Default width
vim.g.goyo_height = '90%' -- Default height

vim.cmd [[
function! s:goyo_enter()
  " Hides mode from showing
  set noshowmode 

  " Hides the sign column
  :set scl=no 

  " Hides lualine
  lua require"lualine".hide() 

  " ...
endfunction
function! s:goyo_leave()
  " Resets syntax highlighting (workaround for goyo bug)
  syntax off 
  syntax on 

  " Makes the signcolumn match the background colorscheme
  highlight clear SignColumn

  " Brings mode back
  set showmode 

  " Shows lualine again
  lua require"lualine".hide({unhide=true})

  " Recreate incline functionality
  lua require'incline'.setup{}

  " ...
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
]]