Oops. I wrote in the docs that no-remote-resize also included
[sgt/putty] / terminal.c
index 2962b0a..8afb98b 100644 (file)
@@ -99,7 +99,7 @@ static int wrap, wrapnext;           /* wrap flags */
 static int insert;                    /* insert-mode flag */
 static int cset;                      /* 0 or 1: which char set */
 static int save_cset, save_csattr;     /* saved with cursor position */
-static int save_utf;                  /* saved with cursor position */
+static int save_utf, save_wnext;       /* saved with cursor position */
 static int rvideo;                    /* global reverse video flag */
 static unsigned long rvbell_startpoint;/* for ESC[?5hESC[?5l vbell */
 static int cursor_on;                 /* cursor enabled flag */
@@ -351,6 +351,21 @@ void term_pwron(void)
 }
 
 /*
+ * When the user reconfigures us, we need to check the forbidden-
+ * alternate-screen config option.
+ */
+void term_reconfig(void)
+{
+    if (cfg.no_alt_screen)
+       swap_screen(0);
+    if (cfg.no_remote_charset) {
+       cset_attr[0] = cset_attr[1] = ATTR_ASCII;
+       sco_acs = alt_sco_acs = 0;
+       utf = 0;
+    }
+}
+
+/*
  * Clear the scrollback.
  */
 void term_clrsb(void)
@@ -746,6 +761,7 @@ static void save_cursor(int save)
        save_attr = curr_attr;
        save_cset = cset;
        save_utf = utf;
+       save_wnext = wrapnext;
        save_csattr = cset_attr[cset];
        save_sco_acs = sco_acs;
     } else {
@@ -759,6 +775,13 @@ static void save_cursor(int save)
        curr_attr = save_attr;
        cset = save_cset;
        utf = save_utf;
+       wrapnext = save_wnext;
+       /*
+        * wrapnext might reset to False if the x position is no
+        * longer at the rightmost edge.
+        */
+       if (wrapnext && curs.x < cols-1)
+           wrapnext = FALSE;
        cset_attr[cset] = save_csattr;
        sco_acs = save_sco_acs;
        fix_cpos;
@@ -869,7 +892,8 @@ static void toggle_mode(int mode, int query, int state)
            break;
          case 3:                      /* 80/132 columns */
            deselect();
-           request_resize(state ? 132 : 80, rows);
+           if (!cfg.no_remote_resize)
+               request_resize(state ? 132 : 80, rows);
            reset_132 = state;
            break;
          case 5:                      /* reverse video */
@@ -921,7 +945,7 @@ static void toggle_mode(int mode, int query, int state)
          case 47:                     /* alternate screen */
            compatibility(OTHER);
            deselect();
-           swap_screen(state);
+           swap_screen(cfg.no_alt_screen ? 0 : state);
            disptop = 0;
            break;
          case 1000:                   /* xterm mouse 1 */
@@ -964,13 +988,15 @@ static void do_osc(void)
        switch (esc_args[0]) {
          case 0:
          case 1:
-           set_icon(osc_string);
+           if (!cfg.no_remote_wintitle)
+               set_icon(osc_string);
            if (esc_args[0] == 1)
                break;
            /* fall through: parameter 0 means set both */
          case 2:
          case 21:
-           set_title(osc_string);
+           if (!cfg.no_remote_wintitle)
+               set_title(osc_string);
            break;
        }
     }
@@ -1164,7 +1190,8 @@ void term_out(void)
                curs.x--;
            wrapnext = FALSE;
            fix_cpos;
-           *cpos = (' ' | curr_attr | ATTR_ASCII);
+           if (!cfg.no_dbackspace)    /* destructive bksp might be disabled */
+               *cpos = (' ' | curr_attr | ATTR_ASCII);
        } else
            /* Or normal C0 controls. */
        if ((c & -32) == 0 && termstate < DO_CTRLS) {
@@ -1509,7 +1536,8 @@ void term_out(void)
                    compatibility(VT100);
                    power_on();
                    if (reset_132) {
-                       request_resize(80, rows);
+                       if (!cfg.no_remote_resize)
+                           request_resize(80, rows);
                        reset_132 = 0;
                    }
                    fix_cpos;
@@ -1573,46 +1601,56 @@ void term_out(void)
 
                  case ANSI('A', '('):
                    compatibility(VT100);
-                   cset_attr[0] = ATTR_GBCHR;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[0] = ATTR_GBCHR;
                    break;
                  case ANSI('B', '('):
                    compatibility(VT100);
-                   cset_attr[0] = ATTR_ASCII;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[0] = ATTR_ASCII;
                    break;
                  case ANSI('0', '('):
                    compatibility(VT100);
-                   cset_attr[0] = ATTR_LINEDRW;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[0] = ATTR_LINEDRW;
                    break;
                  case ANSI('U', '('): 
                    compatibility(OTHER);
-                   cset_attr[0] = ATTR_SCOACS; 
+                   if (!cfg.no_remote_charset)
+                       cset_attr[0] = ATTR_SCOACS; 
                    break;
 
                  case ANSI('A', ')'):
                    compatibility(VT100);
-                   cset_attr[1] = ATTR_GBCHR;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[1] = ATTR_GBCHR;
                    break;
                  case ANSI('B', ')'):
                    compatibility(VT100);
-                   cset_attr[1] = ATTR_ASCII;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[1] = ATTR_ASCII;
                    break;
                  case ANSI('0', ')'):
                    compatibility(VT100);
-                   cset_attr[1] = ATTR_LINEDRW;
+                   if (!cfg.no_remote_charset)
+                       cset_attr[1] = ATTR_LINEDRW;
                    break;
                  case ANSI('U', ')'): 
                    compatibility(OTHER);
-                   cset_attr[1] = ATTR_SCOACS; 
+                   if (!cfg.no_remote_charset)
+                       cset_attr[1] = ATTR_SCOACS; 
                    break;
 
                  case ANSI('8', '%'):  /* Old Linux code */
                  case ANSI('G', '%'):
                    compatibility(OTHER);
-                   utf = 1;
+                   if (!cfg.no_remote_charset)
+                       utf = 1;
                    break;
                  case ANSI('@', '%'):
                    compatibility(OTHER);
-                   utf = 0;
+                   if (!cfg.no_remote_charset)
+                       utf = 0;
                    break;
                }
                break;
