Scrollable previews #1946
Replies: 2 comments 9 replies
-
This is now added as a tip in the wiki. |
Beta Was this translation helpful? Give feedback.
-
At this stage I should point out that the ability to scroll previews should be viewed as a way of quickly verifying the contents of a file. It is not intended to be a replacement for a file viewer - that functionality is still better suited for more dedicated programs like When I first looked into this issue, I thought that it would be nice to somehow configure keybindings like |
Beta Was this translation helpful? Give feedback.
-
There has been a number of requests from users to implement preview scrolling:
Given that the contents of directories can be scrolled, it is understandable why users would request the same for (text) files. However, the reality is that while scrolling is implemented for directories, the same implementation does not work for files. In
lf
, the entire directory tree is read once and stored in memory, and it is simple enough to implement scrolling (and other commands liketop
andbottom
). The same approach can't be used for files though - if the user selects a file that is several GB in size, then storing the entire contents of the file just for previewing can cause out-of-memory issues as RAM is a limited resource.That being said, it is not impossible to implement scrolling for file contents. After all, pagers and text editors exist which can handle files that are several GB in size. But then the question is "why?" - if there are already other programs that can scroll previews, why does
lf
need to include it as a feature as well? From the very start,lf
has been designed to be a minimalistic application, with pager-like features listed as a non-feature, see #610 (comment). This means writing code such that only core functionality for file management is provided, while maintaining the flexibility to use additional programs for other less-important features, as opposed to writing a monolithic program wherelf
can do everything by itself.Despite all of this, after some experimenting I have managed to find a way (albeit somewhat hacky) to implement preview scrolling entirely from user configuration. I believe that this was always the intended approach, and that a built-in implementation for scrolling was never intended when the file previews was added as a feature.
lfrc
:previewer.sh
:The way it works is by storing the preview offset as user-defined variable, and then using it in the
previewer
script. The output is never cached, so that thepreviewer
script will be invoked again when the offset is changed. This is just a proof-of-concept implementation, just for working with text files. However, in theory this approach could also be used for scrolling other types of files, such as pages of PDFs, or frames of a video.Beta Was this translation helpful? Give feedback.
All reactions