kitten_alias is also an is_multiple option

This commit is contained in:
Kovid Goyal
2021-05-26 14:11:40 +05:30
parent 2fd4487922
commit e1cd6b6037
3 changed files with 24 additions and 18 deletions

View File

@@ -23,8 +23,8 @@ from .constants import cache_dir, defconf, is_macos
from .options_stub import Options as OptionsStub
from .options_types import (
FuncArgsType, KeyDefinition, KeyMap, MouseMap, MouseMapping, SequenceMap,
env, font_features, func_with_args, parse_map, parse_key_action,
parse_mouse_map, symbol_map
env, font_features, func_with_args, kitten_alias, parse_key_action,
parse_map, parse_mouse_map, symbol_map
)
from .typing import TypedDict
from .utils import log_error
@@ -390,9 +390,8 @@ def handle_font_features(key: str, val: str, ans: Dict[str, Any]) -> None:
@special_handler
def handle_kitten_alias(key: str, val: str, ans: Dict[str, Any]) -> None:
parts = val.split(maxsplit=2)
if len(parts) >= 2:
ans['kitten_aliases'][parts[0]] = parts[1:]
for k, v in kitten_alias(val):
ans['kitten_alias'][k] = v
@special_handler
@@ -457,7 +456,7 @@ def option_names_for_completion() -> Generator[str, None, None]:
def parse_config(lines: Iterable[str], check_keys: bool = True, accumulate_bad_lines: Optional[List[BadLine]] = None) -> Dict[str, Any]:
ans: Dict[str, Any] = {
'symbol_map': {}, 'keymap': {}, 'sequence_map': {}, 'key_definitions': [],
'env': {}, 'kitten_aliases': {}, 'font_features': {}, 'mouse_mappings': [],
'env': {}, 'kitten_alias': {}, 'font_features': {}, 'mouse_mappings': [],
'mousemap': {}
}
defs: Optional[FrozenSet] = None
@@ -575,11 +574,10 @@ def finalize_keys(opts: OptionsStub) -> None:
defns = []
else:
defns.append(d)
kitten_aliases: List[Dict[str, Sequence[str]]] = getattr(opts, 'kitten_aliases')
for d in defns:
d.resolve(opts.kitty_mod)
if kitten_aliases and d.action.func == 'kitten':
d.resolve_kitten_aliases(kitten_aliases)
if opts.kitten_alias and d.action.func == 'kitten':
d.resolve_kitten_aliases(opts.kitten_alias)
keymap: KeyMap = {}
sequence_map: SequenceMap = {}
@@ -611,7 +609,7 @@ def finalize_mouse_mappings(opts: OptionsStub) -> None:
defns = []
else:
defns.append(d)
kitten_aliases: List[Dict[str, Sequence[str]]] = getattr(opts, 'kitten_aliases')
kitten_aliases: List[Dict[str, Sequence[str]]] = getattr(opts, 'kitten_alias')
for d in defns:
d.resolve(opts.kitty_mod)
if kitten_aliases and d.action.func == 'kitten':
@@ -635,7 +633,7 @@ def load_config(*paths: str, overrides: Optional[Iterable[str]] = None, accumula
finalize_keys(opts)
finalize_mouse_mappings(opts)
# delete no longer needed definitions, replacing with empty placeholders
setattr(opts, 'kitten_aliases', {})
setattr(opts, 'kitten_alias', {})
setattr(opts, 'mouse_mappings', [])
setattr(opts, 'key_definitions', [])
if opts.background_opacity < 1.0 and opts.macos_titlebar_color:

View File

@@ -18,12 +18,13 @@ from .options_types import (
allow_remote_control, box_drawing_scale, clipboard_control,
config_or_absolute_path, copy_on_select, cursor_text_color,
default_tab_separator, disable_ligatures, edge_width, env, font_features,
hide_window_decorations, macos_option_as_alt, macos_titlebar_color,
optional_edge_width, resize_draw_strategy, scrollback_lines,
scrollback_pager_history_size, symbol_map, tab_activity_symbol,
tab_bar_edge, tab_bar_min_tabs, tab_fade, tab_font_style, tab_separator,
tab_title_template, to_cursor_shape, to_font_size, to_layout_names,
to_modifiers, url_prefixes, url_style, window_border_width, window_size
hide_window_decorations, kitten_alias, macos_option_as_alt,
macos_titlebar_color, optional_edge_width, resize_draw_strategy,
scrollback_lines, scrollback_pager_history_size, symbol_map,
tab_activity_symbol, tab_bar_edge, tab_bar_min_tabs, tab_fade,
tab_font_style, tab_separator, tab_title_template, to_cursor_shape,
to_font_size, to_layout_names, to_modifiers, url_prefixes, url_style,
window_border_width, window_size
)
from .rgb import color_as_sharp, color_from_int
@@ -1068,7 +1069,7 @@ o('clear_all_shortcuts', False, long_text=_('''
You can have kitty remove all shortcut definition seen up to this point. Useful, for
instance, to remove the default shortcuts.'''))
o('kitten_alias', 'hints hints --hints-offset=0', add_to_default=False, long_text=_('''
o('+kitten_alias', 'hints hints --hints-offset=0', option_type=kitten_alias, add_to_default=False, long_text=_('''
You can create aliases for kitten names, this allows overriding the defaults
for kitten options and can also be used to shorten repeated mappings of the same
kitten with a specific group of options. For example, the above alias

View File

@@ -389,6 +389,13 @@ def env(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, str]]:
yield key, expandvars(val, current_val)
def kitten_alias(val: str) -> Iterable[Tuple[str, List[str]]]:
parts = val.split(maxsplit=2)
if len(parts) >= 2:
name = parts.pop(0)
yield name, parts
def symbol_map(val: str) -> Iterable[Tuple[Tuple[int, int], str]]:
parts = val.split()