chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / vt102.c
index 88210873f2d1e1e31b9dadcbd6e36b38e7f32f36..d94bc4d92d1a0946a7f6aa922cb2fd706ca3294a 100644 (file)
@@ -10,6 +10,27 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.50  2008/02/28 12:12:25  james
+ * *** empty log message ***
+ *
+ * Revision 1.49  2008/02/28 11:27:48  james
+ * *** empty log message ***
+ *
+ * Revision 1.48  2008/02/27 09:42:53  james
+ * *** empty log message ***
+ *
+ * Revision 1.47  2008/02/27 09:42:22  james
+ * *** empty log message ***
+ *
+ * Revision 1.46  2008/02/27 01:31:38  james
+ * *** empty log message ***
+ *
+ * Revision 1.45  2008/02/27 01:31:14  james
+ * *** empty log message ***
+ *
+ * Revision 1.44  2008/02/27 00:54:16  james
+ * *** empty log message ***
+ *
  * Revision 1.43  2008/02/27 00:27:22  james
  * *** empty log message ***
  *
@@ -379,12 +400,32 @@ in_margins (VT102 * v, CRT_Pos p)
   return 1;
 }
 
+void vt102_do_resize(Context *c)
+{
+
+VT102 *v=c->v;
+
+          v->crt.size = v->current_size;
+          v->crt.size.y++;
+          v->screen_end = v->current_size;
+          v->screen_end.x--;
+          v->screen_end.y--;
+          v->top_margin = v->screen_start;
+          v->bottom_margin = v->screen_end;
+          vt102_cursor_home (v);
+          crt_cls (&v->crt);
+
+         if (c->t)
+               tty_winch(c->t,v->current_size);
+}
+
+
 void
 vt102_log_line (Context * c, int line)
 {
-  CRT_Pos e = { c->v->current_width - 1, line };
+  CRT_Pos e = { c->v->current_size.x - 1, line };
   CRT_Pos p = { 0, line };
-  char logbuf[VT102_MAX_COLS + 1];
+  char logbuf[4 * (VT102_MAX_COLS + 1)], *logptr = logbuf;
 
   if (!c->l)
     return;
@@ -401,11 +442,9 @@ vt102_log_line (Context * c, int line)
       int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
       if (ch < 32)
         ch = ' ';
-      if (ch > 126)
-        ch = ' ';
-      logbuf[p.x] = ch;
+      logptr += utf8_encode (logptr, ch);
     }
-  logbuf[p.x] = 0;
+  *logptr = 0;
 
   c->l->log (c->l, logbuf);
 }
@@ -689,8 +728,9 @@ vt102_insert_into_line (VT102 * v, CRT_Pos p)
 
 
 void
-vt102_change_mode (VT102 * v, int private, char *ns, int set)
+vt102_change_mode (Context *c, int private, char *ns, int set)
 {
+  VT102 *v=c->v;
   int m;
 
 
@@ -727,19 +767,12 @@ vt102_change_mode (VT102 * v, int private, char *ns, int set)
         case VT102_PRIVATE_MODE_132COLS:
           /* We don't implement 132 col mode - yet */
 
-          v->current_width =
+          v->current_size.x =
             v->
             private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 :
             VT102_COLS_80;
 
-          v->crt.width = v->current_width;
-          v->screen_end.x = v->current_width - 1;
-          v->top_margin = v->screen_start;
-          v->bottom_margin = v->screen_end;
-          vt102_cursor_home (v);
-          crt_cls (&v->crt);
-
-
+         vt102_do_resize(c);
           break;
         }
 
@@ -753,8 +786,9 @@ vt102_change_mode (VT102 * v, int private, char *ns, int set)
 }
 
 void
