diff options
author | wm4 <wm4@mplayer2.org> | 2012-01-13 07:59:21 +0100 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-01-18 04:13:27 +0100 |
commit | e72296758074d8e375490025b0cbe7f333230f13 (patch) | |
tree | ead7a5b776f7123bc2e3b3451357a12f26f62c5a /osdep | |
parent | ad455c43f54f1ec259d9aea48cc16e7c4485b584 (diff) | |
download | mpv-e72296758074d8e375490025b0cbe7f333230f13.tar.bz2 mpv-e72296758074d8e375490025b0cbe7f333230f13.tar.xz |
input: handle UTF-8 terminal input
This assumes the terminal uses UTF-8. If invalid UTF-8 is encountered (for
example because the terminal uses a legacy encoding), the code falls back
to the old method and feeds each byte as key code to the input code.
In theory, UTF-8 input could randomly fail, because the code in getch2.c
doesn't try to fill the input buffer correctly with input sequences
longer than a byte. This is a problem with the design of the existing
code.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index f421bdea7e..1eb78070c0 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -57,6 +57,7 @@ #include <unistd.h> #include <fcntl.h> +#include "bstr.h" #include "mp_fifo.h" #include "input/keycodes.h" #include "getch2.h" @@ -202,6 +203,15 @@ void getch2(struct mp_fifo *fifo) } code = KEY_ENTER; } + int utf8len = bstr_parse_utf8_code_length(code); + if (utf8len > 0 && utf8len <= getch2_len) { + struct bstr s = { getch2_buf, utf8len }; + int unicode = bstr_decode_utf8(s, NULL); + if (unicode > 0) { + len = utf8len; + code = unicode; + } + } } else if (getch2_len > 1) { int c = getch2_buf[1]; |