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

--no-clear option does not have desired effect; cannot scroll after exiting; mouse scroll wheel ineffective #2978

Closed
5 of 10 tasks
ElectricRCAircraftGuy opened this issue Sep 21, 2022 · 6 comments

Comments

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Sep 21, 2022

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf; fzf --version shows 0.33.0 (e03ac31)
  • I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

Steps

Run fzf with the --no-clear option. Ex:

# search everything, including file names *and* contents
rg --hidden -L --color always -n '' | fzf --ansi --no-clear

Press Ctrl + C to exit fzf.

Actual behavior:

You'll see the content that was being viewed in fzf, but you can no longer scroll up or down in the terminal!--neither with your mouse scroll wheel nor with the PageUp and PageDown keys.

Expected behavior:

The content that was being viewed in fzf should still be visible when you exit fzf with the --no-clear option, and you should still be able to scroll up and down with your mouse scroll wheel and with the PageUp and PageDown keys, just the same as though you had run git log or less -RFX some_filename and then exited! (After running git log or less -X some_filename and exiting, you can still see the output that was on the screen and you can still scroll).

@ElectricRCAircraftGuy
Copy link
Author

Work-around attempts

1. Run tput rmcup at the end

I see in man fzf the following:

--no-clear

Do not clear finder interface on exit. If fzf was started in full screen mode, it will not switch back to the original screen, so you'll have to manually run tput rmcup to return. This
option can be used to avoid flickering of the screen when your application needs to start fzf multiple times in order.

I tried running tput rmcup, and it clears the screen. That's obviously not what I want. I want the screen to not be cleared, hence the --no-clear option in the first place.

2. Add the --height=100 option

I also tried adding the --height=100 option, and it produces very different behavior, but still not the right behavior!

Ex:

# search everything, including file names *and* contents
rg --hidden -L --color always -n '' | fzf --ansi --no-clear --height=100

Now when I quit, I still cannot scroll, and the prompt remains at the top of the screen, overwriting the text beneath it as though you were writing terminal commands and output on top of the remaining fzf screen output. It clutters the screen and appears buggy as well.

3. Type reset to reset the terminal

This gets my scrolling back, but obviously also clears the terminal and wipes away the fzf output, which I don't want--again--the whole point of the --no-clear option is to not clear the fzf screen output.

@junegunn
Copy link
Owner

Unfortunately, --no-clear is probably not what you're looking for. The option was added to address a very specific use case where the user wants to restart fzf on every keystroke to reload the input list while avoiding the constant flicking of the screen due to the restarts. You can read more about it here: #974. The strange behavior you see is exactly what we need for that use case.

query=initial
while true; do
  query=$(echo "$query" | fzf --sync --bind change:accept --print-query --query "$query" --no-clear | head -1)
  [[ -z $query ]] && break
done; tput rmcup

However, since the introduction of the reload action (#1750), the option has lost its raison d'etre. I'm going to remove --no-clear from the documentation not to confuse the users.

# Much simpler and easier to use
query=initial
echo "$query" | fzf --bind 'change:reload:echo {q}' --print-query --query "$query" --disabled

@ElectricRCAircraftGuy
Copy link
Author

Thanks for replying. Do you have a solution then that would meet my need, or would that be a new feature request?

@ElectricRCAircraftGuy
Copy link
Author

Note also that I'd love a clean rg solution like you have here: https://github.com/junegunn/fzf/blob/master/ADVANCED.md#switching-between-ripgrep-mode-and-fzf-mode, except which searches the filename as well, and allows toggling searching the filename as well via Ctrl + N.

@junegunn
Copy link
Owner

It's going to be a new feature, but I'm unlikely to add it. Because 1. it's for niche use cases, 2. and fzf opens in two different modes depending on the value of --height and it's non-trivial to provide consistent UX.

You can limit the scope of search using --nth, but you can't dynamically change it during runtime because fzf is highly optimized for a specific nth value. You'll have to restart fzf with a different set of options in your script (check out --expect)

@arozbiz
Copy link

arozbiz commented May 29, 2023

I came across this issue while trying to write a python script that used fzf twice in a row to gather different user input (basically I'm trying to replace all my rofi-based scripts with fzf-based scripts because I don't want to rely on a gui). It turns out that adding --no-clear to the first fzf call was exactly what I needed in order to avoid the flicker between the two calls. So I just wanted to flag that it might be worth putting information on --no-clear back into the documentation.

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

No branches or pull requests

3 participants