From e1b454e49e004fa82433a58ad5641ec384e19a86 Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Sat, 15 Mar 2025 13:28:36 +0100 Subject: [PATCH] fix: generate config min contrast --- kitty/options/definition.py | 2 +- kitty/options/parse.py | 25 +++++++------------------ kitty/options/types.py | 2 +- kitty/options/utils.py | 8 ++++++++ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 7a28d1764..feb06e23a 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -265,7 +265,7 @@ and adjust the first parameter until the perceived thickness matches the dark theme. ''') -opt('text_fg_override_threshold', '0 %', option_type='number_with_unit', long_text=''' +opt('text_fg_override_threshold', '0 %', option_type='text_fg_override_threshold', long_text=''' A setting to prevent low contrast scenarios, configurable in two different modes (suffix :code:` %` and suffix :code:` ratio`). The default value is :code:`0`, which means no overriding is performed. Useful when working with applications that use colors that do not contrast well with your preferred color scheme. diff --git a/kitty/options/parse.py b/kitty/options/parse.py index a45b730b4..2f3fcf4a3 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -4,16 +4,8 @@ import typing import collections.abc # noqa: F401, RUF100 from kitty.conf.utils import ( - merge_dicts, - positive_float, - positive_int, - python_string, - number_with_unit, - to_bool, - to_cmdline, - to_color, - to_color_or_none, - unit_float, + merge_dicts, positive_float, positive_int, python_string, to_bool, to_cmdline, to_color, + to_color_or_none, unit_float ) from kitty.options.utils import ( action_alias, active_tab_title_template, allow_hyperlinks, bell_on_tab, box_drawing_scale, @@ -27,10 +19,10 @@ pointer_shape_when_dragging, remote_control_password, resize_debounce_time, scrollback_lines, scrollback_pager_history_size, shell_integration, store_multiple, symbol_map, tab_activity_symbol, tab_bar_edge, tab_bar_margin_height, tab_bar_min_tabs, tab_fade, tab_font_style, tab_separator, - tab_title_template, titlebar_color, to_cursor_shape, to_cursor_unfocused_shape, to_font_size, - to_layout_names, to_modifiers, transparent_background_colors, underline_exclusion, url_prefixes, - url_style, visual_bell_duration, visual_window_select_characters, window_border_width, - window_logo_scale, window_size + tab_title_template, text_fg_override_threshold, titlebar_color, to_cursor_shape, + to_cursor_unfocused_shape, to_font_size, to_layout_names, to_modifiers, + transparent_background_colors, underline_exclusion, url_prefixes, url_style, visual_bell_duration, + visual_window_select_characters, window_border_width, window_logo_scale, window_size ) @@ -1332,10 +1324,7 @@ def text_composition_strategy(self, val: str, ans: dict[str, typing.Any]) -> Non ans['text_composition_strategy'] = str(val) def text_fg_override_threshold(self, val: str, ans: dict[str, typing.Any]) -> None: - value, unit = number_with_unit(val, default_unit='%') - if unit not in ['%', 'ratio']: - raise ValueError(f'The unit {unit} is not a valid choice for text_fg_override_threshold') - ans['text_fg_override_threshold'] = value, unit + ans['text_fg_override_threshold'] = text_fg_override_threshold(val) def touch_scroll_multiplier(self, val: str, ans: dict[str, typing.Any]) -> None: ans['touch_scroll_multiplier'] = float(val) diff --git a/kitty/options/types.py b/kitty/options/types.py index 1fef0f042..1e6aff7df 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -612,7 +612,7 @@ class Options: term: str = 'xterm-kitty' terminfo_type: choices_for_terminfo_type = 'path' text_composition_strategy: str = 'platform' - text_fg_override_threshold: tuple[float, str] = 0.0, '%' + text_fg_override_threshold: tuple[float, str] = (0.0, '%') touch_scroll_multiplier: float = 1.0 transparent_background_colors: tuple[tuple[kitty.fast_data_types.Color, float], ...] = () undercurl_style: choices_for_undercurl_style = 'thin-sparse' diff --git a/kitty/options/utils.py b/kitty/options/utils.py index cf90c7503..91691ab0f 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -26,6 +26,7 @@ KeyAction, KeyFuncWrapper, currently_parsing, + number_with_unit, percent, positive_float, positive_int, @@ -752,6 +753,13 @@ def active_tab_title_template(x: str) -> str | None: return None if x == 'none' else x +def text_fg_override_threshold(x: str) -> tuple[float, str]: + value, unit = number_with_unit(x, default_unit='%') + if unit not in ['%', 'ratio']: + raise ValueError(f'The unit {unit} is not a valid choice for text_fg_override_threshold') + return value, unit + + ClearOn = Literal['next', 'focus'] default_clear_on: tuple[ClearOn, ...] = 'focus', 'next' all_clear_on = get_args(ClearOn)