mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 10:12:17 +02:00
Use a stub rather than TYPE_CHECKING
This commit is contained in:
@@ -3,35 +3,29 @@
|
||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from types import TracebackType
|
||||
from typing import (
|
||||
TYPE_CHECKING, Any, Callable, ContextManager, Dict, Optional, Sequence, Type,
|
||||
Union
|
||||
Any, Callable, ContextManager, Dict, Optional, Sequence, Type, Union
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from kitty.utils import ScreenSize
|
||||
from .loop import TermManager, Loop, Debug, MouseEvent
|
||||
from .images import ImageManager
|
||||
from kitty.conf.utils import KittensKeyAction
|
||||
from kitty.boss import Boss
|
||||
from kitty.key_encoding import KeyEvent
|
||||
from types import TracebackType
|
||||
ScreenSize, TermManager, Loop, Debug, KeyEvent, MouseEvent, TracebackType, Boss, ImageManager
|
||||
import asyncio
|
||||
from kitty.typing import (
|
||||
AbstractEventLoop, BossType, Debug, ImageManagerType, KeyEventType,
|
||||
KittensKeyActionType, LoopType, MouseEvent, ScreenSize, TermManagerType
|
||||
)
|
||||
|
||||
|
||||
class Handler:
|
||||
|
||||
image_manager_class: Optional[Type['ImageManager']] = None
|
||||
image_manager_class: Optional[Type[ImageManagerType]] = None
|
||||
|
||||
def _initialize(
|
||||
self,
|
||||
screen_size: 'ScreenSize',
|
||||
term_manager: 'TermManager',
|
||||
screen_size: ScreenSize,
|
||||
term_manager: TermManagerType,
|
||||
schedule_write: Callable[[bytes], None],
|
||||
tui_loop: 'Loop',
|
||||
debug: 'Debug',
|
||||
image_manager: Optional['ImageManager'] = None
|
||||
tui_loop: LoopType,
|
||||
debug: Debug,
|
||||
image_manager: Optional[ImageManagerType] = None
|
||||
) -> None:
|
||||
from .operations import commander
|
||||
self.screen_size = screen_size
|
||||
@@ -43,15 +37,15 @@ class Handler:
|
||||
self._image_manager = image_manager
|
||||
|
||||
@property
|
||||
def image_manager(self) -> 'ImageManager':
|
||||
def image_manager(self) -> ImageManagerType:
|
||||
assert self._image_manager is not None
|
||||
return self._image_manager
|
||||
|
||||
@property
|
||||
def asyncio_loop(self) -> 'asyncio.AbstractEventLoop':
|
||||
def asyncio_loop(self) -> AbstractEventLoop:
|
||||
return self._tui_loop.asycio_loop
|
||||
|
||||
def add_shortcut(self, action: 'KittensKeyAction', key: str, mods: Optional[int] = None, is_text: Optional[bool] = False) -> None:
|
||||
def add_shortcut(self, action: KittensKeyActionType, key: str, mods: Optional[int] = None, is_text: Optional[bool] = False) -> None:
|
||||
if not hasattr(self, '_text_shortcuts'):
|
||||
self._text_shortcuts, self._key_shortcuts = {}, {}
|
||||
if is_text:
|
||||
@@ -59,7 +53,7 @@ class Handler:
|
||||
else:
|
||||
self._key_shortcuts[(key, mods or 0)] = action
|
||||
|
||||
def shortcut_action(self, key_event_or_text: Union[str, 'KeyEvent']) -> Optional['KittensKeyAction']:
|
||||
def shortcut_action(self, key_event_or_text: Union[str, KeyEventType]) -> Optional[KittensKeyActionType]:
|
||||
if isinstance(key_event_or_text, str):
|
||||
return self._text_shortcuts.get(key_event_or_text)
|
||||
return self._key_shortcuts.get((key_event_or_text.key, key_event_or_text.mods))
|
||||
@@ -70,7 +64,7 @@ class Handler:
|
||||
self.debug.fobj = self
|
||||
self.initialize()
|
||||
|
||||
def __exit__(self, etype: type, value: Exception, tb: 'TracebackType') -> None:
|
||||
def __exit__(self, etype: type, value: Exception, tb: TracebackType) -> None:
|
||||
del self.debug.fobj
|
||||
self.finalize()
|
||||
if self._image_manager is not None:
|
||||
@@ -82,7 +76,7 @@ class Handler:
|
||||
def finalize(self) -> None:
|
||||
pass
|
||||
|
||||
def on_resize(self, screen_size: 'ScreenSize') -> None:
|
||||
def on_resize(self, screen_size: ScreenSize) -> None:
|
||||
self.screen_size = screen_size
|
||||
|
||||
def quit_loop(self, return_code: Optional[int] = None) -> None:
|
||||
@@ -94,7 +88,7 @@ class Handler:
|
||||
def on_text(self, text: str, in_bracketed_paste: bool = False) -> None:
|
||||
pass
|
||||
|
||||
def on_key(self, key_event: 'KeyEvent') -> None:
|
||||
def on_key(self, key_event: KeyEventType) -> None:
|
||||
pass
|
||||
|
||||
def on_mouse(self, mouse_event: 'MouseEvent') -> None:
|
||||
@@ -127,7 +121,7 @@ class Handler:
|
||||
data = sep.join(map(str, args)) + end
|
||||
self.write(data)
|
||||
|
||||
def suspend(self) -> ContextManager['TermManager']:
|
||||
def suspend(self) -> ContextManager[TermManagerType]:
|
||||
return self._term_manager.suspend()
|
||||
|
||||
|
||||
@@ -141,7 +135,7 @@ class HandleResult:
|
||||
self.no_ui = no_ui
|
||||
self.type_of_input = type_of_input
|
||||
|
||||
def __call__(self, args: Sequence[str], data: Any, target_window_id: int, boss: 'Boss') -> Any:
|
||||
def __call__(self, args: Sequence[str], data: Any, target_window_id: int, boss: BossType) -> Any:
|
||||
return self.impl(args, data, target_window_id, boss)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user