No top level typing issues for kittens

This commit is contained in:
Kovid Goyal 2020-03-04 07:49:28 +05:30
parent c9ce2f47dc
commit 36eb52424f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 42 additions and 20 deletions

View File

@ -4,12 +4,13 @@
import os
import re
from contextlib import suppress
from functools import lru_cache
from hashlib import md5
from mimetypes import guess_type
from contextlib import suppress
from typing import Dict
path_name_map = {}
path_name_map: Dict[str, str] = {}
class Segment:
@ -146,13 +147,17 @@ def data_for_path(path):
return ans
@lru_cache(maxsize=1024)
def lines_for_path(path):
data = data_for_path(path).replace('\t', lines_for_path.replace_tab_by)
return tuple(sanitize(data).splitlines())
class LinesForPath:
replace_tab_by = ' ' * 4
@lru_cache(maxsize=1024)
def __call__(self, path):
data = data_for_path(path).replace('\t', self.replace_tab_by)
return tuple(sanitize(data).splitlines())
lines_for_path.replace_tab_by = ' ' * 4
lines_for_path = LinesForPath()
@lru_cache(maxsize=1024)

View File

@ -3,18 +3,17 @@
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
from functools import partial
# Utils {{{
from gettext import gettext as _
from functools import partial
from typing import Dict, Union
from kitty.conf.definition import option_func
from kitty.conf.utils import (
positive_int, python_string, to_color
)
from kitty.conf.definition import Option, Shortcut, option_func
from kitty.conf.utils import positive_int, python_string, to_color
# }}}
all_options = {}
all_options: Dict[str, Union[Option, Shortcut]] = {}
o, k, g, all_groups = option_func(all_options, {
'colors': [_('Colors')],
'diff': [_('Diffing'), ],
@ -121,4 +120,4 @@ k('prev_match', '<', 'scroll_to prev-match', _('Scroll to previous search match'
k('search_forward_simple', 'f', 'start_search substring forward', _('Search forward (no regex)'))
k('search_backward_simple', 'b', 'start_search substring backward', _('Search backward (no regex)'))
type_map = {o.name: o.option_type for o in all_options.values() if hasattr(o, 'option_type')}
type_map = {o.name: o.option_type for o in all_options.values() if isinstance(o, Option)}

View File

@ -0,0 +1,14 @@
from typing import List, Optional, Tuple
from .collect import Segment
def split_with_highlights(
line: str, truncate_points: List[int], fg_highlights: List,
bg_highlight: Optional[Segment]
) -> List:
pass
def changed_center(left_prefix: str, right_postfix: str) -> Tuple[int, int]:
pass

View File

@ -6,10 +6,10 @@ import concurrent
import os
import re
from pygments import highlight
from pygments.formatter import Formatter
from pygments.lexers import get_lexer_for_filename
from pygments.util import ClassNotFound
from pygments import highlight # type: ignore
from pygments.formatter import Formatter # type: ignore
from pygments.lexers import get_lexer_for_filename # type: ignore
from pygments.util import ClassNotFound # type: ignore
from kitty.rgb import color_as_sgr, parse_sharp

View File

@ -71,7 +71,7 @@ def set_line_wrapping(yes_or_no: bool) -> str:
def set_cursor_visible(yes_or_no: bool) -> str:
return set_mode('DECTEM') if yes_or_no else reset_mode('DECTCEM')
return set_mode('DECTCEM') if yes_or_no else reset_mode('DECTCEM')
def set_cursor_position(x, y) -> str: # (0, 0) is top left

View File

@ -719,6 +719,10 @@ def set_window_render_data(
pass
def truncate_point_for_length(text: str, num_cells: int, start_pos: int = 0) -> int:
pass
class ChildMonitor:
def __init__(

View File

@ -1866,7 +1866,7 @@ screen_wcswidth(PyObject UNUSED *self, PyObject *str) {
static PyObject*
screen_truncate_point_for_length(PyObject UNUSED *self, PyObject *args) {
PyObject *str; unsigned int num_cells, start_pos = 0;
if (!PyArg_ParseTuple(args, "OI|I", &str, &num_cells, &start_pos)) return NULL;
if (!PyArg_ParseTuple(args, "UI|I", &str, &num_cells, &start_pos)) return NULL;
if (PyUnicode_READY(str) != 0) return NULL;
int kind = PyUnicode_KIND(str);
void *data = PyUnicode_DATA(str);