Added local-editing line discipline to make raw backend usable
[u/mdw/putty] / terminal.c
index 1e286ce..0218c09 100644 (file)
@@ -577,7 +577,7 @@ void term_out(void) {
            do_toplevel:
            switch (c) {
              case '\005':             /* terminal type query */
-               back->send ("\033[?1;2c", 7);
+               ldisc->send ("\033[?1;2c", 7);
                break;
              case '\007':
                beep();
@@ -628,6 +628,8 @@ void term_out(void) {
                    scroll (marg_t, marg_b, 1, TRUE);
                else if (curs_y < rows-1)
                    curs_y++;
+                if (cfg.lfhascr)
+                    curs_x = 0;
                fix_cpos;
                wrapnext = FALSE;
                disptop = scrtop;
@@ -663,7 +665,7 @@ void term_out(void) {
                    if (insert)
                        insch (1);
                    check_selection (cpos, cpos+1);
-                   *cpos++ = c | curr_attr | 
+                   *cpos++ = xlat_tty2scr((unsigned char)c) | curr_attr |
                        (c <= 0x7F ? cset_attr[cset] : ATTR_ASCII);
                    curs_x++;
                    if (curs_x == cols) {
@@ -764,7 +766,7 @@ void term_out(void) {
                must_update = TRUE;
                break;
              case 'Z':                /* terminal type query */
-               back->send ("\033[?6c", 5);
+               ldisc->send ("\033[?6c", 5);
                break;
              case 'c':                /* restore power-on settings */
                power_on();
@@ -900,13 +902,13 @@ void term_out(void) {
                must_update = TRUE;
                break;
              case 'c':                /* terminal type query */
-               back->send ("\033[?6c", 5);
+               ldisc->send ("\033[?6c", 5);
                break;
              case 'n':                /* cursor position query */
                if (esc_args[0] == 6) {
                    char buf[32];
                    sprintf (buf, "\033[%d;%dR", curs_y + 1, curs_x + 1);
-                   back->send (buf, strlen(buf));
+                   ldisc->send (buf, strlen(buf));
                }
                break;
              case 'h':                /* toggle a mode to high */
@@ -927,12 +929,12 @@ void term_out(void) {
                }
                break;
              case 'r':                /* set scroll margins */
-               if (esc_nargs <= 2) {
+               if (!esc_query && esc_nargs <= 2) {
                    int top, bot;
                    top = def(esc_args[0], 1) - 1;
                    if (top < 0)
                        top = 0;
-                   bot = (esc_nargs == 1 ? rows :
+                   bot = (esc_nargs <= 1 || esc_args[1] == 0 ? rows :
                           def(esc_args[1], rows)) - 1;
                    if (bot >= rows)
                        bot = rows-1;
@@ -1029,7 +1031,7 @@ void term_out(void) {
                    if (i == 0 || i == 1) {
                        strcpy (buf, "\033[2;1;1;112;112;1;0x");
                        buf[2] += i;
-                       back->send (buf, 20);
+                       ldisc->send (buf, 20);
                    }
                }
                break;
@@ -1254,8 +1256,8 @@ void term_paint (Context ctx, int l, int t, int r, int b) {
     right = (r - 1) / font_width;
     top = t / font_height;
     bottom = (b - 1) / font_height;
-    for (i = top; i <= bottom; i++)
-       for (j = left; j <= right; j++)
+    for (i = top; i <= bottom && i < rows ; i++)
+      for (j = left; j <= right && j < cols ; j++)
            disptext[i*(cols+1)+j] = ATTR_INVALID;
 
     do_paint (ctx, FALSE);
@@ -1339,7 +1341,20 @@ static void sel_spread (void) {
 }
 
 void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {
-    unsigned long *selpoint = disptop + y * (cols+1) + x;
+    unsigned long *selpoint;
+    
+    if (y<0) y = 0;
+    if (y>=rows) y = rows-1;
+    if (x<0) {
+        if (y > 0) {
+            x = cols-1;
+            y--;
+        } else
+            x = 0;
+    }
+    if (x>=cols) x = cols-1;
+
+    selpoint = disptop + y * (cols+1) + x;
 
     if (b == MB_SELECT && a == MA_CLICK) {
        deselect();
@@ -1421,10 +1436,20 @@ void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {
                       !(p <= data+len-sizeof(sel_nl) &&
                         !memcmp(p, sel_nl, sizeof(sel_nl))))
                    p++;
-               back->send (q, p-q);
+
+               {
+                   int i;
+                   unsigned char c;
+                   for(i=0;i<p-q;i++)
+                   {
+                       c=xlat_kbd2tty(q[i]);
+                       ldisc->send(&c,1);
+                   }
+               }
+
                if (p <= data+len-sizeof(sel_nl) &&
                    !memcmp(p, sel_nl, sizeof(sel_nl))) {
-                   back->send ("\r", 1);
+                   ldisc->send ("\r", 1);
                    p += sizeof(sel_nl);
                }
                q = p;