Skip to content

Commit

Permalink
fix: Add workaround for urwid images on last row
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymouX47 committed Feb 5, 2023
1 parent 53bd90e commit e9264b1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/term_image/widget/urwid.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,24 @@ def render(self, size: Tuple[int, int], focus: bool = False) -> UrwidImageCanvas
raise
canv = type(self)._ti_error_placeholder.render(size, focus)
else:
canv = UrwidImageCanvas(render.encode().split(b"\n"), size)
lines = render.encode().split(b"\n")

# On the last row of the screen, urwid inserts the second to the last
# character after writing the last (though placed before it i.e inserted),
# thereby messing up an escape sequence occurring at the end.
# See `urwid.raw_display.Screen._last_row()`
# Exceptions:
# - The workaround is not needed for kitty style since image sequences
# always come before some blanks.
# - Unfortunately, this workaround results in the screen being scrolled with
# iterm2 style on wezterm. So, I guess a missing image line is better off.
if not (
isinstance(image, KittyImage)
or (isinstance(image, ITerm2Image) and ITerm2Image._TERM == "wezterm")
):
lines = [line + b"\0\0" for line in lines]

canv = UrwidImageCanvas(lines, size)

return canv

Expand Down

0 comments on commit e9264b1

Please sign in to comment.