More typing work
This commit is contained in:
parent
308d171dae
commit
9b973ef99c
@ -9,7 +9,7 @@ import re
|
||||
from contextlib import suppress
|
||||
from functools import partial
|
||||
from gettext import gettext as _
|
||||
from typing import Dict, Optional
|
||||
from typing import Optional
|
||||
from weakref import WeakValueDictionary
|
||||
|
||||
from .child import cached_process_data, cwd_of_process
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import re
|
||||
from functools import partial
|
||||
from typing import (
|
||||
Any, Dict, Iterator, List, Optional, Set, Tuple, Union, get_type_hints
|
||||
Any, Dict, Iterable, List, Optional, Set, Tuple, Union, get_type_hints
|
||||
)
|
||||
|
||||
from .utils import to_bool
|
||||
@ -160,7 +160,7 @@ def remove_markup(text):
|
||||
return re.sub(r':([a-zA-Z0-9]+):`(.+?)`', sub, text, flags=re.DOTALL)
|
||||
|
||||
|
||||
def iter_blocks(lines: Iterator[str]):
|
||||
def iter_blocks(lines: Iterable[str]):
|
||||
current_block: List[str] = []
|
||||
prev_indent = 0
|
||||
for line in lines:
|
||||
@ -204,7 +204,7 @@ def render_block(text):
|
||||
return '\n'.join(wrapped_block(lines))
|
||||
|
||||
|
||||
def as_conf_file(all_options):
|
||||
def as_conf_file(all_options: Iterable[Union[Option, Shortcut]]) -> List[str]:
|
||||
ans = ['# vim:fileencoding=utf-8:ft=conf:foldmethod=marker', '']
|
||||
a = ans.append
|
||||
current_group: Optional[Group] = None
|
||||
@ -272,14 +272,16 @@ def as_conf_file(all_options):
|
||||
num_open_folds -= 1
|
||||
|
||||
map_groups = []
|
||||
start = count = None
|
||||
start: Optional[int] = None
|
||||
count: Optional[int] = None
|
||||
for i, line in enumerate(ans):
|
||||
if line.startswith('map '):
|
||||
if start is None:
|
||||
start = i
|
||||
count = 1
|
||||
else:
|
||||
count += 1
|
||||
if count is not None:
|
||||
count += 1
|
||||
else:
|
||||
if start is not None and count is not None:
|
||||
map_groups.append((start, count))
|
||||
@ -310,8 +312,8 @@ def config_lines(all_options):
|
||||
def as_type_stub(
|
||||
all_options: Dict[str, Union[Option, List[Shortcut]]],
|
||||
special_types: Optional[Dict[str, str]] = None,
|
||||
preamble_lines: Union[Tuple[str, ...], List[str], Iterator[str]] = (),
|
||||
extra_fields: Union[Tuple[Tuple[str, str], ...], List[Tuple[str, str]], Iterator[Tuple[str, str]]] = (),
|
||||
preamble_lines: Union[Tuple[str, ...], List[str], Iterable[str]] = (),
|
||||
extra_fields: Union[Tuple[Tuple[str, str], ...], List[Tuple[str, str]], Iterable[Tuple[str, str]]] = (),
|
||||
class_name: str = 'Options'
|
||||
) -> str:
|
||||
ans = ['import typing\n'] + list(preamble_lines) + ['', 'class {}:'.format(class_name)]
|
||||
@ -329,6 +331,7 @@ def as_type_stub(
|
||||
ans.append(' {}: {}'.format(field_name, type_def))
|
||||
ans.append(' def __iter__(self): pass')
|
||||
ans.append(' def __len__(self): pass')
|
||||
ans.append(' def _replace(self, **kw) -> {}: pass'.format(class_name))
|
||||
return '\n'.join(ans) + '\n\n\n'
|
||||
|
||||
|
||||
|
||||
@ -737,6 +737,14 @@ def ring_bell() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def concat_cells(cell_width: int, cell_height: int, is_32_bit: bool, cells: Tuple[bytes, ...]) -> bytes:
|
||||
pass
|
||||
|
||||
|
||||
def current_fonts() -> Dict[str, Any]:
|
||||
pass
|
||||
|
||||
|
||||
def remove_window(os_window_id: int, tab_id: int, window_id: int) -> None:
|
||||
pass
|
||||
|
||||
@ -820,7 +828,9 @@ def parse_input_from_terminal(
|
||||
|
||||
|
||||
class Line:
|
||||
pass
|
||||
|
||||
def sprite_at(self, cell: int) -> Tuple[int, int, int]:
|
||||
pass
|
||||
|
||||
|
||||
def test_shape(line: Line,
|
||||
@ -838,7 +848,7 @@ def sprite_map_set_limits(w: int, h: int) -> None:
|
||||
|
||||
|
||||
def set_send_sprite_to_gpu(
|
||||
func: Callable[[int, int, int, bytes], None]
|
||||
func: Optional[Callable[[int, int, int, bytes], None]]
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
@ -908,6 +918,12 @@ class Screen:
|
||||
):
|
||||
pass
|
||||
|
||||
def line(self, int) -> Line:
|
||||
pass
|
||||
|
||||
def draw(self, text) -> None:
|
||||
pass
|
||||
|
||||
def copy_colors_from(self, other: 'Screen') -> None:
|
||||
pass
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import ctypes
|
||||
import sys
|
||||
from functools import partial
|
||||
from math import ceil, cos, floor, pi
|
||||
from typing import Any, List, Tuple
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from kitty.config import defaults
|
||||
from kitty.constants import is_macos
|
||||
@ -16,6 +16,7 @@ from kitty.fast_data_types import (
|
||||
test_render_line, test_shape
|
||||
)
|
||||
from kitty.fonts.box_drawing import render_box_char, render_missing_glyph
|
||||
from kitty.options_stub import Options as OptionsStub
|
||||
from kitty.utils import log_error
|
||||
|
||||
if is_macos:
|
||||
@ -26,7 +27,7 @@ else:
|
||||
current_faces: List[Tuple[Any, bool, bool]] = []
|
||||
|
||||
|
||||
def coalesce_symbol_maps(maps):
|
||||
def coalesce_symbol_maps(maps: Dict[Tuple[int, int], str]) -> Dict[Tuple[int, int], str]:
|
||||
if not maps:
|
||||
return maps
|
||||
items = tuple((k, maps[k]) for k in sorted(maps))
|
||||
@ -47,9 +48,9 @@ def coalesce_symbol_maps(maps):
|
||||
return dict(ans)
|
||||
|
||||
|
||||
def create_symbol_map(opts):
|
||||
def create_symbol_map(opts: OptionsStub) -> Tuple[Tuple[int, int, int], ...]:
|
||||
val = coalesce_symbol_maps(opts.symbol_map)
|
||||
family_map = {}
|
||||
family_map: Dict[str, int] = {}
|
||||
count = 0
|
||||
for family in val.values():
|
||||
if family not in family_map:
|
||||
@ -284,11 +285,11 @@ def render_string(text, family='monospace', size=11.0, dpi=96.0):
|
||||
for i in reversed(range(s.columns)):
|
||||
sp = list(line.sprite_at(i))
|
||||
sp[2] &= 0xfff
|
||||
sp = tuple(sp)
|
||||
if sp == (0, 0, 0) and not found_content:
|
||||
tsp = tuple(sp)
|
||||
if tsp == (0, 0, 0) and not found_content:
|
||||
continue
|
||||
found_content = True
|
||||
cells.append(sprites[sp])
|
||||
cells.append(sprites[tsp])
|
||||
return cell_width, cell_height, list(reversed(cells))
|
||||
|
||||
|
||||
@ -305,11 +306,11 @@ def display_bitmap(rgb_data, width, height):
|
||||
from kittens.icat.main import detect_support, show
|
||||
if not hasattr(display_bitmap, 'detected') and not detect_support():
|
||||
raise SystemExit('Your terminal does not support the graphics protocol')
|
||||
display_bitmap.detected = True
|
||||
setattr(display_bitmap, 'detected', True)
|
||||
with NamedTemporaryFile(suffix='.rgba', delete=False) as f:
|
||||
f.write(rgb_data)
|
||||
assert len(rgb_data) == 4 * width * height
|
||||
show(f.name, width, height, 32, align='left')
|
||||
show(f.name, width, height, 0, 32, align='left')
|
||||
|
||||
|
||||
def test_render_string(text='Hello, world!', family='monospace', size=64.0, dpi=96.0):
|
||||
@ -329,9 +330,12 @@ def test_render_string(text='Hello, world!', family='monospace', size=64.0, dpi=
|
||||
print('\n')
|
||||
|
||||
|
||||
def test_fallback_font(qtext=None, bold=False, italic=False):
|
||||
def test_fallback_font(qtext: Optional[str] = None, bold=False, italic=False):
|
||||
with setup_for_testing():
|
||||
trials = (qtext,) if qtext else ('你', 'He\u0347\u0305', '\U0001F929')
|
||||
if qtext:
|
||||
trials = [qtext]
|
||||
else:
|
||||
trials = ['你', 'He\u0347\u0305', '\U0001F929']
|
||||
for text in trials:
|
||||
f = get_fallback_font(text, bold, italic)
|
||||
try:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user