charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
25.55k stars 740 forks source link

Displaying images #163

Open cwqt opened 2 years ago

cwqt commented 2 years ago

Would be cool to be able to display images in the CLI (think displaying graphs with a higher resolution than ASCII characters) - this kind of thing has been implemented in projects like neofetch using various image backends (see https://sw.kovidgoyal.net/kitty/kittens/icat/ for example)

image

mistakenelf commented 2 years ago

Not that this is exactly what you are looking for, but, in https://github.com/knipferrc/fm I render the images as a string. Its not super high quality, but a little nicer than ASCII characters

AutumnMeowMeow commented 1 year ago

You may find this list of bitmap protocols and supporting terminal emulators of use: https://www.reddit.com/r/linux/comments/t3m7zm/quick_roundup_of_bitmap_graphics_availability_in/

jficz commented 1 year ago

For quick'n'dirty partial support two things might be enough to support Kitty graphics protocol (and sixel, too):

  1. detect image APCs here and don't truncate lines containing them (and also make sure it is rendered fully if it is a multiline APC (sixel) - that doesn't always work (probably) because of the terminal height detection but I didn't do any in-depth debugging there yet.
  2. make sure they're rendered properly (not sure how to do that with Kitty graphics)

Sixel graphics is usually displayed correctly by bubbletea if not truncated (i.e. short images or properly newlined images) but kitty graphics is not displayed even when the APC code is not (apparently) mangled by the rendering engine. Kitty graphics is much more powerful but the rendering is also a bit more complex so this may actually be a problem with how termenv is used but this is just a speculation on my side at this point.