Skip to content

Commit

Permalink
Whenever sixel graphics are clipped on last line of terminal, treat s…
Browse files Browse the repository at this point in the history
…ixel cells on last line as mixed cells.
  • Loading branch information
salt-die committed Feb 12, 2025
1 parent 82df206 commit 589e2c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/batgrl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""batgrl, the badass terminal graphics library."""

__version__ = "0.43.0"
__version__ = "0.43.1"
40 changes: 25 additions & 15 deletions src/batgrl/_rendering.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,21 @@ cpdef void terminal_render(
)
# Note ALL mixed and ALL sixel cells are re-emitted if any has changed.
if emit_sixel:
gy = min_y_sixel * cell_h
gx = min_x_sixel * cell_w
gh = (max_y_sixel + 1 - min_y_sixel) * cell_h
# If sixel graphics rect reaches last line of terminal, its height must be
# clipped to nearest multiple of 6 to prevent scrolling.
if max_y_sixel + 1 == h:
y = gh % 6
if y:
gh -= y
# If sixel graphics height is clipped force repaint of sixel cells on
# last line by changing to mixed cells.
for x in range(min_x_sixel, max_x_sixel + 1):
if kind[max_y_sixel, x]:
kind[max_y_sixel, x] = MIXED

for y in range(h):
for x in range(w):
if kind[y, x] == MIXED:
Expand All @@ -1780,21 +1795,16 @@ cpdef void terminal_render(
):
raise MemoryError

gy = min_y_sixel * cell_h
gx = min_x_sixel * cell_w
gh = (max_y_sixel + 1 - min_y_sixel) * cell_h
# If sixel graphics rect reaches last line of terminal, its height must be
# truncated to nearest multiple of 6 to prevent scrolling.
if max_y_sixel + 1 == h:
gh -= gh % 6
gw = (max_x_sixel + 1 - min_x_sixel) * cell_w

if fbuf_printf(f, "\x1b[%d;%dH", min_y_sixel + 1 + oy, min_x_sixel + 1 + ox):
raise MemoryError
if sixel(
f, &octree.qs, graphics, sgraphics, aspect_h, aspect_w, gy, gx, gh, gw
):
raise MemoryError
if gh > 0:
gw = (max_x_sixel + 1 - min_x_sixel) * cell_w
if fbuf_printf(
f, "\x1b[%d;%dH", min_y_sixel + 1 + oy, min_x_sixel + 1 + ox
):
raise MemoryError
if sixel(
f, &octree.qs, graphics, sgraphics, aspect_h, aspect_w, gy, gx, gh, gw
):
raise MemoryError

cursor_y = -1
cursor_x = -1
Expand Down

0 comments on commit 589e2c9

Please sign in to comment.