fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Introduce '--keep-ansi' option to keep ANSI codes on output

Open 7ocb opened this issue 4 years ago • 12 comments

This improves filtering mode by allowing cases when colors needed to be passed from input to output in filtering mode.

7ocb avatar Dec 24 '21 11:12 7ocb

@7ocb no plan to fix?

blcham avatar May 21 '22 14:05 blcham

@blcham I initially intended to but had no time. I just did another attempt now and to be honest I'm not sure how to approach this.

The tests on CI failing:

  2) Failure:
TestGoFZF#test_kill_default_command_on_accept [test/test_go.rb:1960]:
Expected: "Started"
  Actual: ""

171 runs, 1425 assertions, 1 failures, 0 errors, 1 skips

but this test succeeds for me locally (here I commented other tests) :

# Running:

TestGoFZF#test_kill_default_command_on_accept = 0.16 s = .

Finished in 0.164830s, 6.0669 runs/s, 30.3343 assertions/s.

1 runs, 5 assertions, 0 failures, 0 errors, 0 skips

also the on CI in "test fzf on linux" this test passes also.

7ocb avatar May 22 '22 12:05 7ocb

@7ocb :heart: thanks for the try, not sure how to fix this either

blcham avatar May 22 '22 12:05 blcham

@blcham also I rebased this PR on top of base/master, so can be used as drop-in replacement of original fzf :smile:

7ocb avatar May 22 '22 12:05 7ocb

Could it be merged into the original repo? @junegunn

WantToLearnJapanese avatar Jun 12 '23 16:06 WantToLearnJapanese

Just rebased this on latest master.

7ocb avatar Aug 25 '23 11:08 7ocb

All checks are green.

7ocb avatar Aug 25 '23 11:08 7ocb

@7ocb

I did following:

git clone https://github.com/7ocb/fzf
cd fzf
git checkout keep-colors-on-ouptut-cleaned 
make
ls --color=auto | ./target/fzf-linux_amd64 --keep-ansi

The last command did not show me any color :(: image

Is it expected behavior?

blcham avatar Sep 28 '23 20:09 blcham

@blcham you need to do

ls --color | fzf --keep-ansi --ansi:

2023-10-01--11-32-41

7ocb avatar Oct 01 '23 08:10 7ocb

@7ocb thanks a lot! it works! However my original issue was not only ls --color, but vimcat :(. I thought it is the same case, so i presented ls --color instead. The following still does not work for me:

vimcat some-file-with-syntax-highlighting | fzf --keep-ansi --ansi

Any idea about that? Is vimcat not using ansi?

blcham avatar Oct 01 '23 20:10 blcham

@blcham likely vimcat detects if it's output goes to terminal or to pipe and it does not include coloring in case if it's output goes to pipe (in same way as ls --color=auto does).

7ocb avatar Oct 02 '23 05:10 7ocb