ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.37k stars 151 forks source link

Bug: disable `--ansi` in fzf prints escape chars related to colors? #1482

Closed Masber closed 1 month ago

Masber commented 1 month ago

RTFM Checklist

Operating system

Linus Ubuntu 24.04.1

Shell

bash

Neovim version (nvim --version)

NVIM v0.10.1

Fzf version (fzf --version)

0.55.0 (fc69308)

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

Fzf-lua configuration

{ -- FZF Lua
    'ibhagwan/fzf-lua',
    -- optional for icon support
    dependencies = { 'nvim-tree/nvim-web-devicons' },
    config = function()
      -- local actions = require 'fzf-lua.actions'

      -- calling `setup` is optional for customization
      require('fzf-lua').setup {
        fzf_opts = { ['--ansi'] = false, ['--border'] = 'rounded' }, -- Disable fzf --ansi coloring for better performance https://github.com/ibhagwan/fzf-lua/wiki#how-do-i-get-maximum-performance-out-of-fzf-lua
        defaults = {
          file_icons = false, -- better performance https://github.com/ibhagwan/fzf-lua/wiki#how-do-i-get-maximum-performance-out-of-fzf-lua
          color_icons = false,
          git_icons = false, -- better performance https://github.com/ibhagwan/fzf-lua/wiki#how-do-i-get-maximum-performance-out-of-fzf-lua
          icon_padding = false,
          -- debug = true,
        },
        winopts = {
          height = 0.25,
          width = 1,
          row = 1,
          -- split = 'belowright new',
          -- border = { '', '─', '', '', '', '', '', '' },
          border = 'none',
          backdrop = 100, -- background opacity
          preview = {
            default = 'bat_native', -- using `bat_vative` in preview for better performance https://github.com/ibhagwan/fzf-lua/wiki#how-do-i-get-maximum-performance-out-of-fzf-lua
            hidden = 'hidden',
            wrap = 'wrap',
            layout = 'horizontal',
          },
        },
        files = {
          -- prompt = 'Files❯ ',
          cwd_prompt = false,
          multiprocess = true, -- run command in a separate process
          -- formatter = 'path.filename_first',
          fd_opts = ' --type f --no-ignore --hidden ', -- if `fd` is installed, then fzf-lua will use it instead of `find` see https://github.com/ibhagwan/fzf-lua/discussions/1475#discussioncomment-10852903
        },
        -- CUSTOMIATION - 06/10/2024 - keep it simple... try to use vim/neovim low level capabilities to make the app more responsive
        -- code_actions = {
        --   prompt = 'Code Actions> ',
        --   async_or_timeout = 5000,
        --   -- when git-delta is installed use "codeaction_native" for beautiful diffs
        --   -- try it out with `:FzfLua lsp_code_actions previewer=codeaction_native`
        --   -- scroll up to `previewers.codeaction{_native}` for more previewer options
        --   previewer = 'codeaction',
        -- },
      }
      -- vim.keymap.set('n', '<leader>sd', require('fzf-lua').git_files, { desc = 'Search in Documents (polybox)' })
      vim.keymap.set('n', '<leader>sf', require('fzf-lua').git_files, { desc = 'Search Git files in project' })
      vim.keymap.set('n', '<leader>sg', require('fzf-lua').grep_project, { desc = 'Search Grep in project' })
      vim.keymap.set('n', '<leader>sa', require('fzf-lua').files, { desc = 'Search All files in project' })
      vim.keymap.set('n', '<leader>sD', function()
        require('fzf-lua').files { cmd = 'fd "/home/msopena/polybox/Documents/"' }
      end, { desc = 'Search All files in project' })
      vim.keymap.set('n', '<leader>sd', require('fzf-lua').diagnostics_workspace, { desc = 'Search Diagnostics' })

      vim.keymap.set('n', '<leader>gr', function()
        require('fzf-lua').lsp_references { jump_to_single_resuilt = true, includeDeclaration = false, ignore_current_line = true }
      end, { desc = 'Go to References' })
      vim.keymap.set('n', '<leader>gd', function()
        require('fzf-lua').lsp_definitions { jump_to_single_result = true }
      end, { desc = 'Go to Definitions' })
      vim.keymap.set('n', '<leader>gD', function()
        require('fzf-lua').lsp_declarations { jump_to_single_result = true }
      end, { desc = 'Go to Declarations' })
      vim.keymap.set('n', '<leader>gi', function()
        require('fzf-lua').lsp_implementations { jump_to_single_result = true }
      end, { desc = 'Go to Implementations' })
      vim.keymap.set('n', '<leader>gt', function()
        require('fzf-lua').lsp_typedefs { jump_to_single_result = true }
      end, { desc = 'Go to Type Definitions' })
      vim.keymap.set('n', '<leader>gf', require('fzf-lua').lsp_finder, { desc = 'Go to Finder (find all)' })
      -- CUSTOMIATION - 06/10/2024 - keep it simple... try to use vim/neovim low level capabilities to make the app more responsive
      -- vim.keymap.set('n', '<leader>ca', require('fzf-lua').lsp_code_actions, { desc = 'Code Actions' })
    end,
  },

Describe the bug / steps to reproduce

I have disabled ansi in fzf because I don't mind about colors and I prioritize responsiveness. However I realized, the escape chars for colors are not escaped making difficult to understand the fzf results (see screenshot below)

image

ibhagwan commented 1 month ago

The performance gains by --ansi are because fzf will not try to detect ansi escape codes and display colors, but this isn't a bug, if you're using --ansi also make sure the ripgrep results never use colors by using a custom grep.cmd or grep.rg_opts (see the default command in the README and add --color=never).

ibhagwan commented 1 month ago

You can add debug=true to see the underlying command to see if you did it right (see the first DEBUG line): image

ibhagwan commented 1 month ago

https://github.com/ibhagwan/fzf-lua/commit/1e03541de4d8a169defe83bb4d7abfba450c63a1

@Masber, I added --ansi to grep in the max-perf profile, you can now use:

require("fzf-lua").setup({ "max-perf" })
-- Or if you prefer window titles instead of prompt titles
require("fzf-lua").setup({ { "default-title", "max-perf" } })
Masber commented 1 month ago

why not fzf_opts = { ['--ansi'] = false }, under root?

ibhagwan commented 1 month ago

why not fzf_opts = { ['--ansi'] = false }, under root?

I haven’t tested all the pickers with it, some other pickers like lsp still have colors, I’d welcome a PR for it if you test the pickers and set the appropriate hls.xxx to false.

abenz1267 commented 1 month ago

I'm not entirely sure if it's related, but when i use path.filename_first as a formatter for grep i get this still:

image

ibhagwan commented 1 month ago

I'm not entirely sure if it's related, but when i use path.filename_first as a formatter for grep i get this still:

image

Yes, 100% related that’s the ansi escape sequence for the highlight FzfLuaDirPart, unlink it or set hls.dir_part = false to remove the escape sequence.