From: Bill Lash Date: Mon, 4 Feb 2019 06:13:59 +0000 (-0600) Subject: Adding input of utf-8 chars and history X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=8b898570775a2387f04f1504d09f88391afa07f9;p=liskon_frotz.git Adding input of utf-8 chars and history This adds utf8 input and the ability to move up and down in history when the command line has utf8 characters --- diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index ce61690..69c35f9 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -182,7 +182,7 @@ static int unix_read_char(int extkeys) } timeout(0); - c = getch(); + get_wch(&c); /* Catch 98% of all input right here... */ if ((c >= ZC_ASCII_MIN && c <= ZC_ASCII_MAX) @@ -222,7 +222,7 @@ static int unix_read_char(int extkeys) value of the letter. We have to decide here whether to return a single escape or a frotz hot key. */ case ZC_ESCAPE: - nodelay(stdscr, TRUE); c = getch(); nodelay(stdscr, FALSE); + nodelay(stdscr, TRUE); get_wch(&c); nodelay(stdscr, FALSE); switch(c) { case ERR: return ZC_ESCAPE; case 'p': return ZC_HKEY_PLAYBACK; @@ -434,7 +434,26 @@ static void scrnset(int start, int c, int n) return; } - +static void utf8_mvaddstr(int y, int x, char * buf) +{ + unsigned char *bp = (unsigned char *)buf; + + move(y,x); + while(*bp) { + if(*bp < ZC_LATIN1_MIN) { + addch(*bp); + } else { + if(*bp < 0xc0) { + addch(0xc2); + addch(*bp); + } else { + addch(0xc3); + addch(*bp - 0x40); + } + } + bp++; + } +} /* * os_read_line * @@ -611,7 +630,7 @@ zchar os_read_line (int bufmax, zchar *buf, int timeout, int width, if ((ch == ZC_ARROW_UP ? unix_history_back : unix_history_forward) (buf, searchpos, max)) { scrnset(x, ' ', len); - mvaddstr(y, x, (char *) buf); + utf8_mvaddstr(y, x, (char *) buf); scrpos = len = strlen((char *) buf); } continue; @@ -666,7 +685,15 @@ zchar os_read_line (int bufmax, zchar *buf, int timeout, int width, } if (insert_flag || scrpos == len) len++; - mvaddch(y, x + scrpos, ch); + if (ch < ZC_LATIN1_MIN) { + mvaddch(y, x + scrpos, ch); + } else if (ch < 0xc0) { + mvaddch(y, x + scrpos, 0xc2); + addch(ch); + } else { + mvaddch(y, x + scrpos, 0xc3); + addch(ch - 0x40); + } buf[scrpos++] = ch; continue; }