profanity-im / profanity

Ncurses based XMPP client
https://profanity-im.github.io/
Other
1.31k stars 183 forks source link

Inline display of images #1301

Open jubalh opened 4 years ago

jubalh commented 4 years ago

We could use @hpjansson s chafa/libchafa to display images inline.

Expected Behavior

There should be a dedicated setting for this. For example /inlineimage on|off. When on and a user sends a URL ending in a known image format (we will have to search through each incoming message). We download the image to a temporary location (or a general media location) and use chafa to display the picture inside Profanity.

Similar this could be done for avatars, a new /avatar view contact could be added.

Current Behavior

The URL is shown.

Possible Solution

Chafa has also sixel support. I'm not sure whether we can detect whether a terminal supports this or should make it easy and just let the user have a setting for this. So in case sixel support is present/set we can use sixel to display the image, otherwise we use one of chafas tricks.

See https://hpjansson.org/chafa/gallery/ what chafa looks like on the terminal.

It might be helpful to look at what vifm and ranger do: https://github.com/vifm/vifm/commit/7e21fa69a5e78cdbea84b3bb6cf7cf749e99ce8f https://github.com/ranger/ranger/issues/1434

Example what it looks like in ranger:

ranger
hpjansson commented 4 years ago

I'm available to help if needed. Note that Chafa can be made to generate Unicode, ASCII or sixel output using the same API. There isn't a lot of extra work to get sixel output that way, even the dimensions are still specified in character cells.

Also, if you need extra API (for instance, ways to access canvas contents), feel free to let me know. I'm already planning to add more accessors/drawing functions, but I haven't planned out the details yet, so input is very welcome.

jubalh commented 3 years ago

@mdosch @wstrm Anybody knows how Conversations decides whether to display an image inline?

Displaying each image inline? Sounds like you can be spammed easily. So should we do it like /url open <tab>? That you can tab through the last links with image ending and upon hitting enter just that image will be displayed?

How do we detect whether an URL actually is just an image? We would need to download it first I assume since just the file ending won't be a guarantee.

mdosch commented 3 years ago

Afaik conversations automatically downloads from contacts in your roster if the file size is below a configurable threshold.