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

cannot preview terminal buffers with bat_native previewer #354

Closed
ViRu-ThE-ViRuS opened this issue Mar 2, 2022 · 10 comments
Closed

cannot preview terminal buffers with bat_native previewer #354

ViRu-ThE-ViRuS opened this issue Mar 2, 2022 · 10 comments
Labels
not planned This will not be worked on

Comments

@ViRu-ThE-ViRuS
Copy link

ViRu-ThE-ViRuS commented Mar 2, 2022

Info

  • Operating System: MacOS 12.0.1
  • Shell: Fish 3.3.1
  • Terminal: Kitty 0.24.2
  • nvim --version: HEAD
  • fzf --version: 0.29.0
fzf-lua configuration
require('fzf-lua').setup({
    winopts = {
        split = 'belowright new',
        fullscreen = false,
        preview = {
            default = 'bat_native',
            horizontal = 'right:50%',
            vertical = 'down:50%',
            layout = 'horizontal'

            -- layout = 'flex',
            -- flip_columns=utils.truncation_limit_s_terminal
        },
        on_create = function()
            vim.opt_local.buflisted = false
            vim.opt_local.bufhidden = 'wipe'
            vim.opt_local.signcolumn = 'no'
            -- vim.opt_local.statusline = require('statusline').StatusLine('FZF')
        end
    },
    keymap = {
        fzf = {
            ['ctrl-a'] = 'select-all',
            ['ctrl-d'] = 'deselect-all',
            ['ctrl-f'] = 'half-page-down',
            ['ctrl-b'] = 'half-page-up'
        }
    },
    fzf_opts = { ['--layout'] = 'default' },
    previewers = {
        bat = {
            cmd = "bat",
            args = "--style=numbers,changes --color always",
            theme = 'Coldark-Dark',
        }
    },
    files = {
        multiprocess = true,
        cmd = 'rg --files --follow --smart-case --hidden --no-ignore -g "!{.DS_Store,.cache,venv,.git,.clangd,.ccls-cache}" 2> /dev/null',
        actions = {
            ['default'] = actions.file_edit,
            ['ctrl-x'] = actions.file_split,
            ['ctrl-v'] = actions.file_vsplit,
            ['ctrl-q'] = require('utils').qf_populate
        }
    },
    git = {
        files = {
            multiprocess = true,
            actions = {
                ['default'] = actions.file_edit,
                ['ctrl-x'] = actions.file_split,
                ['ctrl-v'] = actions.file_vsplit,
                ['ctrl-q'] = require('utils').qf_populate
            }
        }
    },
    buffers = {
        actions = {
            ['default'] = actions.buf_edit,
            ['ctrl-x'] = actions.buf_split,
            ['ctrl-v'] = actions.buf_vsplit,
            ['ctrl-q'] = { actions.buf_del, actions.resume }
        }
    },
    grep = {
        rg_opts = "--hidden --column --line-number --no-heading --color=always --smart-case -g '!{.DS_Store,.cache,venv,.git,.clangd,.ccls-cache}'",
        experimental = false,
        multiprocess = true,
        actions = {
            ['default'] = actions.file_edit,
            ['ctrl-x'] = actions.file_split,
            ['ctrl-v'] = actions.file_vsplit,
            ['ctrl-q'] = require('lib/misc').fzf_to_qf
        }
    },
    lsp = {
        actions = {
            ['default'] = actions.file_edit,
            ['ctrl-x'] = actions.file_split,
            ['ctrl-v'] = actions.file_vsplit,
            ['ctrl-q'] = require('lib/misc').fzf_to_qf
        },
        icons = {
            ['Error'] = { icon = utils.symbol_config.indicator_error, color = 'red' },
            ['Warning'] = { icon = utils.symbol_config.indicator_warning, color = 'yellow' },
            ['Information'] = { icon = utils.symbol_config.indicator_info, color = 'blue' },
            ['Hint'] = { icon = utils.symbol_config.indicator_hint, color = 'magenta' }
        }
    }
})

Description

this is what I see when I try to preview a terminal buffer when using FzfLua Buffers picker:
[bat error] invalid digit found in string

Screen Shot 2022-03-01 at 19 19 39

@ibhagwan
Copy link
Owner

ibhagwan commented Mar 2, 2022

Buffers that do not have a corresponding file on disk cannot be viewed with fzf native previewers (bat, bat_native, cat, etc), when using bat, fzf previewer runs a bat command with the on disk filename, obviously this is not possible with terminal or unnamed buffers.

If you need unnamed and terminal buffer previews change the previewer for buffers to builtin with:

:FzfLua buffers previewer=builtin
-- or:
:lua require'fzf-lua'.buffers({ previewer = 'builtin' })

-- can also be configured in setup:
require'fzf-lua'.setup({
  buffers = { previewer = 'builtin' },
})

@ibhagwan ibhagwan added the not planned This will not be worked on label Mar 2, 2022
@ibhagwan
Copy link
Owner

ibhagwan commented Mar 2, 2022

