From f250c2940385a13bb4f4f408a0504d1f0be5ee48 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 10 Sep 2020 23:03:30 +0200 Subject: terminal-unix: attempt to support more CTRL Hysterically stupid inconsistent legacy garbage from the 70ies or maybe even 60ies. What the fuck. I fucking hate computers so much. Fixes: #8072 --- osdep/terminal-unix.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index a2959ba237..d225d37943 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -212,23 +212,31 @@ static bool getch2(struct input_ctx *input_ctx) } if (!match) { // normal or unknown key + int mods = 0; if (buf.b[0] == '\033') { skip_buf(&buf, 1); - if (buf.len > 0 && mp_isalnum(buf.b[0])) { // meta+normal key - mp_input_put_key(input_ctx, buf.b[0] | MP_KEY_MODIFIER_ALT); - skip_buf(&buf, 1); + if (buf.len > 0 && buf.b[0] > 0 && buf.b[0] < 127) { + // meta+normal key + mods |= MP_KEY_MODIFIER_ALT; } else if (buf.len == 1 && buf.b[0] == '\033') { + // Make 2x ESC -> ESC (lone ESC is ambiguous). mp_input_put_key(input_ctx, MP_KEY_ESC); skip_buf(&buf, 1); + continue; } else { // Throw it away. Typically, this will be a complete, // unsupported sequence, and dropping this will skip it. skip_buf(&buf, buf.len); + continue; } - } else { - mp_input_put_key(input_ctx, buf.b[0]); - skip_buf(&buf, 1); } + unsigned char c = buf.b[0]; + skip_buf(&buf, 1); + if (c < 32) { + c = c <= 25 ? (c + 'a' - 1) : (c - 25 + '2' - 1); + mods |= MP_KEY_MODIFIER_CTRL; + } + mp_input_put_key(input_ctx, c | mods); continue; } -- cgit v1.2.3