Merged Irssi 0.8.2 from irssi.org cvs.
[silc.git] / apps / irssi / src / fe-text / term-terminfo.c
index e09e9c20481fafd7bdd7ebff330e89ab17aa6402..4e9781fe744f405efd4c786d97a74029086d7a91 100644 (file)
@@ -379,14 +379,21 @@ void term_addch(TERM_WINDOW *window, int chr)
        if (term_detached) return;
 
        if (vcmove) term_move_real();
-        term_printed_text(1);
+
+       /* With UTF-8, move cursor only if this char is either single-byte
+          (8. bit on) or beginning of multibyte (7+8 bits on) */
+       if (term_type != TERM_TYPE_UTF8 ||
+           (chr & 0x80) == 0 || (chr & 0x40) == 0) {
+               term_printed_text(1);
+       }
+
        if (vcy != term_height || vcx != 0)
                putc(chr, window->term->out);
 }
 
 static void term_addch_utf8(TERM_WINDOW *window, unichar chr)
 {
-       unsigned char buf[10];
+       char buf[10];
        int i, len;
 
        len = utf16_char_to_utf8(chr, buf);
@@ -630,9 +637,9 @@ int term_gets(unichar *buffer, int size)
 
                if (i >= term_inbuf_pos)
                        term_inbuf_pos = 0;
-               else {
+               else if (i > 0) {
                        memmove(term_inbuf+i, term_inbuf, term_inbuf_pos-i);
-                        term_inbuf_pos = i;
+                        term_inbuf_pos -= i;
                }
        }