DRYer
This commit is contained in:
parent
0f9d6a1e4a
commit
769cd9be3f
@ -10,6 +10,27 @@ from kitty.key_encoding import (
|
|||||||
from kittens.tui.handler import Handler
|
from kittens.tui.handler import Handler
|
||||||
from kittens.tui.loop import Loop
|
from kittens.tui.loop import Loop
|
||||||
|
|
||||||
|
mod_names = {
|
||||||
|
SHIFT: 'Shift',
|
||||||
|
ALT: 'Alt',
|
||||||
|
CTRL: 'Ctrl',
|
||||||
|
SUPER: 'Super',
|
||||||
|
HYPER: 'Hyper',
|
||||||
|
META: 'Meta',
|
||||||
|
NUM_LOCK: 'NumLock',
|
||||||
|
CAPS_LOCK: 'CapsLock',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def format_mods(mods: int) -> str:
|
||||||
|
if not mods:
|
||||||
|
return ''
|
||||||
|
lmods = []
|
||||||
|
for m, name in mod_names.items():
|
||||||
|
if mods & m:
|
||||||
|
lmods.append(name)
|
||||||
|
return '+'.join(lmods)
|
||||||
|
|
||||||
|
|
||||||
class KeysHandler(Handler):
|
class KeysHandler(Handler):
|
||||||
|
|
||||||
@ -24,20 +45,7 @@ class KeysHandler(Handler):
|
|||||||
REPEAT: 'REPEAT',
|
REPEAT: 'REPEAT',
|
||||||
RELEASE: 'RELEASE'
|
RELEASE: 'RELEASE'
|
||||||
}[key_event.type]
|
}[key_event.type]
|
||||||
lmods = []
|
mods = format_mods(key_event.mods)
|
||||||
for m, name in {
|
|
||||||
SHIFT: 'Shift',
|
|
||||||
ALT: 'Alt',
|
|
||||||
CTRL: 'Ctrl',
|
|
||||||
SUPER: 'Super',
|
|
||||||
HYPER: 'Hyper',
|
|
||||||
META: 'Meta',
|
|
||||||
NUM_LOCK: 'NumLock',
|
|
||||||
CAPS_LOCK: 'CapsLock',
|
|
||||||
}.items():
|
|
||||||
if key_event.mods & m:
|
|
||||||
lmods.append(name)
|
|
||||||
mods = '+'.join(lmods)
|
|
||||||
if mods:
|
if mods:
|
||||||
mods += '+'
|
mods += '+'
|
||||||
key = f'{mods}{key_event.key} '
|
key = f'{mods}{key_event.key} '
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user