From 3c3662b032c6cebd666c51c6b6b5774c6fee27ee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Aug 2021 23:18:57 +0530 Subject: [PATCH] Limit display length for theme names --- kittens/themes/collection.py | 4 +++- kittens/themes/main.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kittens/themes/collection.py b/kittens/themes/collection.py index 64081552b..70e404a88 100644 --- a/kittens/themes/collection.py +++ b/kittens/themes/collection.py @@ -264,7 +264,9 @@ class Themes: ans.index_map = self.index_map return ans - def apply_search(self, expression: str, mark_before: str = '\033[32m', mark_after: str = '\033[39m') -> Iterator[str]: + def apply_search( + self, expression: str, mark_before: str = '\033[33m', mark_after: str = '\033[39m' + ) -> Iterator[str]: for k, v in tuple(self.themes.items()): result = match(v.name, expression, mark_before=mark_before, mark_after=mark_after) if result and result[0]: diff --git a/kittens/themes/main.py b/kittens/themes/main.py index d3c6df808..c1deea034 100644 --- a/kittens/themes/main.py +++ b/kittens/themes/main.py @@ -12,7 +12,7 @@ from typing import ( from kitty.cli import create_default_opts from kitty.config import cached_values_for -from kitty.fast_data_types import wcswidth +from kitty.fast_data_types import truncate_point_for_length, wcswidth from kitty.rgb import color_as_sharp, color_from_int from kitty.typing import KeyEventType from kitty.utils import ScreenSize @@ -27,6 +27,13 @@ def format_traceback(msg: str) -> str: return traceback.format_exc() + '\n\n' + styled(msg, fg='red') +def limit_length(text: str, limit: int = 32) -> str: + x = truncate_point_for_length(text, limit - 1) + if x >= len(text): + return text + return text[:x] + '…' + + class State(Enum): fetching = auto() browsing = auto() @@ -89,9 +96,9 @@ class ThemesList: self.themes = self.all_themes = themes if self.current_search: self.themes = self.all_themes.copy() - self.display_strings = tuple(self.themes.apply_search(self.current_search)) + self.display_strings = tuple(map(limit_length, self.themes.apply_search(self.current_search))) else: - self.display_strings = tuple(t.name for t in self.themes) + self.display_strings = tuple(map(limit_length, (t.name for t in self.themes))) self.widths = tuple(map(wcswidth, self.display_strings)) self.max_width = max(self.widths) if self.widths else 0 self.current_idx = 0