From e97afb3433a959a016d8031d4e0d2b071b956825 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Nov 2021 20:40:42 +0530 Subject: [PATCH] Make the repr of SingleKey shorter --- kitty/options/types.py | 22 +++++++++++----------- kitty/types.py | 8 ++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/kitty/options/types.py b/kitty/options/types.py index c45879e4b..e76d07872 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -818,19 +818,19 @@ defaults.map = [ # open_url KeyDefinition(False, (KeyAction('open_url_with_hints'),), 1024, False, 101, ()), # insert_selected_path - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'path', '--program', '-')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=102),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'path', '--program', '-')),), 1024, False, 112, (SingleKey(key=102),)), # open_selected_path - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'path')),), 1024, False, 112, (SingleKey(mods=1, is_native=False, key=102),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'path')),), 1024, False, 112, (SingleKey(mods=1, key=102),)), # insert_selected_line - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'line', '--program', '-')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=108),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'line', '--program', '-')),), 1024, False, 112, (SingleKey(key=108),)), # insert_selected_word - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'word', '--program', '-')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=119),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'word', '--program', '-')),), 1024, False, 112, (SingleKey(key=119),)), # insert_selected_hash - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'hash', '--program', '-')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=104),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'hash', '--program', '-')),), 1024, False, 112, (SingleKey(key=104),)), # goto_file_line - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'linenum')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=110),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'linenum')),), 1024, False, 112, (SingleKey(key=110),)), # open_selected_hyperlink - KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'hyperlink')),), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=121),)), + KeyDefinition(True, (KeyAction('kitten', ('hints', '--type', 'hyperlink')),), 1024, False, 112, (SingleKey(key=121),)), # toggle_fullscreen KeyDefinition(False, (KeyAction('toggle_fullscreen'),), 1024, False, 57374, ()), # toggle_maximized @@ -842,13 +842,13 @@ defaults.map = [ # kitty_shell KeyDefinition(False, (KeyAction('kitty_shell', ('window',)),), 1024, False, 57344, ()), # increase_background_opacity - KeyDefinition(True, (KeyAction('set_background_opacity', ('+0.1',)),), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=109),)), + KeyDefinition(True, (KeyAction('set_background_opacity', ('+0.1',)),), 1024, False, 97, (SingleKey(key=109),)), # decrease_background_opacity - KeyDefinition(True, (KeyAction('set_background_opacity', ('-0.1',)),), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=108),)), + KeyDefinition(True, (KeyAction('set_background_opacity', ('-0.1',)),), 1024, False, 97, (SingleKey(key=108),)), # full_background_opacity - KeyDefinition(True, (KeyAction('set_background_opacity', ('1',)),), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=49),)), + KeyDefinition(True, (KeyAction('set_background_opacity', ('1',)),), 1024, False, 97, (SingleKey(key=49),)), # reset_background_opacity - KeyDefinition(True, (KeyAction('set_background_opacity', ('default',)),), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=100),)), + KeyDefinition(True, (KeyAction('set_background_opacity', ('default',)),), 1024, False, 97, (SingleKey(key=100),)), # reset_terminal KeyDefinition(False, (KeyAction('clear_terminal', ('reset', True)),), 1024, False, 57349, ()), # reload_config_file diff --git a/kitty/types.py b/kitty/types.py index 83d1de6a8..89f9f3031 100644 --- a/kitty/types.py +++ b/kitty/types.py @@ -52,6 +52,14 @@ class SingleKey(NamedTuple): is_native: bool = False key: int = -1 + def __repr__(self) -> str: + kwds = [] + for i, f in enumerate(self._fields): + val = self[i] + if val != self._field_defaults[f]: + kwds.append(f'{f}={val!r}') + return 'SingleKey(' + ', '.join(kwds) + ')' + class MouseEvent(NamedTuple): button: int = 0