Nicer fix for human_repr of keys defined with kitty_mod

This commit is contained in:
Kovid Goyal
2022-08-12 12:37:15 +05:30
parent ce91b6d9d9
commit 63fa0c4e94
4 changed files with 36 additions and 30 deletions

View File

@@ -51,8 +51,7 @@ class SignalInfo(NamedTuple):
sival_ptr: int
def mod_to_names(mods: int, kitty_mod: int = 0) -> Iterator[str]:
has_kitty_mod = kitty_mod and (mods & kitty_mod) == kitty_mod
def mod_to_names(mods: int, has_kitty_mod: bool = False, kitty_mod: int = 0) -> Iterator[str]:
if has_kitty_mod:
mods &= ~kitty_mod
yield 'kitty_mod'
@@ -61,13 +60,22 @@ def mod_to_names(mods: int, kitty_mod: int = 0) -> Iterator[str]:
yield name
def human_repr_of_single_key(self: 'SingleKey', kitty_mod: int) -> str:
from .fast_data_types import glfw_get_key_name
names = []
names = list(mod_to_names(self.mods, self.defined_with_kitty_mod, kitty_mod))
if self.key > 0:
kname = (glfw_get_key_name(0, self.key) if self.is_native else glfw_get_key_name(self.key, 0)) or f'{self.key}'
kname = {' ': 'space'}.get(kname, kname)
names.append(kname)
return '+'.join(names)
class Shortcut(NamedTuple):
keys: Tuple['SingleKey', ...]
kitty_mod: int = 0
@property
def human_repr(self) -> str:
return ' > '.join(k.human_repr_with_kitty_mod(self.kitty_mod) for k in self.keys)
def human_repr(self, kitty_mod: int = 0) -> str:
return ' > '.join(human_repr_of_single_key(k, kitty_mod) for k in self.keys)
class MouseEvent(NamedTuple):
@@ -76,8 +84,7 @@ class MouseEvent(NamedTuple):
repeat_count: int = 1
grabbed: bool = False
@property
def human_repr(self) -> str:
def human_repr(self, kitty_mod: int = 0) -> str:
from .options.utils import mouse_button_map, mouse_trigger_count_map
def mouse_button_num_to_name(num: int) -> str: