more typing work
This commit is contained in:
parent
01142cdc8c
commit
10435c23c2
@ -101,7 +101,7 @@ class Resize(Handler):
|
|||||||
print(styled('Sizes', bold=True, fg='white', fg_intense=True))
|
print(styled('Sizes', bold=True, fg='white', fg_intense=True))
|
||||||
print('Original: {} rows {} cols'.format(self.original_size.rows, self.original_size.cols))
|
print('Original: {} rows {} cols'.format(self.original_size.rows, self.original_size.cols))
|
||||||
print('Current: {} rows {} cols'.format(
|
print('Current: {} rows {} cols'.format(
|
||||||
styled(self.screen_size.rows, fg='magenta'), styled(self.screen_size.cols, fg='magenta')))
|
styled(str(self.screen_size.rows), fg='magenta'), styled(str(self.screen_size.cols), fg='magenta')))
|
||||||
|
|
||||||
|
|
||||||
OPTIONS = r'''
|
OPTIONS = r'''
|
||||||
|
|||||||
@ -5,14 +5,17 @@
|
|||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
|
from typing import (
|
||||||
|
IO, TYPE_CHECKING, Any, Callable, Dict, Generator, Optional, Tuple, Union
|
||||||
|
)
|
||||||
|
|
||||||
from kitty.rgb import Color, color_as_sharp, to_color
|
from kitty.rgb import Color, color_as_sharp, to_color
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from kitty.utils import ScreenSize
|
from kitty.utils import ScreenSize
|
||||||
from .images import GraphicsCommand
|
from .images import GraphicsCommand
|
||||||
ScreenSize, GraphicsCommand
|
from .handler import Handler
|
||||||
|
ScreenSize, GraphicsCommand, Handler
|
||||||
|
|
||||||
S7C1T = '\033 F'
|
S7C1T = '\033 F'
|
||||||
SAVE_CURSOR = '\0337'
|
SAVE_CURSOR = '\0337'
|
||||||
@ -216,7 +219,7 @@ def clear_images_on_screen(delete_data: bool = False) -> str:
|
|||||||
return gc.serialize().decode('ascii')
|
return gc.serialize().decode('ascii')
|
||||||
|
|
||||||
|
|
||||||
def init_state(alternate_screen=True):
|
def init_state(alternate_screen: bool = True) -> str:
|
||||||
ans = (
|
ans = (
|
||||||
S7C1T + SAVE_CURSOR + SAVE_PRIVATE_MODE_VALUES + reset_mode('LNM') +
|
S7C1T + SAVE_CURSOR + SAVE_PRIVATE_MODE_VALUES + reset_mode('LNM') +
|
||||||
reset_mode('IRM') + reset_mode('DECKM') + reset_mode('DECSCNM') +
|
reset_mode('IRM') + reset_mode('DECKM') + reset_mode('DECSCNM') +
|
||||||
@ -235,7 +238,7 @@ def init_state(alternate_screen=True):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def reset_state(normal_screen=True):
|
def reset_state(normal_screen: bool = True) -> str:
|
||||||
ans = ''
|
ans = ''
|
||||||
if normal_screen:
|
if normal_screen:
|
||||||
ans += reset_mode('ALTERNATE_SCREEN')
|
ans += reset_mode('ALTERNATE_SCREEN')
|
||||||
@ -246,21 +249,27 @@ def reset_state(normal_screen=True):
|
|||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cursor(write):
|
def cursor(write: Callable[[str], None]) -> Generator[None, None, None]:
|
||||||
write(SAVE_CURSOR)
|
write(SAVE_CURSOR)
|
||||||
yield
|
yield
|
||||||
write(RESTORE_CURSOR)
|
write(RESTORE_CURSOR)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def alternate_screen(f=None):
|
def alternate_screen(f: Optional[IO[str]] = None) -> Generator[None, None, None]:
|
||||||
f = f or sys.stdout
|
f = f or sys.stdout
|
||||||
print(set_mode('ALTERNATE_SCREEN'), end='', file=f)
|
print(set_mode('ALTERNATE_SCREEN'), end='', file=f)
|
||||||
yield
|
yield
|
||||||
print(reset_mode('ALTERNATE_SCREEN'), end='', file=f)
|
print(reset_mode('ALTERNATE_SCREEN'), end='', file=f)
|
||||||
|
|
||||||
|
|
||||||
def set_default_colors(fg=None, bg=None, cursor=None, select_bg=None, select_fg=None) -> str:
|
def set_default_colors(
|
||||||
|
fg: Optional[Union[Color, str]] = None,
|
||||||
|
bg: Optional[Union[Color, str]] = None,
|
||||||
|
cursor: Optional[Union[Color, str]] = None,
|
||||||
|
select_bg: Optional[Union[Color, str]] = None,
|
||||||
|
select_fg: Optional[Union[Color, str]] = None
|
||||||
|
) -> str:
|
||||||
ans = ''
|
ans = ''
|
||||||
|
|
||||||
def item(which: Optional[Union[Color, str]], num: int) -> None:
|
def item(which: Optional[Union[Color, str]], num: int) -> None:
|
||||||
@ -284,7 +293,7 @@ def set_default_colors(fg=None, bg=None, cursor=None, select_bg=None, select_fg=
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def write_to_clipboard(data: Union[str, bytes], use_primary=False) -> str:
|
def write_to_clipboard(data: Union[str, bytes], use_primary: bool = False) -> str:
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
from base64 import standard_b64encode
|
from base64 import standard_b64encode
|
||||||
@ -300,7 +309,7 @@ def write_to_clipboard(data: Union[str, bytes], use_primary=False) -> str:
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def request_from_clipboard(use_primary=False) -> str:
|
def request_from_clipboard(use_primary: bool = False) -> str:
|
||||||
return '\x1b]52;{};?\x07'.format('p' if use_primary else 'c')
|
return '\x1b]52;{};?\x07'.format('p' if use_primary else 'c')
|
||||||
|
|
||||||
|
|
||||||
@ -309,13 +318,13 @@ all_cmds = tuple(
|
|||||||
if hasattr(obj, '__annotations__') and obj.__annotations__.get('return') is str)
|
if hasattr(obj, '__annotations__') and obj.__annotations__.get('return') is str)
|
||||||
|
|
||||||
|
|
||||||
def writer(handler, func):
|
def writer(handler: 'Handler', func: Callable) -> Callable:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def f(self, *a, **kw):
|
def f(self: 'Handler', *a: Any, **kw: Any) -> None:
|
||||||
handler.write(func(*a, **kw))
|
handler.write(func(*a, **kw))
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
def commander(handler):
|
def commander(handler: 'Handler') -> Any:
|
||||||
ans = {name: writer(handler, obj) for name, obj in all_cmds}
|
ans = {name: writer(handler, obj) for name, obj in all_cmds}
|
||||||
return type('CMD', (), ans)()
|
return type('CMD', (), ans)()
|
||||||
|
|||||||
@ -56,11 +56,11 @@ If specified resize the window this command is run in, rather than the active wi
|
|||||||
def response_from_kitty(self, boss: 'Boss', window: 'Window', payload_get: PayloadGetType) -> ResponseType:
|
def response_from_kitty(self, boss: 'Boss', window: 'Window', payload_get: PayloadGetType) -> ResponseType:
|
||||||
match = payload_get('match')
|
match = payload_get('match')
|
||||||
if match:
|
if match:
|
||||||
windows = tuple(boss.match_windows(match))
|
windows = list(boss.match_windows(match))
|
||||||
if not windows:
|
if not windows:
|
||||||
raise MatchError(match)
|
raise MatchError(match)
|
||||||
else:
|
else:
|
||||||
windows = tuple(window if window and payload_get('self') else boss.active_window)
|
windows = [window if window and payload_get('self') else boss.active_window]
|
||||||
resized = False
|
resized = False
|
||||||
if windows and windows[0]:
|
if windows and windows[0]:
|
||||||
resized = boss.resize_layout_window(
|
resized = boss.resize_layout_window(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user