Accept UTF-8 sequence as keyboard input.

This commit is contained in:
Renaud 2015-02-10 17:07:43 +08:00
parent 7da7916b28
commit 5401aec485
2 changed files with 22 additions and 1 deletions

21
input.c
View File

@ -21,6 +21,7 @@
#include "exec.h"
#include "names.h"
#include "terminal.h"
#include "utf8.h"
#include "wrapper.h"
#if PKCODE
@ -454,6 +455,26 @@ handle_CSI:
return CTLX | c;
}
if( c <= 0xC1 || c > 0xF4)
return c ;
else {
char utf[ 4] ;
utf[ 0] = c ;
if( (c & 0xE0) == 0xC0)
utf[ 1] = get1key() ;
else if( (c & 0xF0) == 0xE0) {
utf[ 1] = get1key() ;
utf[ 2] = get1key() ;
} else if( (c & 0xF8) == 0xF0) {
utf[ 1] = get1key() ;
utf[ 2] = get1key() ;
utf[ 3] = get1key() ;
}
utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &c) ;
}
/* otherwise, just return it */
return c;
}

2
utf8.c
View File

@ -29,7 +29,7 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re
* 1100000x is start of overlong encoding sequence
* Sequence longer than 4 bytes are invalid
*/
if( c <= 0xc0 || c > 0xF4 || c == 0xC1)
if( c <= 0xC1 || c > 0xF4)
return 1;
/* Ok, it's 11xxxxxx, do a stupid decode */