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

Display image values using Sixel terminal protocol #267

Open
gwpl opened this issue Mar 8, 2025 · 10 comments
Open

Display image values using Sixel terminal protocol #267

gwpl opened this issue Mar 8, 2025 · 10 comments

Comments

@gwpl
Copy link

gwpl commented Mar 8, 2025

Requesting here as jqlang/jq#3291 maybe also great addition to this project:

Sixel allows to display images in terminals ( e.g. https://github.com/saitoha/libsixel ; https://en.wikipedia.org/wiki/Sixel ; https://github.com/atanunq/viu (Rust) ),
let's make --sixel flag that will :

  • under each value (in pretty print mode) that contains image (e.g. base64 encoded) to display "key-name:" and after that display image using sixel
  • that would require detecting if given value is base64 and later if is some supported image file (e.g. png, jpg, webp, etc) (e.g. --img auto flag)
  • alternatively pointing manually at keys to try to decode as image ( --img .data.key.img )

Rationale:

  • more and more APIs return image encoded as value, or AI/ML datasets, contain images in json files as values.
@gwpl
Copy link
Author

gwpl commented Mar 8, 2025

If you decide to add support you can always reply to https://x.com/GWierzowiecki/status/1898510522221461577 :)
Thank you!

@gwpl
Copy link
Author

gwpl commented Mar 9, 2025

Btw. I gave a try in

with this test payload json with base64 png image as one of values:

Currently it "almost works" , in my terminal it just jumps to 0x0 cortner then displaying image, instead of behaving like viu ( https://github.com/atanunq/viu - that uses viuer btw.) or lsix, which display image in next line, and continue with printing text after image...

@01mf02 01mf02 changed the title Please consider feature for displaying values that are images using Sixel terminal protocol Display image values using Sixel terminal protocol Mar 10, 2025
@01mf02
Copy link
Owner

01mf02 commented Mar 10, 2025

Hi @gwpl, thanks a lot for the idea and your work on the sixel branch! Funnily, just today, before seeing your post, I thought about precisely the same functionality (showing image data directly from jaq), so I'm definitely interested. I think that to be flexible, I would not add a command-line flag, but a filter that interprets an image as image, e.g. .img |= (@base64d | @pngd). I can adapt your work to this, once you figure out how to make the image appear at the right position.

@gwpl
Copy link
Author

gwpl commented Mar 10, 2025

Lovely!
Please, I don't know when I will have spare moment to sit and debug this,
if I will I will do, otherwise as you see I made ticket on repo of library asking for help, so hopefully it will work out...
... otherwise, please try viu command line tool yourself that is CLI wrapper around library I used, and maybe that will give you a feel how to make it work.
Also I don't mind if anyone will make new branch and drop mine, I just would love to see that feature , and hopefully my work will be good starting point or inspiration to others.
Otherwise, if spare moment comes, will try to push debugging deeper.
(or if someone finds issue please write in this issue I am happy to apply changes, advice to my branch and update it)

@01mf02
Copy link
Owner

01mf02 commented Mar 11, 2025

@gwpl, do not worry and take your time, if you want to continue your effort on this feature. I'm not in a hurry. :)

@gwpl
Copy link
Author

gwpl commented Mar 11, 2025

I've found fix!

Works! Pull Reuqest: #269

Image

@01mf02
Copy link
Owner

01mf02 commented Mar 14, 2025

Wow, thanks for your work, this looks already quite good! I have left a few comments in your PR to help you improve your code.

@gwpl
Copy link
Author

gwpl commented Mar 14, 2025

More updates on #269 !

Image
2025-03-14--jaq-issue-267-with-identation.json

(updating gist with used jsons with images: https://gist.github.com/gwpl/f770639a0a21025ec5c1c775a200ddc8 )

@gwpl
Copy link
Author

gwpl commented Mar 26, 2025

Hello, can I help with review?
IIUC Convention is to respond to reviewer comments, and reviewer to close discussions, however if you wish otherwise, I am glad to help and follow.

@01mf02
Copy link
Owner

01mf02 commented Mar 27, 2025

@gwpl, see my comment in #269.

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

No branches or pull requests

2 participants