From a591a7f268b65df60f6789bd733e999a6ccefbe7 Mon Sep 17 00:00:00 2001 From: Yurii Karabas <1998uriyyo@gmail.com> Date: Fri, 10 Apr 2026 00:16:53 +0200 Subject: [PATCH] feat: add ability to override sixel encoder func --- textual_image/widget/sixel.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/textual_image/widget/sixel.py b/textual_image/widget/sixel.py index 7e9b591..a680611 100644 --- a/textual_image/widget/sixel.py +++ b/textual_image/widget/sixel.py @@ -184,7 +184,7 @@ def render_lines(self, crop: Region) -> list[Strip]: image_data = self._scale_image(image_data, terminal_sizes) image_data = self._crop_image(image_data, crop, terminal_sizes) - sixel_data = image_to_sixels(image_data.pil_image, self._sixel_options, background=background) + sixel_data = self._image_to_sixels(image_data.pil_image, self._sixel_options, background=background) self._cached_sixels = _CachedSixels( self.image, crop, self.content_size, terminal_sizes, self._sixel_options, background, sixel_data ) @@ -193,6 +193,14 @@ def render_lines(self, crop: Region) -> list[Strip]: lines = [Strip([])] * (crop.height - 1) + [Strip(sixel_segments, cell_length=crop.width)] return lines + def _image_to_sixels( + self, + image: PILImage.Image, + sixel_options: SixelOptions | None = None, + background: BackgroundColor | None = None, + ) -> str: + return image_to_sixels(image, sixel_options, background) + def _scale_image(self, image_data: PixelData, terminal_sizes: CellSize) -> PixelData: assert isinstance(self.parent, Image)