Preview window doesn't scroll to the end when combining 'follow' and 'wrap'
- [x] I have read through the manual page (
man fzf) - [x] I have the latest version of fzf
- [x] I have searched through the existing issues
=> Using tip from
master
Info
- OS
- [x] Linux
- [ ] Mac OS X
- [ ] Windows
- [ ] Etc.
- Shell
- [ ] bash
- [ ] zsh
- [ ] fish
- [x] sh
Problem / Steps to reproduce
I want to use the follow option to scroll to the last line and follow the output of my preview script. Also, the preview script has long line, so I want them to be wrapped; I use the wrap option.
Problem: it seems like fzf calculates the scroll first and goes there, then wraps; what I see first is not the last line but some line in the middle.
Here's a reproducer, expecting your screen to be less than 200 chars wide and 200 lines tall:
SHELL=sh fzf --preview-window follow,wrap --preview 'for i in $(seq 200); do echo -n $i; for j in $(seq 200); do echo -n '-'; done; echo $i; done'
Each line is $i---------$i, where i is iterated from 1 to 200, and the --- is 200 chars wide.
What I expect: see the last line wrapped, which means something like
[more lines on top]
199-------------------------
-------------------------199
200-------------------------
-------------------------200
[nothing below, we're at the bottom]
What I see:
[more lines on top]
171-------------------------
-------------------------171
172-------------------------
-------------------------172
[more lines below]
Oh and btw: thanks for fzf, it's amazing, I'm slowly replacing EVERETHING with fzf-based scripts
Problem: it seems like
fzfcalculates the scroll first and goes there, then wraps
Correct. This is a known issue. The current implementation calculates the offset first assuming there's no wrap before actually processing the preview contents (extracting and interpreting ANSI color codes, wrapping lines, and rendering the text on the preview window). Unfortunately, the whole process is pretty complicated and I think it's not going to be trivial to get it right.
Junegunn Choi @.***> wrote:
Correct. This is a known issue. The current implementation calculates the offset first assuming there's no wrap before actually processing the preview contents (extracting and interpreting ANSI color codes, wrapping lines, and rendering the text on the preview window). Unfortunately, the whole process is pretty complicated and I think it's not going to be trivial to get it right.
Understood. For information I have managed to do a manual wrapping on my side (not just because of this issue, but because I also need some specific indentation for my use case) so this issue has no urgency for me. Feel free to manage it as you see fit :)
For anyone looking for a simple solution, use fold -s -w $(tput cols)
in the preview
-- Matthieu Rakotojaona
FYI, you can refer to $FZF_PREVIEW_COLUMNS instead of using tput cols.
Junegunn Choi @.***> wrote:
FYI, you can refer to
$FZF_PREVIEW_COLUMNSinstead of usingtput cols.
Oh great ! I didn't know about that.
I'm using my own script and I'd like it to be usable outside of fzf as well, so I'll keep using tput, but it's good to know !
-- Matthieu Rakotojaona