AnonymouX47 / term-image

Display images in the terminal with python
https://term-image.readthedocs.io
MIT License
219 stars 10 forks source link

Request: Refactor to provide reusable widgets that can be used in other Urwid projects #71

Closed danschwarz closed 1 year ago

danschwarz commented 1 year ago

I think several widgets would be helpful to have available for reuse elsewhere:

  1. GridListWidget
  2. Simplified widget(s) - given a fixed row count, render a (Pillow) Image using Kitty, iTerm, Sixel, or ANSI. I have separate widgets that do this in PRs for the toot project: ANSI widget and SIXEL widget
AnonymouX47 commented 1 year ago

Thanks for the request.

As i mentioned here, it will take one or two releases before this happens.

It's not that I can't release the widget now but for the following reason, I don't want to.

In my TUI, I implemented mechanisms to render images asynchronously (using a mixture of multithreading and multiprocessing). I plan to implement these mechanisms as classes in the library first.

Without asynchronous rendering, the widget will be of little or no use... rendering images will delay UI updates, input processing, etc.

What do you think?

AnonymouX47 commented 1 year ago

Thinking about it again... it wouldn't actually do any harm releasing the widget now and then releasing the asynchronous rendering as an improvement later on.

This, I can do before the next release.

AnonymouX47 commented 1 year ago

I forgot to mention that SIXEL support isn't available yet... I intend to work on it towards the release after the next.

AnonymouX47 commented 1 year ago

I just checked back here now and noticed you mentioned the GridListBox widget. Thinking about it now, I have a few concerns:

  1. Such a widget actually seems to be outside the scope of this library :thinking:.
  2. It was a really hacky thing, it basically uses a GridFlow widget and purges out the contents of its underlying pile into a ListBox, using some of the private interface of the widgets. The square-shaped LineBox you see within the grid is another widget LineSquare which monkey-patches the wrapped widget of a LineBox with another widget LineSquareMiddleColumns.
  3. If you read through its code, you'll notice it's very closely tied to other parts of the program. In fact, it works hand-in-hand with a thread that [re-]populates the grid continuously.

You're free to reuse and modify the code in another project if needed but I should note that if I were to re-implement the widget(s) today, I'd do them differently.