Skip to content

Commit

Permalink
feat: Add .widget.UrwidImageScreen
Browse files Browse the repository at this point in the history
- Add: An urwid screen that clears *kitty* and *iterm2* images at start
  and stop.
  • Loading branch information
AnonymouX47 committed Feb 22, 2023
1 parent c1af6af commit 49a95bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/term_image/widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
except ImportError:
pass
else:
from .urwid import UrwidImage, UrwidImageCanvas, UrwidImageJanitor
from .urwid import UrwidImage, UrwidImageCanvas, UrwidImageJanitor, UrwidImageScreen

del urwid
__all__ += ["UrwidImage", "UrwidImageCanvas", "UrwidImageJanitor"]
__all__ += [
"UrwidImage",
"UrwidImageCanvas",
"UrwidImageJanitor",
"UrwidImageScreen",
]
20 changes: 19 additions & 1 deletion src/term_image/widget/urwid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import urwid

from ..exceptions import UrwidImageError
from ..image import BaseImage, ITerm2Image, KittyImage, Size, TextImage
from ..image import BaseImage, ITerm2Image, KittyImage, Size, TextImage, kitty
from ..utils import COLOR_RESET_b, ESC_b

# NOTE: Any new "private" attribute of any subclass of an urwid class should be
Expand Down Expand Up @@ -601,3 +601,21 @@ def process_shard_tails():
self._ti_image_cviews = frozenset(images)

return main_canv


class UrwidImageScreen(urwid.raw_display.Screen):
"""A screen that clears all visible :ref:`graphics-based <graphics-based>` images
off the screen immediately after it starts and immediately before it stops.
See the `baseclass
<http://urwid.org/reference/display_modules.html#urwid.raw_display.Screen>`_
for futher description.
"""

def _start(self, *args, **kwargs):
super()._start(*args, **kwargs)
self.write(kitty.DELETE_ALL_IMAGES)

def _stop(self):
self.write(kitty.DELETE_ALL_IMAGES)
super()._stop()

0 comments on commit 49a95bf

Please sign in to comment.