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 e8f89b2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/term_image/widget/urwid.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,19 @@ 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:
# - 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, 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 e8f89b2

Please sign in to comment.