Merges from Irssi CVS.
[crypto.git] / apps / irssi / src / fe-text / term-terminfo.c
index e09e9c20481fafd7bdd7ebff330e89ab17aa6402..ddb00441d0b81204d5f22cc2391bc7072cea9cae 100644 (file)
@@ -77,7 +77,8 @@ static int redraw_timeout(void)
 
 int term_init(void)
 {
-        struct sigaction act;
+       struct sigaction act;
+        int width, height;
 
        last_fg = last_bg = -1;
        last_attrs = 0;
@@ -89,6 +90,11 @@ int term_init(void)
        if (current_term == NULL)
                return FALSE;
 
+       if (term_get_size(&width, &height)) {
+                current_term->width = width;
+                current_term->height = height;
+       }
+
         /* grab CONT signal */
        sigemptyset(&act.sa_mask);
        act.sa_flags = 0;
@@ -113,6 +119,7 @@ int term_init(void)
 void term_deinit(void)
 {
        if (current_term != NULL) {
+               signal(SIGCONT, SIG_DFL);
                g_source_remove(redraw_tag);
 
                term_common_deinit();
@@ -369,7 +376,7 @@ static void term_printed_text(int count)
        vcx += count;
        while (vcx >= term_width) {
                vcx -= term_width;
-               if (vcy < term_height) vcy++;
+               if (vcy < term_height-1) vcy++;
                if (vcx > 0) term_lines_empty[vcy] = FALSE;
        }
 }
@@ -379,14 +386,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 +644,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;
                }
        }