summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2021-08-19 01:19:55 +0300
committeravih <avih@users.noreply.github.com>2021-08-19 15:39:42 +0300
commit21d434d2dbadf91d7bd2089ca1ca92c2d918b114 (patch)
tree17cad1ba464a3aab602465d6e2b8b9a4349b68ea
parent007c728ad27cc9eb3d0315d6d15fd3bc5f055cc5 (diff)
downloadmpv-21d434d2dbadf91d7bd2089ca1ca92c2d918b114.tar.bz2
mpv-21d434d2dbadf91d7bd2089ca1ca92c2d918b114.tar.xz
terminal-unix: identify and ignore unknown CSI sequences
If an unknown ESC sequence is detected where an ASCII char <X> follows the ESC, mpv interprets it as ALT+<X>, which is the traditional terminal encoding of ALT+letter. However, if <X> is '[' then it's a CSI sequence which continues after the '[', and has its own termination rules (can be many chars). Previously, mpv interpreted unknown CSI sequences as (incorrect) ALT+[ followed by (incorrect) "keys" from the rest of the sequence. In this commit, if a unknown CSI sequence is detected, mpv ignores exactly the complete sequence.
-rw-r--r--osdep/terminal-unix.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 1e7d874028..adcf3a3540 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -221,6 +221,17 @@ static void process_input(struct input_ctx *input_ctx, bool timeout)
if (!match) { // normal or unknown key
int mods = 0;
if (buf.b[0] == '\033') {
+ if (buf.len > 1 && buf.b[1] == '[') {
+ // unknown CSI sequence. wait till it completes
+ for (int i = 2; i < buf.len; i++) {
+ if (buf.b[i] >= 0x40 && buf.b[i] <= 0x7E) {
+ skip_buf(&buf, i+1);
+ continue; // complete - throw it away
+ }
+ }
+ goto read_more; // not yet complete
+ }
+ // non-CSI esc sequence
skip_buf(&buf, 1);
if (buf.len > 0 && buf.b[0] > 0 && buf.b[0] < 127) {
// meta+normal key