Suggestion for album art display #37
Replies: 3 comments 3 replies
-
Hi! Thanks for the suggestion. I took a look at your library and it looks very promising! I have been experimenting with getting w3m to work and also been trying to get chafa working properly. Does your library integrate well with cursed? I have been running into trouble with the way curses keeps track of the cursor position. I haven't (yet) found a way to draw an image using sixels (or ansi characters) without the cursor position getting messed up. I hope to find a solution to this soon. |
Beta Was this translation helpful? Give feedback.
-
I went through the code and realized your approach is to draw the image after refreshing the curses screen. After trying to print some images, I saw what you meant and realized "cbreak" mode was the culprit. The way out is to reset the TTY attributes and set them back after drawing the image. Below are the changes I made and with these, term-image works just fine on multiple terminal emulators. This should also work for chafa. @@ -11,6 +11,11 @@ from colorthief import ColorThief
import math
from pathlib import Path
+from termios import tcgetattr, tcsetattr, TCSAFLUSH
+from term_image import AutoCellRatio, set_cell_ratio
+from term_image.exceptions import TermImageError
+from term_image.image import from_file
# Get config directory
config_dir = Path(
@@ -1346,6 +1351,18 @@ class Player:
.thumbnail(self.image_width_px)
.show(x=(self.art_window_width - self.image_width)//2, y=self.image_y_pos)
)
+ elif IMAGEMETHOD == "term-image":
+ image = from_file(self.album_art_loc)
+ image.set_size(maxsize=(self.art_window_width, self.art_window_height - 5))
+
+ curses_tty_attr = tcgetattr(0)
+ try:
+ tcsetattr(0, TCSAFLUSH, original_tty_attr)
+ print("\033[0;0H", end="")
+ image.draw(pad_width=self.art_window_width, pad_height=self.art_window_height - 5)
+ print("\033[9999B", end="", flush=True)
+ finally:
+ tcsetattr(0, TCSAFLUSH, curses_tty_attr)
def centerText(self, y: int, string: str):
@@ -1488,6 +1505,11 @@ class Player:
"""
The main program loop
"""
+ # term-image
+ try:
+ set_cell_ratio(AutoCellRatio.DYNAMIC)
+ except TermImageError:
+ pass
if self.art_placement is None and IMAGEMETHOD == "ueberzug":
# Create album art placement if we are using ueberzug
@@ -1556,6 +1578,7 @@ class Player:
print(self.error)
+original_tty_attr = tcgetattr(0)
try:
player = Player()
player.loop() I also changed my NB: This was just a quick implementation. If you decide you want to use term-image, I would be willing to open a PR with a proper implementation. |
Beta Was this translation helpful? Give feedback.
-
Hello, @GuardKenzie! Stumbled upon this and upon reading through, the aura of self-promotion hit me hard. 🤦 I don't recall whether or not I knew about chafa.py at the time but even if I didn't, that still doesn't justify my actions. I'm really sorry if this made a bad first impression (I believe this was our first interaction). Please, forgive my naïveté at the time. 🙏 Thank you very much. 😃 |
Beta Was this translation helpful? Give feedback.
-
I thought this would fit better in "Discussions" but it seems to be disabled.
I just recently came across this project and going through, I noticed the limited support for album art display e.g the range of supported terminal emulators and image aspect ratio, amongst other things.
I'm the maintainer of term-image. Without much ado, I believe it has quite a lot to offer for the purpose at hand. It's still in active development and there's a lot more features on the way.
NOTE: It's still on version zero, meaning the API isn't stable yet and might change across minor versions, so it would be advisable to pin the dependency to a specific minor version if you decide to go ahead with it.
Finally, I'll appreciate your suggestions/contributions towards improving the project.
Thank you 🙇
Beta Was this translation helpful? Give feedback.
All reactions