-vt102_parse_mode_string (VT102 * v, char *buf, int len)
+vt102_parse_mode_string (Context *c, char *buf, int len)
 {
+  VT102 *v=c->v;
   int private = 0;
   char last = buf[len - 1];
   char num[4];
@@ -779,7 +813,7 @@ vt102_parse_mode_string (VT102 * v, char *buf, int len)
     {
       if (*buf == ';')
         {
-          vt102_change_mode (v, private, &num[o], last == 'h');
+          vt102_change_mode (c, private, &num[o], last == 'h');
           memset (num, 0, sizeof (num));
           o = sizeof (num) - 1;
           buf++;
@@ -796,7 +830,7 @@ vt102_parse_mode_string (VT102 * v, char *buf, int len)
       buf++;
     }
 
-  vt102_change_mode (v, private, &num[o], last == 'h');
+  vt102_change_mode (c, private, &num[o], last == 'h');
 
 }
 
@@ -983,25 +1017,33 @@ void
 vt102_regular_char (Context * c, VT102 * v, uint32_t ch)
 {
 
+
   vt102_do_pending_wrap (c);
 
+
   if (v->modes[VT102_MODE_INSERT])
     vt102_insert_into_line (v, v->pos);
 
+  v->last_reg_char = ch;
+
+
   if (ch < VT102_CHARSET_SIZE)
     {
-      int cs = charset_from_csid[v->g[v->cs]][ch];
-      v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = cs ? cs : ch;
-    }
-  else
-    {
-      v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
+      int cs;
+      if ((cs = vt102_charset_c0[ch]))
+        {
+          ch = cs;
+        }
+      else if ((cs = charset_from_csid[v->g[v->cs]][ch]))
+        {
+          ch = cs;
+        }
     }
+  v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
   v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
   v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
   vt102_cursor_advance (c);
 
-  v->last_reg_char = ch;
 }
 
 vt102_send_id (Context * c, char *buf)
@@ -1148,7 +1190,7 @@ vt102_parse_csi (Context * c, char *buf, int len)
         case 'K':
           {
             CRT_Pos ls = { 0, v->pos.y };
-            CRT_Pos le = { v->current_width - 1, v->pos.y };
+            CRT_Pos le = { v->current_size.x - 1, v->pos.y };
             if (len == 2)
               narg = 0;         /*Different default */
 
@@ -1257,7 +1299,7 @@ vt102_parse_csi (Context * c, char *buf, int len)
           break;
         case 'h':
         case 'l':
-          vt102_parse_mode_string (v, &buf[1], len - 1);
+          vt102_parse_mode_string (c, &buf[1], len - 1);
           break;
 
 
@@ -1390,7 +1432,7 @@ vt102_parse_esc (Context * c)
           break;
         case 'K':
           {
-            CRT_Pos le = { v->current_width - 1, v->pos.y };
+            CRT_Pos le = { v->current_size.x - 1, v->pos.y };
             crt_erase (&v->crt, v->pos, le, 1, v->color);
           }
           break;
@@ -1453,9 +1495,7 @@ vt102_parse_esc (Context * c)
       vt102_send_id (c, terminal_id);
       break;
     case 'c':
-      vt102_reset (v);
-
-
+      vt102_reset (c);
       break;
     case '=':
       v->application_keypad_mode = 1;
@@ -1530,10 +1570,10 @@ vt102_parse_esc (Context * c)
 void
 vt102_status_line (VT102 * v, char *str)
 {
-  int i = v->current_width - 1;
-  CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
+  int i;
+  CRT_CA *ca = &v->crt.screen[CRT_ADDR (v->current_size.y, 0)];
 
-  for (i = 0; i < v->current_width; ++i)
+  for (i = 0; i < v->current_size.x; ++i)
     {
       ca->attr = CRT_ATTR_REVERSE;
       ca->color = CRT_COLOR_NORMAL;
@@ -1565,8 +1605,9 @@ vt102_parser_reset (VT102_parser * p)
 
 
 void
-vt102_reset_state (VT102 * v)
+vt102_reset_state (Context *c)
 {
+  VT102 *v=c->v;
   vt102_parser_reset (&v->parser);
 
   v->attr = CRT_ATTR_NORMAL;
@@ -1574,12 +1615,9 @@ vt102_reset_state (VT102 * v)
 
   v->application_keypad_mode = 0;
 
-  v->current_width = VT102_COLS_80;
-  v->crt.width = v->current_width;
-  v->screen_end.x = v->current_width - 1;
+  v->current_size = v->original_size;
 
-  v->top_margin = v->screen_start;
-  v->bottom_margin = v->screen_end;
+  vt102_do_resize(c);
 
   memset (v->modes, 0, VT102_NMODES);
   memset (v->private_modes, 0, VT102_NMODES);
@@ -1652,7 +1690,7 @@ vt102_parse_char (Context * c, int ch)
 #endif
   if (ch == SYM_CHAR_RESET)
     {
-      vt102_reset_state (v);
+      vt102_reset_state (c);
     }
   else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination))
     {
@@ -1719,17 +1757,23 @@ vt102_parse_char (Context * c, int ch)
 
       switch (ch)
         {
+#if 0
          /*NUL*/ case 0:
          /*SOH*/ case 1:
          /*STX*/ case 2:
          /*ETX*/ case 3:
          /*EOT*/ case 4:
           break;
+#endif
          /*ENQ*/ case 5:
           vt102_send_id (c, terminal_id);
           break;
+#if 0
          /*ACK*/ case 6:
+          break;
+#endif
          /*BEL*/ case 7:
+          //FIXME beep
           break;
          /*BS*/ case 8:
           vt102_cursor_retreat (c->v);
@@ -1754,6 +1798,7 @@ vt102_parse_char (Context * c, int ch)
           /*select G0 */
           v->cs = 0;
           break;
+#if 0
          /*DLE*/ case 16:
         /*DC1 */ case 17:
         /*DC2 */ case 18:
@@ -1766,15 +1811,18 @@ vt102_parse_char (Context * c, int ch)
          /*EM*/ case 25:
          /*SUB*/ case 26:
           break;
+#endif
          /*ESC*/ case 27:
           p->in_escape++;
           return;
+#if 0
          /*FS*/ case 28:
          /*GS*/ case 29:
          /*RS*/ case 30:
          /*US*/ case 31:
          /*DEL*/ case 127:
           break;
+#endif
         /*regular character */ default:
           vt102_regular_char (c, v, ch);
         }
@@ -1969,8 +2017,9 @@ vt102_send (Context * c, uint8_t key)
 }
 
 void
-vt102_reset (VT102 * v)
+vt102_reset (Context * c)
 {
+  VT102 *v=c->v;
   VT102_parser *p = &v->parser;
 
 
@@ -1980,10 +2029,12 @@ vt102_reset (VT102 * v)
 
   v->screen_start.x = 0;
   v->screen_start.y = 0;
-  v->current_width = VT102_COLS_80;
-  v->crt.width = v->current_width;
-  v->screen_end.x = v->current_width - 1;
-  v->screen_end.y = VT102_ROWS - 1;
+  v->current_size = v->original_size;
+  v->crt.size = v->current_size;
+  v->crt.size.y++;
+  v->screen_end = v->current_size;
+  v->screen_end.x--;
+  v->screen_end.y--;
 
   vt102_cursor_home (v);
   vt102_status_line (v, "");
@@ -1992,7 +2043,7 @@ vt102_reset (VT102 * v)
   v->current_line = v->pos;
 
   vt102_parser_reset (p);
-  vt102_reset_state (v);
+  vt102_reset_state (c);
 
   vt102_save_state (v);
 
@@ -2000,7 +2051,7 @@ vt102_reset (VT102 * v)
 }
 
 VT102 *
-vt102_new (void)
+vt102_new (CRT_Pos * size)
 {
   VT102 *v;
 
@@ -2008,8 +2059,27 @@ vt102_new (void)
 
   v->xn_glitch = 1;
 
-  vt102_reset (v);
 
+  if (size)
+    {
+      v->original_size = *size;
+
+      if (v->original_size.x < 1)
+        v->original_size.x = 1;
+      if (v->original_size.y < 1)
+        v->original_size.y = 1;
+
+      if (v->original_size.x > VT102_MAX_COLS)
+        v->original_size.x = VT102_MAX_COLS;
+      if (v->original_size.y > VT102_ROWS)
+        v->original_size.y = VT102_ROWS;
+
+    }
+  else
+    {
+      v->original_size.x = VT102_COLS_80;
+      v->original_size.y = VT102_ROWS;
+    }
 
   return v;
 }
@@ -2020,6 +2090,26 @@ vt102_set_ansi (VT102 * v, int ansi)
   v->xn_glitch = ansi ? 0 : 1;
 }
 
+void vt102_resize(Context *c,CRT_Pos size)
+{
+
+       if (!size.x) size.x=c->v->current_size.x;
+       if (!size.y) size.x=c->v->current_size.y;
+
+      if (size.x < 1)
+        size.x = 1;
+      if (size.y < 1)
+        size.y = 1;
+
+      if (size.x > VT102_MAX_COLS)
+        size.x = VT102_MAX_COLS;
+      if (size.y > VT102_ROWS)
+        size.y = VT102_ROWS;
+
+       c->v->current_size=size;
+       vt102_do_resize(c);
+}
+
 void
 vt102_free (VT102 * v)
 {