From d653b08f864aec730c1750506a3b61490fa801e5 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 4 Aug 2025 15:42:58 +0200 Subject: [PATCH] Refactor out _SetScreenEvent. --- ircplom/tui_base.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ircplom/tui_base.py b/ircplom/tui_base.py index ef7da24..124b026 100644 --- a/ircplom/tui_base.py +++ b/ircplom/tui_base.py @@ -52,16 +52,6 @@ class TuiEvent(AffectiveEvent): target.term.flush() -@dataclass -class _SetScreenEvent(TuiEvent): - - def affect(self, target: 'BaseTui') -> None: - target.term.calc_geometry() - for window in target.windows: - window.set_geometry() - super().affect(target) - - class _YX(NamedTuple): y: int x: int @@ -369,7 +359,7 @@ class _KeyboardEvent(TuiEvent, PayloadMixin): def affect(self, target: 'BaseTui') -> None: if self.payload[0] == _CHAR_RESIZE: - _SetScreenEvent().affect(target) + target.set_screen() return if self.payload in _KEYBINDINGS: cmd_data = _KEYBINDINGS[self.payload] @@ -407,7 +397,16 @@ class BaseTui(QueueMixin): self.log = Logger( lambda msg: # pylint: disable=unnecessary-lambda # to keep … self.window.log.append(msg)) # … up-to-date _what_ window's .log - self._put(_SetScreenEvent()) + self.set_screen() + signal(SIGWINCH, lambda *_: self.set_screen()) + + def set_screen(self) -> None: + 'Calc screen geometry into .windows, fully draw front one and flush.' + self.term.calc_geometry() + for window in self.windows: + window.set_geometry() + self.window.draw() + self.term.flush() def cmd_name_to_cmd(self, cmd_name: str) -> Optional[Callable]: 'Map cmd_name to executable TUI element method.' @@ -504,7 +503,6 @@ class Terminal(QueueMixin): @contextmanager def setup(self) -> Generator: 'Combine multiple contexts into one and run keypress loop.' - signal(SIGWINCH, lambda *_: self._put(_SetScreenEvent())) self.clear() with (self._blessed.raw(), self._blessed.fullscreen(), -- 2.30.2