chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / vt102.c
index 52f7fb959f60f70d8a22e88a223394214fd68a8e..d94bc4d92d1a0946a7f6aa922cb2fd706ca3294a 100644 (file)
@@ -10,6 +10,18 @@ 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 ***
  *
@@ -388,10 +400,30 @@ 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[4 * (VT102_MAX_COLS + 1)], *logptr = logbuf;
 
@@ -696,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;
 
 
@@ -734,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;
         }
 
@@ -760,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];
@@ -786,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++;
@@ -803,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');
 
 }
 
@@ -1163,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 */
 
@@ -1272,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;
 
 
@@ -1405,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;
@@ -1468,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;
@@ -1545,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;
@@ -1580,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;
@@ -1589,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);
@@ -1667,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))
     {
@@ -1994,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;
 
 
@@ -2005,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, "");
@@ -2017,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);
 
@@ -2025,7 +2051,7 @@ vt102_reset (VT102 * v)
 }
 
 VT102 *
-vt102_new (int width)
+vt102_new (CRT_Pos * size)
 {
   VT102 *v;
 
@@ -2033,16 +2059,26 @@ vt102_new (int width)
 
   v->xn_glitch = 1;
 
-  vt102_reset (v);
 
-  if (width)
+  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->current_width = width;
-      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);
+      v->original_size.x = VT102_COLS_80;
+      v->original_size.y = VT102_ROWS;
     }
 
   return v;
@@ -2054,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)
 {