Cleanup previous PR

This commit is contained in:
Kovid Goyal
2026-03-25 09:23:29 +05:30
parent 95ca222eba
commit 0ddad7474b
9 changed files with 44 additions and 39 deletions

View File

@@ -714,11 +714,11 @@ a double backslash.
'''
)
opt('show_hyperlink_targets', 'never', choices=('ctrl', 'cmd', 'shift', 'always', 'never'),
opt('show_hyperlink_targets', 'never', option_type='show_hyperlink_targets',
ctype='show_hyperlink_targets',
long_text='''
When the mouse hovers over a terminal hyperlink, show the actual URL that will
be activated when the hyperlink is clicked. Set to :code:`ctrl`, :code:`cmd` or
be activated when the hyperlink is clicked. Set to :code:`ctrl`, :code:`cmd`, :code:`alt` or
:code:`shift` to show only while the corresponding modifier key is pressed
(:kbd:`Ctrl`, :kbd:`Super` (macOS :kbd:`Cmd`), :kbd:`Shift`). If multiple modifiers
are pressed, the URL is shown as long as the configured modifier is among them.

15
kitty/options/parse.py generated
View File

@@ -18,8 +18,8 @@ from kitty.options.utils import (
mouse_hide_wait, narrow_symbols, notify_on_cmd_finish, optional_edge_width, parse_font_spec,
parse_map, parse_mouse_map, paste_actions, pointer_shape_when_dragging, remote_control_password,
resize_debounce_time, scrollback_lines, scrollback_pager_history_size, scrollbar_color,
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,
shell_integration, show_hyperlink_targets, 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, 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,
@@ -1290,16 +1290,7 @@ class Parser:
ans['shell_integration'] = shell_integration(val)
def show_hyperlink_targets(self, val: str, ans: dict[str, typing.Any]) -> None:
val = val.lower()
if val == 'yes':
val = 'always'
elif val == 'no':
val = 'never'
if val not in self.choices_for_show_hyperlink_targets:
raise ValueError(f"The value {val} is not a valid choice for show_hyperlink_targets")
ans["show_hyperlink_targets"] = val
choices_for_show_hyperlink_targets = frozenset(('ctrl', 'cmd', 'shift', 'always', 'never'))
ans['show_hyperlink_targets'] = show_hyperlink_targets(val)
def single_window_margin_width(self, val: str, ans: dict[str, typing.Any]) -> None:
ans['single_window_margin_width'] = optional_edge_width(val)

View File

@@ -102,11 +102,13 @@ static inline ShowHyperlinkTargets
show_hyperlink_targets(PyObject *x) {
const char *in = PyUnicode_AsUTF8(x);
if (!in) return SHOW_HYPERLINK_TARGETS_NEVER;
if (strcmp(in, "always") == 0) return SHOW_HYPERLINK_TARGETS_ALWAYS;
if (strcmp(in, "ctrl") == 0) return SHOW_HYPERLINK_TARGETS_CTRL;
if (strcmp(in, "shift") == 0) return SHOW_HYPERLINK_TARGETS_SHIFT;
if (strcmp(in, "cmd") == 0) return SHOW_HYPERLINK_TARGETS_CMD;
return SHOW_HYPERLINK_TARGETS_NEVER;
switch(in[0]) {
case 'a': return SHOW_HYPERLINK_TARGETS_ALWAYS;
case 'A': return SHOW_HYPERLINK_TARGETS_ALT;
case 'C': return SHOW_HYPERLINK_TARGETS_CTRL;
case 'S': return in[1] == 'u' ? SHOW_HYPERLINK_TARGETS_SUPER : SHOW_HYPERLINK_TARGETS_SHIFT;
default: return SHOW_HYPERLINK_TARGETS_NEVER;
}
}
static inline BackgroundImageLayout

View File

@@ -28,7 +28,6 @@ choices_for_macos_show_window_title_in = typing.Literal['all', 'menubar', 'none'
choices_for_placement_strategy = typing.Literal['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']
choices_for_pointer_shape_when_grabbed = choices_for_default_pointer_shape
choices_for_scrollbar = typing.Literal['scrolled', 'always', 'never', 'hovered', 'scrolled-and-hovered']
choices_for_show_hyperlink_targets = typing.Literal['ctrl', 'cmd', 'shift', 'always', 'never']
choices_for_strip_trailing_spaces = typing.Literal['always', 'never', 'smart']
choices_for_tab_bar_align = typing.Literal['left', 'center', 'right']
choices_for_tab_bar_style = typing.Literal['fade', 'hidden', 'powerline', 'separator', 'slant', 'custom']
@@ -647,7 +646,7 @@ class Options:
selection_foreground: kitty.fast_data_types.Color | None = Color(0, 0, 0)
shell: str = '.'
shell_integration: frozenset[str] = frozenset({'enabled'})
show_hyperlink_targets: choices_for_show_hyperlink_targets = 'never'
show_hyperlink_targets: typing.Literal['never', 'always', 'Ctrl', 'Shift', 'Super', 'Alt'] = 'never'
single_window_margin_width: FloatEdges = FloatEdges(left=-1.0, top=-1.0, right=-1.0, bottom=-1.0)
single_window_padding_width: FloatEdges = FloatEdges(left=-1.0, top=-1.0, right=-1.0, bottom=-1.0)
startup_session: str | None = None
@@ -1150,4 +1149,4 @@ special_colors = frozenset({
})
secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass')
secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass')

View File

@@ -601,6 +601,24 @@ def url_prefixes(x: str) -> tuple[str, ...]:
return tuple(a.lower() for a in x.replace(',', ' ').split())
def show_hyperlink_targets(x: str) -> Literal['never', 'always', 'Ctrl', 'Shift', 'Super', 'Alt']:
q = x.lower()
if q in ('never', 'n', 'no', 'false'):
return 'never'
if q in ('y', 'yes', 'true', 'always'):
return 'always'
if q == 'ctrl':
return 'Ctrl'
if q == 'shift':
return 'Shift'
if q in ('super', 'cmd'):
return 'Super'
if q in ('alt', 'meta'):
return 'Alt'
raise KeyError(f'Unknown value for show_hyperlink_targets: {x!r}')
def copy_on_select(raw: str) -> str:
q = raw.lower()
# boolean values special cased for backwards compat