mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Add more type annotations
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
from contextlib import suppress
|
||||
from typing import (
|
||||
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Generator, Iterable, List,
|
||||
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Iterable, Iterator, List,
|
||||
NoReturn, Optional, Tuple, Type, Union, cast
|
||||
)
|
||||
|
||||
@@ -64,9 +64,9 @@ class PayloadGetter:
|
||||
|
||||
no_response = NoResponse()
|
||||
payload_get = object()
|
||||
ResponseType = Optional[Union[bool, str]]
|
||||
CmdReturnType = Union[Dict[str, Any], List, Tuple, str, int, float, bool]
|
||||
CmdGenerator = Generator[CmdReturnType, None, None]
|
||||
ResponseType = Union[bool, str, None]
|
||||
CmdReturnType = Union[Dict[str, Any], List[Any], Tuple[Any, ...], str, int, float, bool]
|
||||
CmdGenerator = Iterator[CmdReturnType]
|
||||
PayloadType = Optional[Union[CmdReturnType, CmdGenerator]]
|
||||
PayloadGetType = PayloadGetter
|
||||
ArgsType = List[str]
|
||||
@@ -120,7 +120,7 @@ class RemoteCommand:
|
||||
args_count: Optional[int] = None
|
||||
args_completion: Optional[Dict[str, Tuple[str, Union[Callable[[], Iterable[str]], Tuple[str, ...]]]]] = None
|
||||
defaults: Optional[Dict[str, Any]] = None
|
||||
options_class: Type = RCOptions
|
||||
options_class: Type[RCOptions] = RCOptions
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.desc = self.desc or self.short_desc
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Dict, Generator, List, Optional, Union
|
||||
from typing import TYPE_CHECKING, List, Optional, Union
|
||||
|
||||
from kitty.fast_data_types import KeyEvent as WindowSystemKeyEvent
|
||||
from kitty.key_encoding import decode_key_event_as_window_system_key
|
||||
from kitty.options.utils import parse_send_text_bytes
|
||||
|
||||
from .base import (
|
||||
MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, MatchError,
|
||||
PayloadGetType, PayloadType, RCOptions, RemoteCommand, ResponseType, Window
|
||||
MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, CmdGenerator,
|
||||
MatchError, PayloadGetType, PayloadType, RCOptions, RemoteCommand,
|
||||
ResponseType, Window
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -63,7 +64,7 @@ Do not send text to the active window, even if it is one of the matched windows.
|
||||
limit = 1024
|
||||
ret = {'match': opts.match, 'data': '', 'match_tab': opts.match_tab, 'all': opts.all, 'exclude_active': opts.exclude_active}
|
||||
|
||||
def pipe() -> Generator[Dict, None, None]:
|
||||
def pipe() -> CmdGenerator:
|
||||
if sys.stdin.isatty():
|
||||
ret['exclude_active'] = True
|
||||
import select
|
||||
@@ -90,14 +91,14 @@ Do not send text to the active window, even if it is one of the matched windows.
|
||||
ret['data'] = 'base64:' + base64.standard_b64encode(data).decode('ascii')
|
||||
yield ret
|
||||
|
||||
def chunks(text: str) -> Generator[Dict, None, None]:
|
||||
def chunks(text: str) -> CmdGenerator:
|
||||
data = parse_send_text_bytes(text).decode('utf-8')
|
||||
while data:
|
||||
ret['data'] = 'text:' + data[:limit]
|
||||
yield ret
|
||||
data = data[limit:]
|
||||
|
||||
def file_pipe(path: str) -> Generator[Dict, None, None]:
|
||||
def file_pipe(path: str) -> CmdGenerator:
|
||||
with open(path, 'rb') as f:
|
||||
while True:
|
||||
data = f.read(limit)
|
||||
@@ -116,7 +117,7 @@ Do not send text to the active window, even if it is one of the matched windows.
|
||||
text = ' '.join(args)
|
||||
sources.append(chunks(text))
|
||||
|
||||
def chain() -> Generator[Dict, None, None]:
|
||||
def chain() -> CmdGenerator:
|
||||
for src in sources:
|
||||
yield from src
|
||||
return chain()
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
import imghdr
|
||||
import tempfile
|
||||
from base64 import standard_b64decode, standard_b64encode
|
||||
from typing import IO, TYPE_CHECKING, Dict, Generator, Optional
|
||||
from typing import IO, TYPE_CHECKING, Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from .base import (
|
||||
MATCH_WINDOW_OPTION, ArgsType, Boss, PayloadGetType, PayloadType,
|
||||
RCOptions, RemoteCommand, ResponseType, Window
|
||||
MATCH_WINDOW_OPTION, ArgsType, Boss, CmdGenerator, PayloadGetType,
|
||||
PayloadType, RCOptions, RemoteCommand, ResponseType, Window
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -83,7 +83,7 @@ failed, the command will exit with a success code.
|
||||
if imghdr.what(path) != 'png':
|
||||
self.fatal(f'{path} is not a PNG image')
|
||||
|
||||
def file_pipe(path: str) -> Generator[Dict, None, None]:
|
||||
def file_pipe(path: str) -> CmdGenerator:
|
||||
with open(path, 'rb') as f:
|
||||
while True:
|
||||
data = f.read(512)
|
||||
|
||||
Reference in New Issue
Block a user