chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / vt102.c
index 2132f83f7005874168937f27e47c6096aea2d949..74888035be62746b0bd559c00299c755b96f37b1 100644 (file)
@@ -10,6 +10,18 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.52  2008/02/28 16:57:52  james
+ * *** empty log message ***
+ *
+ * Revision 1.51  2008/02/28 16:37:16  james
+ * *** empty log message ***
+ *
+ * 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 ***
  *
@@ -394,6 +406,49 @@ in_margins (VT102 * v, CRT_Pos p)
   return 1;
 }
 
+void
+vt102_crt_update (Context * c)
+{
+  VT102 *v = c->v;
+
+  v->crt.pos = v->pos;
+  v->crt.hide_cursor =
+    v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
+
+  if (v->current_line.y != v->pos.y)
+    {
+      vt102_log_line (c, v->current_line.y);
+      v->current_line = v->pos;
+    }
+
+  if (c->d)
+    cmd_show_status (c->d, c);
+}
+
+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);
+
+  log_f (c->l, "<size now %dx%d>", v->current_size.x, v->current_size.y);
+  vt102_crt_update (c);
+}
+
+
 void
 vt102_log_line (Context * c, int line)
 {
@@ -702,8 +757,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;
 
 
@@ -745,17 +801,7 @@ vt102_change_mode (VT102 * v, int private, char *ns, int set)
             private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 :
             VT102_COLS_80;
 
-          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);
-
-
+          vt102_do_resize (c);
           break;
         }
 
@@ -769,8 +815,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];
@@ -795,7 +842,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++;
@@ -812,7 +859,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');
 
 }
 
@@ -1281,7 +1328,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;
 
 
@@ -1477,9 +1524,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;
@@ -1589,8 +1634,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;
@@ -1599,14 +1645,8 @@ vt102_reset_state (VT102 * v)
   v->application_keypad_mode = 0;
 
   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--;
 
-  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);
@@ -1679,7 +1719,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))
     {
@@ -1823,18 +1863,9 @@ vt102_parse_char (Context * c, int ch)
 #endif
     }
 
-  v->crt.pos = v->pos;
-  v->crt.hide_cursor =
-    v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
+  vt102_crt_update (c);
 
-  if (v->current_line.y != v->pos.y)
-    {
-      vt102_log_line (c, v->current_line.y);
-      v->current_line = v->pos;
-    }
 
-  if (c->d)
-    cmd_show_status (c->d, c);
 }
 
 void
@@ -2006,8 +2037,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;
 
 
@@ -2031,7 +2063,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);
 
@@ -2059,18 +2091,16 @@ vt102_new (CRT_Pos * size)
 
       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;
+      if (v->original_size.y > VT102_MAX_ROWS)
+        v->original_size.y = VT102_MAX_ROWS;
 
     }
   else
     {
       v->original_size.x = VT102_COLS_80;
-      v->original_size.y = VT102_ROWS;
+      v->original_size.y = VT102_ROWS_24;
     }
 
-  vt102_reset (v);
-
   return v;
 }
 
@@ -2080,6 +2110,30 @@ vt102_set_ansi (VT102 * v, int ansi)
   v->xn_glitch = ansi ? 0 : 1;
 }
 
+void
+vt102_resize (Context * c, CRT_Pos size)
+{
+  log_f (c->l, "<size change to %dx%d requested>", size.x, size.y);
+
+  if (!size.x)
+    size.x = c->v->current_size.x;
+  if (!size.y)
+    size.y = 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_MAX_ROWS)
+    size.y = VT102_MAX_ROWS;
+
+  c->v->current_size = size;
+  vt102_do_resize (c);
+}
+
 void
 vt102_free (VT102 * v)
 {