@@ -1872,12 +1910,15 @@ void term_out(void)
                                    break;
                                  case 10:      /* SCO acs off */
                                    compatibility(SCOANSI);
+                                   if (cfg.no_remote_charset) break;
                                    sco_acs = 0; break;
                                  case 11:      /* SCO acs on */
                                    compatibility(SCOANSI);
+                                   if (cfg.no_remote_charset) break;
                                    sco_acs = 1; break;
                                  case 12:      /* SCO acs on flipped */
                                    compatibility(SCOANSI);
+                                   if (cfg.no_remote_charset) break;
                                    sco_acs = 2; break;
                                  case 22:      /* disable bold */
                                    compatibility2(OTHER, VT220);
@@ -1954,7 +1995,8 @@ void term_out(void)
                        if (esc_nargs <= 1
                            && (esc_args[0] < 1 || esc_args[0] >= 24)) {
                            compatibility(VT340TEXT);
-                           request_resize(cols, def(esc_args[0], 24));
+                           if (!cfg.no_remote_resize)
+                               request_resize(cols, def(esc_args[0], 24));
                            deselect();
                        } else if (esc_nargs >= 1 &&
                                   esc_args[0] >= 1 &&
@@ -1972,8 +2014,9 @@ void term_out(void)
                                break;
                              case 3:
                                if (esc_nargs >= 3) {
-                                   move_window(def(esc_args[1], 0),
-                                               def(esc_args[2], 0));
+                                   if (!cfg.no_remote_resize)
+                                       move_window(def(esc_args[1], 0),
+                                                   def(esc_args[2], 0));
                                }
                                break;
                              case 4:
@@ -1993,8 +2036,9 @@ void term_out(void)
                                break;
                              case 8:
                                if (esc_nargs >= 3) {
-                                   request_resize(def(esc_args[1], cfg.width),
-                                                  def(esc_args[2], cfg.height));
+                                   if (!cfg.no_remote_resize)
+                                       request_resize(def(esc_args[2], cfg.width),
+                                                      def(esc_args[1], cfg.height));
                                }
                                break;
                              case 9:
@@ -2017,7 +2061,7 @@ void term_out(void)
                                break;
                              case 18:
                                len = sprintf(buf, "\033[8;%d;%dt",
-                                             cols, rows);
+                                             rows, cols);
                                ldisc_send(buf, len, 0);
                                break;
                              case 19:
@@ -2076,7 +2120,8 @@ void term_out(void)
                         */
                        compatibility(VT420);
                        if (esc_nargs == 1 && esc_args[0] > 0) {
-                           request_resize(cols, def(esc_args[0], cfg.height));
+                           if (!cfg.no_remote_resize)
+                               request_resize(cols, def(esc_args[0], cfg.height));
                            deselect();
                        }
                        break;
@@ -2087,7 +2132,8 @@ void term_out(void)
                         */
                        compatibility(VT340TEXT);
                        if (esc_nargs <= 1) {
-                           request_resize(def(esc_args[0], cfg.width), rows);
+                           if (!cfg.no_remote_resize)
+                               request_resize(def(esc_args[0], cfg.width), rows);
                            deselect();
                        }
                        break;
@@ -2214,10 +2260,12 @@ void term_out(void)
                         * Well we should do a soft reset at this point ...
                         */
                        if (!has_compat(VT420) && has_compat(VT100)) {
-                           if (reset_132)
-                               request_resize(132, 24);
-                           else
-                               request_resize(80, 24);
+                           if (!cfg.no_remote_resize) {
+                               if (reset_132)
+                                   request_resize(132, 24);
+                               else
+                                   request_resize(80, 24);
+                           }
                        }
 #endif
                        break;
@@ -3603,6 +3651,8 @@ int term_ldisc(int option)
  */
 int from_backend(int is_stderr, char *data, int len)
 {
+    assert(len > 0);
+
     bufchain_add(&inbuf, data, len);
 
     /*