Use the atomic update decorator everywhere
This commit is contained in:
parent
b1f4b2d8ed
commit
7e17ed21ce
@ -482,8 +482,8 @@ class ThemesHandler(Handler):
|
|||||||
elif self.state is State.accepting:
|
elif self.state is State.accepting:
|
||||||
self.on_accepting_key_event(key_event, in_bracketed_paste)
|
self.on_accepting_key_event(key_event, in_bracketed_paste)
|
||||||
|
|
||||||
|
@Handler.atomic_update
|
||||||
def draw_screen(self) -> None:
|
def draw_screen(self) -> None:
|
||||||
with self.pending_update():
|
|
||||||
self.cmd.clear_screen()
|
self.cmd.clear_screen()
|
||||||
self.enforce_cursor_state()
|
self.enforce_cursor_state()
|
||||||
self.cmd.set_line_wrapping(False)
|
self.cmd.set_line_wrapping(False)
|
||||||
|
|||||||
@ -566,8 +566,9 @@ class Send(Handler):
|
|||||||
self.failed_files.append(file)
|
self.failed_files.append(file)
|
||||||
self.asyncio_loop.call_soon(self.refresh_progress)
|
self.asyncio_loop.call_soon(self.refresh_progress)
|
||||||
|
|
||||||
|
@Handler.atomic_update
|
||||||
def draw_progress(self) -> None:
|
def draw_progress(self) -> None:
|
||||||
with self.pending_update(), without_line_wrap(self.write):
|
with without_line_wrap(self.write):
|
||||||
for df in self.done_files:
|
for df in self.done_files:
|
||||||
sc = styled('✔', fg='green') if not df.err_msg else styled('✘', fg='red')
|
sc = styled('✔', fg='green') if not df.err_msg else styled('✘', fg='red')
|
||||||
self.draw_progress_for_current_file(df, spinner_char=sc, is_complete=True)
|
self.draw_progress_for_current_file(df, spinner_char=sc, is_complete=True)
|
||||||
|
|||||||
@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Callable, ContextManager, Dict, Optional, Sequence, Type, Union, TYPE_CHECKING
|
TYPE_CHECKING, Any, Callable, ContextManager, Dict, Optional, Sequence,
|
||||||
|
Type, Union, cast
|
||||||
)
|
)
|
||||||
|
|
||||||
from kitty.types import ParsedShortcut
|
from kitty.types import DecoratedFunc, ParsedShortcut
|
||||||
from kitty.typing import (
|
from kitty.typing import (
|
||||||
AbstractEventLoop, BossType, Debug, ImageManagerType, KeyActionType,
|
AbstractEventLoop, BossType, Debug, ImageManagerType, KeyActionType,
|
||||||
KeyEventType, LoopType, MouseEvent, ScreenSize, TermManagerType
|
KeyEventType, LoopType, MouseEvent, ScreenSize, TermManagerType
|
||||||
@ -16,7 +17,6 @@ from kitty.typing import (
|
|||||||
|
|
||||||
from .operations import pending_update
|
from .operations import pending_update
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from kitty.file_transmission import FileTransmissionCommand
|
from kitty.file_transmission import FileTransmissionCommand
|
||||||
|
|
||||||
@ -144,18 +144,15 @@ class Handler:
|
|||||||
def suspend(self) -> ContextManager[TermManagerType]:
|
def suspend(self) -> ContextManager[TermManagerType]:
|
||||||
return self._term_manager.suspend()
|
return self._term_manager.suspend()
|
||||||
|
|
||||||
def pending_update(self) -> ContextManager[None]:
|
|
||||||
return pending_update(self.write)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def with_pending_update(cls, func: Callable) -> Callable:
|
def atomic_update(cls, func: DecoratedFunc) -> DecoratedFunc:
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def f(*a: Any, **kw: Any) -> Any:
|
def f(*a: Any, **kw: Any) -> Any:
|
||||||
with a[0].pending_update():
|
with pending_update(a[0].write):
|
||||||
return func(*a, **kw)
|
return func(*a, **kw)
|
||||||
return f
|
return cast(DecoratedFunc, f)
|
||||||
|
|
||||||
|
|
||||||
class HandleResult:
|
class HandleResult:
|
||||||
|
|||||||
@ -391,7 +391,7 @@ class UnicodeInput(Handler):
|
|||||||
text += ' ' * extra
|
text += ' ' * extra
|
||||||
self.print(styled(text, reverse=True))
|
self.print(styled(text, reverse=True))
|
||||||
|
|
||||||
@Handler.with_pending_update
|
@Handler.atomic_update
|
||||||
def draw_screen(self) -> None:
|
def draw_screen(self) -> None:
|
||||||
self.write(clear_screen())
|
self.write(clear_screen())
|
||||||
self.draw_title_bar()
|
self.draw_title_bar()
|
||||||
|
|||||||
@ -3,7 +3,9 @@
|
|||||||
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper
|
||||||
from typing import TYPE_CHECKING, Callable, Generic, NamedTuple, TypeVar, Union
|
from typing import (
|
||||||
|
TYPE_CHECKING, Any, Callable, Generic, NamedTuple, TypeVar, Union
|
||||||
|
)
|
||||||
|
|
||||||
_T = TypeVar('_T')
|
_T = TypeVar('_T')
|
||||||
|
|
||||||
@ -116,3 +118,7 @@ def ac(group: ActionGroup, doc: str) -> Callable[[_T], _T]:
|
|||||||
setattr(f, 'action_spec', ActionSpec(group, doc))
|
setattr(f, 'action_spec', ActionSpec(group, doc))
|
||||||
return f
|
return f
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
||||||
|
_BaseDecoratedFunc = Callable[..., Any]
|
||||||
|
DecoratedFunc = TypeVar('DecoratedFunc', bound=_BaseDecoratedFunc)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user