junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.89k stars 2.37k forks source link

fzf erases scrollback buffer on Windows #1766

Open wjrogers opened 4 years ago

wjrogers commented 4 years ago

Info

Problem / Steps to reproduce

  1. Open a new Command Prompt
  2. Generate some terminal buffer content with e.g. dir or tree
  3. Run fzf
  4. Hit ESC to exit
  5. Observe the terminal buffer has been erased and the scrollback cleared

Interestingly, in the new Windows Terminal, the problem is less severe: only the visible lines in the terminal are erased when running fzf. Anything in the scrollback buffer is still there afterward.

LuRsT commented 4 years ago

Hi @wjrogers, if you set the --height option, you can make fzf smaller, which should at least erase fewer lines. Also, if you use the option --reverse, it opens below the prompt, which may completely solve your issue.

wjrogers commented 4 years ago

@LuRsT I am using --reverse, and passing --height gives the message "--height option is currently not supported on Windows"

KindDragon commented 4 years ago

@wjrogers PR #1341 should fix this

wjrogers commented 3 years ago

I just tested in 0.24.1, and this bug is not fixed. Will you please re-open? (@KindDragon's comment was referring to the --height option, which is now supported on Windows.)

junegunn commented 3 years ago

So this problem only happens when you don't use --height option?

wjrogers commented 3 years ago

Correct. Using --height works around it because it scrolls the terminal far enough for the fzf "window" to fit below the prompt.

junegunn commented 3 years ago

Can you test if this binary helps in your case? I don't have a Windows environment to test it now.

It just makes fzf use the new renderer instead of tcell library when it's available.

diff --git a/src/terminal.go b/src/terminal.go
index 778665a..8697d21 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -408,11 +408,11 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
    var renderer tui.Renderer
    fullscreen := opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100
    if fullscreen {
-       if tui.HasFullscreenRenderer() {
-           renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
-       } else {
+       if tui.IsLightRendererSupported() {
            renderer = tui.NewLightRenderer(opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit,
                true, func(h int) int { return h })
+       } else {
+           renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
        }
    } else {
        maxHeightFunc := func(termHeight int) int {
wjrogers commented 3 years ago

Yes, that binary completely fixes the bug! Tested both Command Prompt and Windows Terminal. Windows 20H2 (19042.610).

junegunn commented 3 years ago

Thanks for the confirmation. Patch pushed to master. Please report any issues you run into.

/cc @kelleyma49

junegunn commented 3 years ago

I had to revert the commit as it doesn't work correctly inside Vim.

https://github.com/junegunn/fzf.vim/issues/1152#issuecomment-719696495

vovcacik commented 2 years ago

The tcell library used in FullscreenRenderer is clipping the console's buffer to the size of console's window during initialization (and few more occasions). There was an effort to preserve the buffer and restore it on exit gdamore/tcell#288.

You could also switch to LightRenderer with fzf --height=99%.