Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sixel image format in less #477

Open
ploum opened this issue Feb 6, 2024 · 6 comments
Open

Support for sixel image format in less #477

ploum opened this issue Feb 6, 2024 · 6 comments

Comments

@ploum
Copy link

ploum commented Feb 6, 2024

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
Copy link
Owner

gwsw commented Feb 7, 2024

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

@ploum
Copy link
Author

ploum commented Feb 7, 2024

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
Copy link
Contributor

polluks commented Feb 8, 2024

It already works! :-)

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

@ploum
Copy link
Author

ploum commented Feb 8, 2024

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
Copy link
Owner

gwsw commented Feb 11, 2024

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
Copy link
Author

ploum commented Feb 11, 2024

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

sixel.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants