diff --git a/kittens/diff/collect.py b/kittens/diff/collect.py index 329833207..1f9808043 100644 --- a/kittens/diff/collect.py +++ b/kittens/diff/collect.py @@ -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) diff --git a/kittens/diff/config_data.py b/kittens/diff/config_data.py index 9bdbf3f60..502ed4a37 100644 --- a/kittens/diff/config_data.py +++ b/kittens/diff/config_data.py @@ -3,18 +3,17 @@ # License: GPL v3 Copyright: 2018, Kovid Goyal +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)} diff --git a/kittens/diff/diff_speedup.pyi b/kittens/diff/diff_speedup.pyi new file mode 100644 index 000000000..9a7a0927d --- /dev/null +++ b/kittens/diff/diff_speedup.pyi @@ -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 diff --git a/kittens/diff/highlight.py b/kittens/diff/highlight.py index 2bd02c4c9..0de0e9b1a 100644 --- a/kittens/diff/highlight.py +++ b/kittens/diff/highlight.py @@ -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 diff --git a/kittens/tui/operations.py b/kittens/tui/operations.py index 5e711b344..8d7d6e4a3 100644 --- a/kittens/tui/operations.py +++ b/kittens/tui/operations.py @@ -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 diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 4c02b5990..d10cc8fda 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -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__( diff --git a/kitty/screen.c b/kitty/screen.c index d5d5a4a4a..9cceb5c28 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -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);