Closed ElectricRCAircraftGuy closed 2 years ago
tput rmcup
at the endI 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.
--height=100
optionI 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.
reset
to reset the terminalThis 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.
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: https://github.com/junegunn/fzf/issues/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 (https://github.com/junegunn/fzf/issues/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
Thanks for replying. Do you have a solution then that would meet my need, or would that be a new feature request?
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.
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
)
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.
man fzf
)fzf --version
shows0.33.0 (e03ac31)
Info
Problem / Steps to reproduce
Steps
Run
fzf
with the--no-clear
option. Ex: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 rungit log
orless -RFX some_filename
and then exited! (After runninggit log
orless -X some_filename
and exiting, you can still see the output that was on the screen and you can still scroll).