Btw, looking at your config, you can it make it much more compact now since you can "bulk" configure all files/bufers actions under the global actions map (since #331):

  • also dropped multiprocess = true since it's the default anywhere possible
  • you defined custom arguments for previewer.bat but you're using preview.default=bat_native, I would use preview.default=bat instead
fzf-lua configuration
require('fzf-lua').setup({
    winopts = {
        split = 'belowright new',
        fullscreen = false,
        preview = {
            default = 'bat_native',
            horizontal = 'right:50%',
            vertical = 'down:50%',
            layout = 'horizontal'

            -- layout = 'flex',
            -- flip_columns=utils.truncation_limit_s_terminal
        },
        on_create = function()
            vim.opt_local.buflisted = false
            vim.opt_local.bufhidden = 'wipe'
            vim.opt_local.signcolumn = 'no'
            -- vim.opt_local.statusline = require('statusline').StatusLine('FZF')
        end
    },
    keymap = {
        fzf = {
            ['ctrl-a'] = 'select-all',
            ['ctrl-d'] = 'deselect-all',
            ['ctrl-f'] = 'half-page-down',
            ['ctrl-b'] = 'half-page-up'
        }
    },
    actions = {
      files = {
        ["default"]       = actions.file_edit,
        ["ctrl-x"]        = actions.file_split,
        ["ctrl-v"]        = actions.file_vsplit,
        ["ctrl-t"]        = actions.file_tabedit,
        ['ctrl-q']        = require('utils').qf_populate
      },
      buffers = {
        ["default"]       = actions.buf_edit,
        ["ctrl-x"]        = actions.buf_split,
        ["ctrl-v"]        = actions.buf_vsplit,
        ["ctrl-t"]        = actions.buf_tabedit,
      }
    },
    fzf_opts = { ['--layout'] = 'default' },
    previewers = {
        bat = {
            cmd = "bat",
            args = "--style=numbers,changes --color always",
            theme = 'Coldark-Dark',
        }
    },
    files = {
        cmd = 'rg --files --follow --smart-case --hidden --no-ignore -g "!{.DS_Store,.cache,venv,.git,.clangd,.ccls-cache}" 2> /dev/null',
    },
    buffers = {
        actions = { ['ctrl-q'] = { actions.buf_del, actions.resume } }
    },
    grep = {
        rg_opts = "--hidden --column --line-number --no-heading --color=always --smart-case -g '!{.DS_Store,.cache,venv,.git,.clangd,.ccls-cache}'",
        actions = { ['ctrl-q'] = require('lib/misc').fzf_to_qf }
    },
    lsp = {
        actions = { ['ctrl-q'] = require('lib/misc').fzf_to_qf },
        icons = {
            ['Error'] = { icon = utils.symbol_config.indicator_error, color = 'red' },
            ['Warning'] = { icon = utils.symbol_config.indicator_warning, color = 'yellow' },
            ['Information'] = { icon = utils.symbol_config.indicator_info, color = 'blue' },
            ['Hint'] = { icon = utils.symbol_config.indicator_hint, color = 'magenta' }
        }
    }
})

@ViRu-ThE-ViRuS
Copy link
Author

aah I see, thanks for the tips! I will just remap the buffers keymap to use the built in previewer for now!

@ViRu-ThE-ViRuS
Copy link
Author

Screen Shot 2022-03-03 at 15 44 44

I see two different border lines for the preview for :lua require('fzf-lua').buffers({previewer = 'builtin'}). can this be fixed somehow?

@ibhagwan
Copy link
Owner

ibhagwan commented Mar 4, 2022

I see two different border lines for the preview for :lua require('fzf-lua').buffers({previewer = 'builtin'}). can this be fixed somehow?

That's because when using split the builtin preview is supposed to render on top of the fzf preview window, although the fzf window isn't needed for the preview, it's needed for the layout so string don't just get cut but behave as if fzf has it's own preview, I wasn't able to get the exact calcuation of width fzf uses so sometimes the width (or height if vertical) will not be perfectly aligned with fzf preview window.

You can play with different numbers for the size (try horizontal=right:<48%-52%>) and see if it will align better?

What is your :lua print(vim.o.columns)?

@ViRu-ThE-ViRuS
Copy link
Author

What is your :lua print(vim.o.columns)?
that is 100 for me

changing the size didn't help the alignment much, so ill just continue using the bat preview, I rarely need to see what the terminal contents are as I am usually using only one terminal buffer frequently, which is mapped to toggle.

thanks for ur help tho :)

@ibhagwan
Copy link
Owner

ibhagwan commented Mar 5, 2022

When I have more time I’ll take another crack at it and see if I can match the Fzf border width code 1-to-1.

@ibhagwan
Copy link
Owner

f996eb2

Good news I was able to solve it, the misalighment happened due to the on_create function in your setup setting signcolumn=no', this was adding available with for fzf` causing the misalignment.

You can now use the builtin previewer and the borders should align properly (i.e. a single border will be displayed).

@ViRu-ThE-ViRuS
Copy link
Author

yup, this works. Thanks for the amazing work as always, @ibhagwan :)

@ibhagwan
Copy link
Owner

yup, this works. Thanks for the amazing work as always, @ibhagwan :)

Ty <3

Btw, since f0ef0d0 you no longer needs to set signcolumn='no' at on_create since it’s now the default for splits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not planned This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants