mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Key encoding: in legacy mode use legacy encoding for a few more combinations
Some legacy terminal applications get confused seeing CSI u escape codes. Since it is relatively common to press ctrl or shift and space/enter/tab/backspace, emit the same bytes as traditional terminals do for these common keys.
This commit is contained in:
@@ -60,29 +60,32 @@ class TestKeys(BaseTest):
|
||||
|
||||
def a(a, b):
|
||||
ae(a, b, f"{a.encode('ascii')} != {b.encode('ascii')}")
|
||||
a(e(), plain or c())
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT), shift or c(defines.GLFW_MOD_SHIFT))
|
||||
a(e(mods=defines.GLFW_MOD_CONTROL), ctrl or c(defines.GLFW_MOD_CONTROL))
|
||||
a(e(mods=defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL), calt or c(defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL))
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_CONTROL), cshift or c(defines.GLFW_MOD_CONTROL | defines.GLFW_MOD_SHIFT))
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT), ashift or c(defines.GLFW_MOD_ALT | defines.GLFW_MOD_SHIFT))
|
||||
|
||||
mods_test(defines.GLFW_FKEY_ENTER, '\x0d', alt='\033\x0d', csi_num=ord('\r'))
|
||||
mods_test(defines.GLFW_FKEY_KP_ENTER, '\x0d', alt='\033\x0d', csi_num=ord('\r'))
|
||||
mods_test(defines.GLFW_FKEY_ESCAPE, '\x1b', alt='\033\033', csi_num=27)
|
||||
mods_test(defines.GLFW_FKEY_BACKSPACE, '\x7f', alt='\033\x7f', ctrl='\x08', csi_num=127)
|
||||
mods_test(defines.GLFW_FKEY_TAB, '\t', alt='\033\t', shift='\x1b[Z', csi_num=ord('\t'))
|
||||
mods_test(defines.GLFW_FKEY_INSERT, csi_num=2, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_KP_INSERT, csi_num=2, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_DELETE, csi_num=3, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_KP_DELETE, csi_num=3, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_PAGE_UP, csi_num=5, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_KP_PAGE_UP, csi_num=5, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_KP_PAGE_DOWN, csi_num=6, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_HOME, csi_num=1, trailer='H')
|
||||
mods_test(defines.GLFW_FKEY_KP_HOME, csi_num=1, trailer='H')
|
||||
mods_test(defines.GLFW_FKEY_END, csi_num=1, trailer='F')
|
||||
mods_test(defines.GLFW_FKEY_KP_END, csi_num=1, trailer='F')
|
||||
def w(a, b):
|
||||
return c(b) if a is None else a
|
||||
|
||||
a(e(), plain or c())
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT), w(shift, defines.GLFW_MOD_SHIFT))
|
||||
a(e(mods=defines.GLFW_MOD_CONTROL), w(ctrl, defines.GLFW_MOD_CONTROL))
|
||||
a(e(mods=defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL), w(calt, defines.GLFW_MOD_ALT | defines.GLFW_MOD_CONTROL))
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_CONTROL), w(cshift, defines.GLFW_MOD_CONTROL | defines.GLFW_MOD_SHIFT))
|
||||
a(e(mods=defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT), w(ashift, defines.GLFW_MOD_ALT | defines.GLFW_MOD_SHIFT))
|
||||
|
||||
def mkp(name, *a, **kw):
|
||||
for x in (f'GLFW_FKEY_{name}', f'GLFW_FKEY_KP_{name}'):
|
||||
k = getattr(defines, x)
|
||||
mods_test(k, *a, **kw)
|
||||
|
||||
mkp('ENTER', '\x0d', alt='\033\x0d', ctrl='\x0d', shift='\x0d', ashift='\033\x0d', calt='\033\x0d', cshift='\x0d')
|
||||
mods_test(defines.GLFW_FKEY_ESCAPE, '\x1b', alt='\033\033', ctrl='\x1b', shift='\x1b', calt='\x1b\x1b', cshift='\x1b', ashift='\x1b\x1b')
|
||||
mods_test(defines.GLFW_FKEY_BACKSPACE, '\x7f', alt='\033\x7f', ctrl='\x08', shift='\x7f', ashift='\033\x7f', cshift='\x08', calt='\x1b\x08')
|
||||
mods_test(defines.GLFW_FKEY_TAB, '\t', alt='\033\t', shift='\x1b[Z', ctrl='\t', ashift='\x1b\x1b[Z', cshift='\x1b[Z', calt='\x1b\t')
|
||||
mkp('INSERT', csi_num=2, trailer='~')
|
||||
mkp('DELETE', csi_num=3, trailer='~')
|
||||
mkp('PAGE_UP', csi_num=5, trailer='~')
|
||||
mkp('PAGE_DOWN', csi_num=6, trailer='~')
|
||||
mkp('HOME', csi_num=1, trailer='H')
|
||||
mkp('END', csi_num=1, trailer='F')
|
||||
mods_test(defines.GLFW_FKEY_F1, csi_num=1, trailer='P')
|
||||
mods_test(defines.GLFW_FKEY_F2, csi_num=1, trailer='Q')
|
||||
mods_test(defines.GLFW_FKEY_F3, csi_num=1, trailer='R')
|
||||
@@ -95,14 +98,10 @@ class TestKeys(BaseTest):
|
||||
mods_test(defines.GLFW_FKEY_F10, csi_num=21, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_F11, csi_num=23, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_F12, csi_num=24, trailer='~')
|
||||
mods_test(defines.GLFW_FKEY_UP, csi_num=1, trailer='A')
|
||||
mods_test(defines.GLFW_FKEY_KP_UP, csi_num=1, trailer='A')
|
||||
mods_test(defines.GLFW_FKEY_DOWN, csi_num=1, trailer='B')
|
||||
mods_test(defines.GLFW_FKEY_KP_DOWN, csi_num=1, trailer='B')
|
||||
mods_test(defines.GLFW_FKEY_RIGHT, csi_num=1, trailer='C')
|
||||
mods_test(defines.GLFW_FKEY_KP_RIGHT, csi_num=1, trailer='C')
|
||||
mods_test(defines.GLFW_FKEY_LEFT, csi_num=1, trailer='D')
|
||||
mods_test(defines.GLFW_FKEY_KP_LEFT, csi_num=1, trailer='D')
|
||||
mkp('UP', csi_num=1, trailer='A')
|
||||
mkp('DOWN', csi_num=1, trailer='B')
|
||||
mkp('RIGHT', csi_num=1, trailer='C')
|
||||
mkp('LEFT', csi_num=1, trailer='D')
|
||||
|
||||
# legacy key tests {{{
|
||||
# start legacy letter tests (auto generated by gen-key-constants.py do not edit)
|
||||
@@ -397,6 +396,10 @@ class TestKeys(BaseTest):
|
||||
ae(enc(key=ord(' ')), ' ')
|
||||
ae(enc(key=ord(' '), mods=ctrl), '\0')
|
||||
ae(enc(key=ord(' '), mods=alt), '\x1b ')
|
||||
ae(enc(key=ord(' '), mods=shift), ' ')
|
||||
ae(enc(key=ord(' '), mods=ctrl | alt), '\x1b\0')
|
||||
ae(enc(key=ord(' '), mods=ctrl | shift), '\0')
|
||||
ae(enc(key=ord(' '), mods=alt | shift), '\x1b ')
|
||||
ae(enc(key=ord('i'), mods=ctrl | shift), csi(ctrl | shift, ord('i')))
|
||||
ae(enc(key=defines.GLFW_FKEY_LEFT_SHIFT), '')
|
||||
ae(enc(key=defines.GLFW_FKEY_CAPS_LOCK), '')
|
||||
|
||||
Reference in New Issue
Block a user