mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-11 01:28:19 +03:00
Add tests for encode/decode roundtripping
This commit is contained in:
parent
c12680895e
commit
cf04a5a036
5
kitty/key_encoding.py
generated
5
kitty/key_encoding.py
generated
@ -315,7 +315,10 @@ def encode_key_event(key_event: KeyEvent) -> str:
|
|||||||
shifted_key = csi_number_for_name(key_event.shifted_key)
|
shifted_key = csi_number_for_name(key_event.shifted_key)
|
||||||
alternate_key = csi_number_for_name(key_event.alternate_key)
|
alternate_key = csi_number_for_name(key_event.alternate_key)
|
||||||
lt = get_csi_number_to_letter_trailer_map()
|
lt = get_csi_number_to_letter_trailer_map()
|
||||||
trailer = lt.get(key, 'u')
|
if key_event.key == 'ENTER':
|
||||||
|
trailer = 'u'
|
||||||
|
else:
|
||||||
|
trailer = lt.get(key, 'u')
|
||||||
if trailer != 'u':
|
if trailer != 'u':
|
||||||
key = 1
|
key = 1
|
||||||
mods = key_event.mods
|
mods = key_event.mods
|
||||||
|
@ -3,7 +3,12 @@
|
|||||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import kitty.fast_data_types as defines
|
import kitty.fast_data_types as defines
|
||||||
|
from kitty.key_encoding import (
|
||||||
|
EventType, KeyEvent, decode_key_event, encode_key_event
|
||||||
|
)
|
||||||
|
|
||||||
from . import BaseTest
|
from . import BaseTest
|
||||||
|
|
||||||
|
|
||||||
@ -447,6 +452,21 @@ class TestKeys(BaseTest):
|
|||||||
ae(eq(ord('a'), mods=shift, text='A'), csi(shift, num='a', text='A'))
|
ae(eq(ord('a'), mods=shift, text='A'), csi(shift, num='a', text='A'))
|
||||||
ae(eq(ord('a'), mods=shift, text='AB'), csi(shift, num='a', text='AB'))
|
ae(eq(ord('a'), mods=shift, text='AB'), csi(shift, num='a', text='AB'))
|
||||||
|
|
||||||
|
# test roundtripping via KeyEvent
|
||||||
|
for mods in range(16):
|
||||||
|
for action in EventType:
|
||||||
|
for key in ('ENTER', 'a', 'TAB', 'F3'):
|
||||||
|
for shifted_key in ('', 'X'):
|
||||||
|
for alternate_key in ('', 'Y'):
|
||||||
|
for text in ('', 'moose'):
|
||||||
|
ev = KeyEvent(
|
||||||
|
type=action, mods=mods, key=key, text=text, shifted_key=shifted_key, alternate_key=alternate_key,
|
||||||
|
shift=bool(mods & 1), alt=bool(mods & 2), ctrl=bool(mods & 4), super=bool(mods & 8)
|
||||||
|
)
|
||||||
|
ec = encode_key_event(ev)
|
||||||
|
q = decode_key_event(ec[2:-1], ec[-1])
|
||||||
|
self.ae(ev, q)
|
||||||
|
|
||||||
def test_encode_mouse_event(self):
|
def test_encode_mouse_event(self):
|
||||||
NORMAL_PROTOCOL, UTF8_PROTOCOL, SGR_PROTOCOL, URXVT_PROTOCOL = range(4)
|
NORMAL_PROTOCOL, UTF8_PROTOCOL, SGR_PROTOCOL, URXVT_PROTOCOL = range(4)
|
||||||
L, M, R = 1, 2, 3
|
L, M, R = 1, 2, 3
|
||||||
|
Loading…
Reference in New Issue
Block a user