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

Keep ANSI colors in the input #977

Closed
3 of 15 tasks
balta2ar opened this issue Jul 18, 2017 · 10 comments
Closed
3 of 15 tasks

Keep ANSI colors in the input #977

balta2ar opened this issue Jul 18, 2017 · 10 comments

Comments

@balta2ar
Copy link

  • Category
    • fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

I've tried to use fzf in filter mode as a version of grep in a chain of ag (the silver searcher) and grep commands. Is it possible to keep ANSI codes coming in the input as grep does?

@junegunn
Copy link
Owner

Don't use --ansi option then, fzf will not try to parse ansi codes in the input and print them as they are. Your query may unfortunately match ANSI escape sequences but I don't think it'll matter much in practice, and grep also has the same problem: echo foo | grep --color=always foo | grep --color=always 'Kfoo'. Also note that --ansi option makes the filtering much slower.

@balta2ar
Copy link
Author

Thanks! It was my mistake, actually. I had --ansi in my FZF_DEFAULT_OPTS.

@balta2ar
Copy link
Author

@junegunn Sorry, I'm still confused. Actually, I wanted both: keep colors from the input AND add colored matches found by fzf in the output (this is what grep does). But I can't figure out how to see matches' colors in filtering mode neither with nor without --ansi option. Is it possible?

@junegunn
Copy link
Owner

No fzf doesn't do it, and I currently have no plan to add support for that.

I don't think having --ansi in your default opts is a good idea. It makes fzf slower by several times unnecessarily when it's not needed. The performance difference will be even larger in the next release due to some optimizations that don't apply when the option is used. You won't notice the difference if you just use fzf with a few thousand lines though.

@junegunn
Copy link
Owner

Having said that, there should be some room for improvement.

@balta2ar
Copy link
Author

No fzf doesn't do it, and I currently have no plan to add support for that

From my POV it looks like a useful thing to have. If it's not too complicated to implement, maybe you could add it to your plans?

@junegunn
Copy link
Owner

I'll take note, but as I rarely use filter mode, it's not my priority.

By the way, I just came up with a way to improve performance of --ansi option. It needs more testing, but it looks extremely promising.

perf-ansi

@balta2ar
Copy link
Author

Great news! I've been missing these graphs of yours since your last refactoring :) (I only hope that Y axis starts at zero, otherwise the difference could be anywhere from amazing to negligible).

By the way, it looks like you have some helper code and environment to benchmark the performance and visualize the results. I think it could be helpful to include them somewhere either in the code or wiki so that contributors could have established tools to verify the performance has not degraded after their updates. It's not that there are so many contributors who need that, but still...

@junegunn
Copy link
Owner

Y axis starts at zero. You will definitely notice the difference when this is merged. But even with such significant improvement, fzf with --ansi will be still slower than without it.

I do have a script, but I don't think it's ready for open yet. The performance varies greatly depending on the options used, the content of the input file, selectivity of the query, etc. I'll have to make the test cases thorough and as complete as possible.

@7ocb
Copy link
Contributor

7ocb commented Dec 24, 2021

PR: #2693

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

No branches or pull requests

3 participants