Skip to content

Commit

Permalink
fix(pikspect: nested_terminal): remove sigwinch signal on __exit__
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Sep 2, 2024
1 parent 4b2d6ab commit 982a3ad
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pikaur/pikspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ def __exit__(self, *_exc_details: object) -> None:

class NestedTerminal:

_original_signal: signal.Handlers | None = None

def __init__(
self, on_terminal_resize: Callable[[int, FrameType | None], None] | None = None,
) -> None:
self.tty_wrapper = TTYInputWrapper()
if on_terminal_resize is not None:
signal.signal(signal.SIGWINCH, on_terminal_resize)
self.on_terminal_resize = on_terminal_resize

def __enter__(self) -> os.terminal_size:
logger.debug("Opening virtual terminal...")
Expand All @@ -238,9 +239,14 @@ def __enter__(self) -> os.terminal_size:
):
if stream.isatty():
tty.setcbreak(stream.fileno())
if self.on_terminal_resize is not None:
self.original_signal = signal.getsignal(signal.SIGWINCH)
signal.signal(signal.SIGWINCH, self.on_terminal_resize)
return real_term_geometry

def __exit__(self, *exc_details: object) -> None:
if self._original_signal:
signal.signal(signal.SIGWINCH, self._original_signal)
self.tty_wrapper.__exit__(*exc_details)
TTYRestore.restore()

Expand Down

0 comments on commit 982a3ad

Please sign in to comment.