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

Add support for Kitty's Terminal graphics protocol #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions rainbowstream/c_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ def image_to_display(path, start=None, length=None):

height = min(height, c['IMAGE_MAX_HEIGHT'])

# Sixel
if c['IMAGE_ON_TERM'] == 'sixel':
import fcntl, struct, termios
from io import BytesIO
from libsixel import sixel_dither_new, sixel_dither_initialize, sixel_encode, sixel_output_new, SIXEL_PIXELFORMAT_RGBA8888
from resizeimage import resizeimage
if c['IMAGE_ON_TERM']: # If it is either 'sixel' or True
import fcntl, struct, termios # Moved up because max_*_pixels is needed
# for both sixel and kitty

# FIXME: rows and columns are gotten a second time. Maybe use this at
# the begining of function instead of the call to stty size
Expand All @@ -100,6 +97,21 @@ def image_to_display(path, start=None, length=None):
max_width_pixels = width * (xpixels // columns)
max_height_pixels = height * (ypixels // rows)


# Kitty
if c['IMAGE_ON_TERM'] and os.environ['TERM'] == 'xterm-kitty':
from pixcat import Image as Image2

pic = Image2(path)
pic = pic.resize(max_w=max_width_pixels, max_h=max_height_pixels)
pic.show(align='center')

# Sixel
elif c['IMAGE_ON_TERM'] == 'sixel':
from io import BytesIO
from libsixel import sixel_dither_new, sixel_dither_initialize, sixel_encode, sixel_output_new, SIXEL_PIXELFORMAT_RGBA8888
from resizeimage import resizeimage

# FIXME: This way is preferable to avoid an addition dependency, but it doesn't work correctly
# i = i.resize((max_width_pixels, max_height_pixels), Image.ANTIALIAS)
i = resizeimage.resize_thumbnail(i, [max_width_pixels, max_height_pixels])
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"PySocks",
"pocket",
"libsixel-python",
"resize-image"
"resize-image",
"pixcat"
]

# Default user (considers non virtualenv method)
Expand Down