Ensure typing in shell works in disambiguate mode

This commit is contained in:
Kovid Goyal 2021-01-14 03:35:10 +05:30
parent 11de87d9d9
commit c421fd56be
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 5 deletions

View File

@ -240,7 +240,11 @@ represented in one of the following two forms::
This makes it very easy to parse key events in an application. In particular, This makes it very easy to parse key events in an application. In particular,
:kbd:`ctrl+c` will no longer generate the ``SIGINT`` signal, but instead be :kbd:`ctrl+c` will no longer generate the ``SIGINT`` signal, but instead be
delivers as a ``CSI u`` escape code. This has the nice side effect of making it delivers as a ``CSI u`` escape code. This has the nice side effect of making it
much easier to integrate into the application event loop. much easier to integrate into the application event loop. The only exceptions
are the :kbd:`Enter, Tab and Backspace` keys which still generate the same
bytes as in legacy mode this is to allow the user to type and execute commands
in the shell such as ``reset`` after a program that sets this mode crashes
without clearing it.
.. _report_events: .. _report_events:

View File

@ -150,15 +150,15 @@ encode_function_key(const KeyEvent *ev, char *output) {
default: break; default: break;
} }
} }
if (ev->mods.value == ALT) { if (ev->mods.value == ALT && !ev->disambiguate) {
switch(key_number) { switch(key_number) {
case GLFW_FKEY_TAB: SIMPLE("\x1b\t"); case GLFW_FKEY_TAB: SIMPLE("\x1b\t");
case GLFW_FKEY_ENTER: SIMPLE("\x1b\r"); case GLFW_FKEY_ENTER: SIMPLE("\x1b\r");
case GLFW_FKEY_BACKSPACE: SIMPLE("\x1b\x7f"); case GLFW_FKEY_BACKSPACE: SIMPLE("\x1b\x7f");
} }
} }
if (ev->mods.value == SHIFT && key_number == GLFW_FKEY_TAB) { SIMPLE("\x1b[Z"); } if (ev->mods.value == SHIFT && key_number == GLFW_FKEY_TAB && !ev->disambiguate) { SIMPLE("\x1b[Z"); }
if (ev->mods.value == CTRL && key_number == GLFW_FKEY_BACKSPACE) { SIMPLE("\x08"); } if (ev->mods.value == CTRL && key_number == GLFW_FKEY_BACKSPACE && !ev->disambiguate) { SIMPLE("\x08"); }
#undef SIMPLE #undef SIMPLE
#define S(number, trailer) key_number = number; csi_trailer = trailer; break #define S(number, trailer) key_number = number; csi_trailer = trailer; break

View File

@ -399,7 +399,11 @@ class TestKeys(BaseTest):
# test disambiguate # test disambiguate
dq = partial(enc, key_encoding_flags=0b1) dq = partial(enc, key_encoding_flags=0b1)
ae(dq(ord('a')), 'a') ae(dq(ord('a')), 'a')
ae(dq(defines.GLFW_FKEY_ESCAPE), csi(num=27)) # esc ae(dq(defines.GLFW_FKEY_ESCAPE), csi(num=27))
ae(dq(defines.GLFW_FKEY_ENTER), '\r')
ae(dq(defines.GLFW_FKEY_ENTER, mods=shift), csi(shift, 13))
ae(dq(defines.GLFW_FKEY_TAB), '\t')
ae(dq(defines.GLFW_FKEY_BACKSPACE), '\x7f')
for mods in (ctrl, alt, ctrl | shift, alt | shift): for mods in (ctrl, alt, ctrl | shift, alt | shift):
ae(dq(ord('a'), mods=mods), csi(mods, ord('a'))) ae(dq(ord('a'), mods=mods), csi(mods, ord('a')))
ae(dq(ord(' '), mods=ctrl), csi(ctrl, ord(' '))) ae(dq(ord(' '), mods=ctrl), csi(ctrl, ord(' ')))