Add tests for event type reporting
This commit is contained in:
parent
5498f4e526
commit
753ad68ca9
@ -114,16 +114,18 @@ Event types
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
There are three key event types: ``press, repeat and release``. They are
|
||||
reported (if requested) as a sub-field of the modifiers field (separated by a
|
||||
colon). If no modifiers are present, the modifiers field must have the value
|
||||
``1`` and the event type sub-field the type of event. The ``press`` event type
|
||||
has value ``1`` and is the default if no event type sub field is present. The
|
||||
``repeat`` type is ``2`` and the ``release`` type is ``3``. So for example::
|
||||
reported (if requested ``0b10``) as a sub-field of the modifiers field
|
||||
(separated by a colon). If no modifiers are present, the modifiers field must
|
||||
have the value ``1`` and the event type sub-field the type of event. The
|
||||
``press`` event type has value ``1`` and is the default if no event type sub
|
||||
field is present. The ``repeat`` type is ``2`` and the ``release`` type is
|
||||
``3``. So for example::
|
||||
|
||||
CSI key-code;1 # this is a press event
|
||||
CSI key-code;1:1 # this is a press event
|
||||
CSI key-code;1:2 # this is a repeat event
|
||||
CSI key-code:1:3 # this is a release event
|
||||
CSI key-code # this is a press event
|
||||
CSI key-code;modifier # this is a press event
|
||||
CSI key-code;modifier:1 # this is a press event
|
||||
CSI key-code;modifier:2 # this is a repeat event
|
||||
CSI key-code:modifier:3 # this is a release event
|
||||
|
||||
|
||||
.. note:: Key events that result in text are reported as plain UTF-8 text, so
|
||||
|
||||
@ -53,6 +53,7 @@ init_encoding_data(EncodingData *ans, const KeyEvent *ev) {
|
||||
ans->has_mods = ev->mods.encoded[0] && ev->mods.encoded[0] != '1';
|
||||
ans->add_alternates = ev->report_alternate_key && (ev->shifted_key > 0 || ev->alternate_key > 0);
|
||||
if (ans->add_alternates) { ans->shifted_key = ev->shifted_key; ans->alternate_key = ev->alternate_key; }
|
||||
ans->action = ev->action;
|
||||
ans->key = ev->key;
|
||||
memcpy(ans->encoded_mods, ev->mods.encoded, sizeof(ans->encoded_mods));
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@ class TestKeys(BaseTest):
|
||||
shift, alt, ctrl, super = defines.GLFW_MOD_SHIFT, defines.GLFW_MOD_ALT, defines.GLFW_MOD_CONTROL, defines.GLFW_MOD_SUPER # noqa
|
||||
press, repeat, release = defines.GLFW_PRESS, defines.GLFW_REPEAT, defines.GLFW_RELEASE # noqa
|
||||
|
||||
def csi(mods=0, num=1, trailer='u'):
|
||||
def csi(mods=0, num=1, action=1, trailer='u'):
|
||||
ans = '\033['
|
||||
if isinstance(num, str):
|
||||
num = ord(num)
|
||||
if num != 1 or mods:
|
||||
ans += f'{num}'
|
||||
if mods:
|
||||
if mods or action > 1:
|
||||
m = 0
|
||||
if mods & shift:
|
||||
m |= 1
|
||||
@ -30,6 +32,8 @@ class TestKeys(BaseTest):
|
||||
if mods & super:
|
||||
m |= 8
|
||||
ans += f';{m+1}'
|
||||
if action > 1:
|
||||
ans += f':{action}'
|
||||
return ans + trailer
|
||||
|
||||
def mods_test(key, plain=None, shift=None, ctrl=None, alt=None, calt=None, cshift=None, ashift=None, csi_num=None, trailer='u'):
|
||||
@ -390,7 +394,14 @@ class TestKeys(BaseTest):
|
||||
ae(dq(k), csi(num=k))
|
||||
ae(dq(k, mods=ctrl), csi(ctrl, num=k))
|
||||
ae(dq(defines.GLFW_FKEY_UP), '\x1b[A')
|
||||
ae(dq(defines.GLFW_FKEY_UP, mods=ctrl), csi(ctrl, 1, 'A'))
|
||||
ae(dq(defines.GLFW_FKEY_UP, mods=ctrl), csi(ctrl, 1, trailer='A'))
|
||||
|
||||
# test event type reporting
|
||||
tq = partial(enc, key_encoding_flags=0b10)
|
||||
ae(tq(ord('a')), 'a')
|
||||
ae(tq(ord('a'), action=defines.GLFW_REPEAT), csi(num='a', action=2))
|
||||
ae(tq(ord('a'), action=defines.GLFW_RELEASE), csi(num='a', action=3))
|
||||
ae(tq(ord('a'), action=defines.GLFW_RELEASE, mods=shift), csi(shift, num='a', action=3))
|
||||
|
||||
def test_encode_mouse_event(self):
|
||||
NORMAL_PROTOCOL, UTF8_PROTOCOL, SGR_PROTOCOL, URXVT_PROTOCOL = range(4)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user