hackerb9 / lsix

Like "ls", but for images. Shows thumbnails in terminal using sixel graphics.
GNU General Public License v3.0
4.03k stars 127 forks source link

paging support #65

Open dan-da opened 1 year ago

dan-da commented 1 year ago

Is there any way to scroll thumbnails one page at a time? If I try to pipe lsix output through more or less there is just garbage, not too surprising I guess.

hackerb9 commented 1 year ago

Good question! I rarely have that many photos in one directory so I never thought about it. I typically just use Shift+PgUp in xterm to scroll back.

Idea 1: Theoretically, one could create a general pager which could read sixel data and know how many rows to scroll down. (For example, cat foo.six | identify - six:- would work most of the time to get the pixel height).

Idea 2: Although I strive to keep lsix as simple as possible, it may make more sense to build the pager into it. My biggest problem with doing that would be that to do it right I'd need to query the terminal to find out how tall the character cell is in pixels and not all terminals handle that correctly. I could make simplifying assumptions, like having lsix prompt "More?" after every three rows no matter the terminal size or resolution, but that might feel embarrassingly kludgy.

Idea 3: Investigate how to send the proper number of newlines to the terminal such that a pager like less -r would show the sixel images at the proper rate. Something like this, perhaps:

lsix | awk -v count=10 -v esc=$'\e'  '
BEGIN { s="";  for (i=0; i<count; i++) {s=s i "\n";}  
        s = s "\r" esc "[" count "A" esc "P";}   
{ gsub(esc "P", s esc "P");  
  print; 
}'  | less -r