chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / ansi.c
index 0fa9a96e9fca5ad4940c7255c0976c918fc2cc62..7a0d630a18406a3966d4bf9bb949d60d713d8e4b 100644 (file)
@@ -10,6 +10,27 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.30  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
+ * Revision 1.29  2008/02/23 11:48:37  james
+ * *** empty log message ***
+ *
+ * Revision 1.28  2008/02/22 17:07:00  james
+ * *** empty log message ***
+ *
+ * Revision 1.27  2008/02/20 22:54:22  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.26  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
+ * Revision 1.25  2008/02/20 19:44:37  james
+ * @@
+ *
+ * Revision 1.24  2008/02/20 19:36:06  james
+ * @@
+ *
  * Revision 1.23  2008/02/20 19:25:09  james
  * *** empty log message ***
  *
@@ -298,21 +319,30 @@ ansi_set_attr (ANSI * a, int attr)
 
 }
 
+static void
+ansi_emit_noutf8 (TTY * t, uint32_t ch)
+{
+  uint8_t c = (ch > 0x7f) ? '?' : ch;
+  t->xmit (t, &c, 1);
+}
 
 static void
 ansi_render (ANSI * a, CRT_CA ca)
 {
   int dif;
 
-  if (ca.chr < 32)
+  if (ca.chr < 0x20)
     ca.chr = ' ';
-  if (ca.chr > 126)
+  if ((ca.chr > 0x7e) && (ca.chr < 0xa0))
     ca.chr = ' ';
 
   ansi_set_attr (a, ca.attr);
   ansi_set_color (a, ca.color);
 
-  a->terminal->xmit (a->terminal, &ca.chr, 1);
+  if (a->utf8)
+    utf8_emit (a->terminal, ca.chr);
+  else
+    ansi_emit_noutf8 (a->terminal, ca.chr);
 
   a->pos.x++;
 
@@ -516,6 +546,9 @@ ansi_history (ANSI * a, History * h)
       /*Roll HISTORY_GUESS_SCROLL lines up putting the top line into the xterm's history */
 
 
+      /*Make extra lines a predictable colour */
+      ansi_set_color (a, CRT_COLOR_NORMAL);
+
       ansi_showhide_cursor (a, 1);
       i = sprintf (buf, "\033[%d;%dH", HISTORY_GUESS_SCROLL, 1);
       a->terminal->xmit (a->terminal, buf, i);
@@ -541,7 +574,7 @@ ansi_history (ANSI * a, History * h)
         /* erase new line */
         s.y = e.y;
         e.x = CRT_COLS - 1;
-        crt_erase (&a->crt, s, e, 1);
+        crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL);
       }
 
     }
@@ -814,7 +847,7 @@ ansi_dispatch (ANSI * a, Context * c)
 
 
   if (!a->terminal)
-    return;
+    return 0;
 
   red = a->terminal->recv (a->terminal, buf, sizeof (buf));
   if (red <= 0)
@@ -850,23 +883,33 @@ ansi_update (ANSI * a, Context * c)
   ansi_draw (a, &c->v->crt);
 }
 
-static void ansi_free(ANSI *a)
+static void
+ansi_free (ANSI * a)
 {
+  a->terminal_reset (a);
+  if (a->terminal)
+    a->terminal->close (a->terminal);
+
+  free (a);
 
 }
 
-ANSI *ansi_new_from_terminal(ANSI *a,TTY *t)
+ANSI *
+ansi_new_from_terminal (TTY * t, int utf8)
 {
-ANSI *ret;
+  ANSI *ret;
 
-ret=malloc(sizeof(ANSI));
-memset(ret,0,sizeof(ANSI));
+  ret = malloc (sizeof (ANSI));
+  memset (ret, 0, sizeof (ANSI));
 
-ret->terminal=t;
+  ret->terminal = t;
 
-ret->update=ansi_update;
-ret->reset=ansi_reset;
-ret->terminal_reset=ansi_terminal_reset;
-ret->close=ansi_free;
+  ret->utf8 = utf8;
+  ret->update = ansi_update;
+  ret->reset = ansi_reset;
+  ret->terminal_reset = ansi_terminal_reset;
+  ret->close = ansi_free;
+  ret->dispatch = ansi_dispatch;
 
+  return ret;
 }