From 96326280e5d6e49b511bc1e5cd1579a6d2a4864e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Aug 2021 22:06:05 +0530 Subject: [PATCH] Use a pending update when drawing the screen --- kittens/themes/main.py | 13 +++++++------ kittens/tui/handler.py | 9 +++++++-- kittens/tui/operations.py | 8 ++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/kittens/themes/main.py b/kittens/themes/main.py index fdc57c4c0..d3c6df808 100644 --- a/kittens/themes/main.py +++ b/kittens/themes/main.py @@ -278,12 +278,13 @@ class ThemesHandler(Handler): self.on_browsing_key_event(key_event, in_bracketed_paste) def draw_screen(self) -> None: - self.cmd.clear_screen() - self.enforce_cursor_state() - if self.state is State.fetching: - self.draw_fetching_screen() - elif self.state is State.browsing: - self.draw_browsing_screen() + with self.pending_update(): + self.cmd.clear_screen() + self.enforce_cursor_state() + if self.state is State.fetching: + self.draw_fetching_screen() + elif self.state is State.browsing: + self.draw_browsing_screen() def on_resize(self, screen_size: ScreenSize) -> None: self.screen_size = screen_size diff --git a/kittens/tui/handler.py b/kittens/tui/handler.py index b3794e804..68a7260cb 100644 --- a/kittens/tui/handler.py +++ b/kittens/tui/handler.py @@ -10,10 +10,12 @@ from typing import ( from kitty.types import ParsedShortcut from kitty.typing import ( - AbstractEventLoop, BossType, Debug, ImageManagerType, KeyEventType, - KeyActionType, LoopType, MouseEvent, ScreenSize, TermManagerType + AbstractEventLoop, BossType, Debug, ImageManagerType, KeyActionType, + KeyEventType, LoopType, MouseEvent, ScreenSize, TermManagerType ) +from .operations import pending_update + class Handler: @@ -134,6 +136,9 @@ class Handler: def suspend(self) -> ContextManager[TermManagerType]: return self._term_manager.suspend() + def pending_update(self) -> ContextManager[None]: + return pending_update(self.write) + class HandleResult: diff --git a/kittens/tui/operations.py b/kittens/tui/operations.py index 8a1a8cf06..8e41daea1 100644 --- a/kittens/tui/operations.py +++ b/kittens/tui/operations.py @@ -40,6 +40,7 @@ MODES = dict( MOUSE_URXVT_MODE=(1015, '?'), ALTERNATE_SCREEN=(1049, '?'), BRACKETED_PASTE=(2004, '?'), + PENDING_UPDATE=(2026, '?'), ) F = TypeVar('F') @@ -290,6 +291,13 @@ def reset_state(normal_screen: bool = True) -> str: return ans +@contextmanager +def pending_update(write: Callable[[str], None]) -> Generator[None, None, None]: + write(set_mode('PENDING_UPDATE')) + yield + write(reset_mode('PENDING_UPDATE')) + + @contextmanager def cursor(write: Callable[[str], None]) -> Generator[None, None, None]: write(SAVE_CURSOR)