gwsw / less

Less - text pager
http://greenwoodsoftware.com/less
Other
562 stars 88 forks source link

Support for sixel image format in less #477

Closed ploum closed 4 months ago

ploum commented 9 months ago

Proposal : adding support for images encoded using the sixel format in less. https://en.wikipedia.org/wiki/Sixel

Usecase :  Offpunk is a CLI webbrowser which translates HTML pages to ANSI, save the result in a file then open it in less.

Images are converted to ANSI symbols using Chafa. See screenshot on: https://sr.ht/~lioploum/offpunk/

Chafa: https://hpjansson.org/chafa/

Chafa also supports encoding images to the sixel format, which would be a lot less useful but is not supported by less.

Proposal would be to allow less to understand sixel images and display them (probably when enabled using a paramater).

For terminals supporting sixel, see: https://www.arewesixelyet.com/

gwsw commented 9 months ago

Can't you use a LESSOPEN preprocessor to do this conversion? It seems a rather specialized feature to add to less itself.

ploum commented 9 months ago

I’m not really a specialist but I don’t think any preprocessing could help.

The way I see it (which may be wrong) is that the sixel protocol is doing to pixel what ANSI is doing to characters. So any rendering has to be done in less itself (you could not preprocess ANSI).

But I have no idea how hard it could be.

All I know is that I could take the following file and do "cat sixel.txt" in my terminal : it will display a picture.

But "less sixel.txt" is full of garbage.

sixel.txt

(I want to be clear that I’m launching a discussion about the subject here because I find it interesting. I have no preconceived opinion on what could or should be done. Thanks a lot for your work on less !)

polluks commented 9 months ago

It already works! :-)


$ xterm -ti vt340
$ wget https://raw.githubusercontent.com/gnachman/libsixel-1/master/images/snake.six
$ less -r snake.six
ploum commented 9 months ago

Oh yeah, with your examples, it works in xterm. That’s really interesting so it seems my own issues are not related to less but probably to the terminal (and also to my own sixels files)

gwsw commented 9 months ago

FWIW, the Wikipedia article says sixel sequences begin with ESC P ... q, but your sixel.txt file seems to be a different format; it contains sequences that begin with ESC _ G. The snake.six file referred to by @polluks does contain ESC P ... q sequences.

ploum commented 9 months ago

yes, I messed up the file. This version should be valid:

sixel.txt

gwsw commented 4 months ago

Based on the message from @ploum on Feb 8, it sounds like this is not a less issue.