]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - terminal.c
Menu items now turn on and off in a vaguely useful way.
[PuTTY.git] / terminal.c
index b41eacda59a5c9bc21dc6666487f31505f3886b7..416b10167b0ee02cc6c65d4e315def0eba81e7da 100644 (file)
@@ -1,8 +1,10 @@
+#ifndef macintosh
 #include <windows.h>
+#endif /* not macintosh */
 
 #include <stdio.h>
 #include <stdlib.h>
-
+#include <string.h>
 #include "putty.h"
 
 static unsigned long *text;           /* buffer of text on terminal screen */
@@ -57,8 +59,6 @@ static unsigned char *tabs;
 #define MAXNL 5
 static int nl_count;
 
-static int scroll_heuristic;
-
 static enum {
     TOPLEVEL, IGNORE_NEXT,
     SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
@@ -95,6 +95,7 @@ static void erase_lots (int, int, int);
 static void swap_screen (int);
 static void update_sbar (void);
 static void deselect (void);
+static void scroll_display(int, int, int);
 
 /*
  * Set up power-on settings for the terminal.
@@ -144,7 +145,6 @@ void term_update(void) {
        do_paint (ctx, TRUE);
        free_ctx (ctx);
        nl_count = 0;
-       scroll_heuristic = 0;
     }
 }
 
@@ -398,9 +398,33 @@ static void scroll (int topline, int botline, int lines, int sb) {
                selend = scroll_top + size + scroll_size;
        }
     }
+#ifdef OPTIMISE_SCROLL
+    scroll_display(topline, botline, lines);
+#endif
+}
+
+#ifdef OPTIMISE_SCROLL
+static void scroll_display(int topline, int botline, int lines) {
+    unsigned long *start, *end;
+    int distance, size, i;
 
-    scroll_heuristic += lines;
+    start = disptext + topline * (cols + 1);
+    end = disptext + (botline + 1) * (cols + 1);
+    distance = (lines > 0 ? lines : -lines) * (cols + 1);
+    size = end - start - distance;
+    if (lines > 0) {
+       memmove(start, start + distance, size * TSIZE);
+       for (i = 0; i < distance; i++)
+           (start + size)[i] |= ATTR_INVALID;
+    } else {
+       memmove(start + distance, start, size * TSIZE);
+       for (i = 0; i < distance; i++)
+           start[i] |= ATTR_INVALID;
+    }
+    do_scroll(topline, botline, lines);
 }
+#endif /* OPTIMISE_SCROLL */
+    
 
 /*
  * Move the cursor to a given position, clipping at boundaries. We
@@ -614,7 +638,7 @@ void term_out(void) {
                termstate = SEEN_OSC;
                esc_args[0] = 0;
                break;
-             case '\r':
+             case '\015':
                curs_x = 0;
                wrapnext = FALSE;
                fix_cpos;
@@ -623,7 +647,7 @@ void term_out(void) {
                break;
              case '\013':
              case '\014':
-             case '\n':
+             case '\012':
                if (curs_y == marg_b)
                    scroll (marg_t, marg_b, 1, TRUE);
                else if (curs_y < rows-1)
@@ -696,8 +720,8 @@ void term_out(void) {
            termstate = TOPLEVEL;
            switch (c) {
              case '\005': case '\007': case '\b': case '\016': case '\017':
-             case '\033': case 0233: case 0234: case 0235: case '\r':
-             case '\013': case '\014': case '\n': case '\t':
+             case '\033': case 0233: case 0234: case 0235: case '\015':
+             case '\013': case '\014': case '\012': case '\t':
                termstate = TOPLEVEL;
                goto do_toplevel;      /* hack... */
              case ' ':                /* some weird sequence? */
@@ -786,8 +810,8 @@ void term_out(void) {
            termstate = TOPLEVEL;      /* default */
            switch (c) {
              case '\005': case '\007': case '\b': case '\016': case '\017':
-             case '\033': case 0233: case 0234: case 0235: case '\r':
-             case '\013': case '\014': case '\n': case '\t':
+             case '\033': case 0233: case 0234: case 0235: case '\015':
+             case '\013': case '\014': case '\012': case '\t':
                termstate = TOPLEVEL;
                goto do_toplevel;      /* hack... */
              case '0': case '1': case '2': case '3': case '4':
@@ -934,7 +958,7 @@ void term_out(void) {
                    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;
@@ -1056,8 +1080,8 @@ void term_out(void) {
            osc_w = FALSE;
            switch (c) {
              case '\005': case '\007': case '\b': case '\016': case '\017':
-             case '\033': case 0233: case 0234: case 0235: case '\r':
-             case '\013': case '\014': case '\n': case '\t':
+             case '\033': case 0233: case 0234: case 0235: case '\015':
+             case '\013': case '\014': case '\012': case '\t':
                termstate = TOPLEVEL;
                goto do_toplevel;      /* hack... */
              case 'P':                /* Linux palette sequence */
@@ -1134,8 +1158,8 @@ void term_out(void) {
          case SEEN_OSC_W:
            switch (c) {
              case '\005': case '\007': case '\b': case '\016': case '\017':
-             case '\033': case 0233: case 0234: case 0235: case '\r':
-             case '\013': case '\014': case '\n': case '\t':
+             case '\033': case 0233: case 0234: case 0235: case '\015':
+             case '\013': case '\014': case '\012': case '\t':
                termstate = TOPLEVEL;
                goto do_toplevel;      /* hack... */
              case '0': case '1': case '2': case '3': case '4':
@@ -1272,6 +1296,10 @@ void term_paint (Context ctx, int l, int t, int r, int b) {
  */
 void term_scroll (int rel, int where) {
     int n = where * (cols+1);
+#ifdef OPTIMISE_SCROLL
+    unsigned long *olddisptop = disptop;
+    int shift;
+#endif /* OPTIMISE_SCROLL */
 
     disptop = (rel < 0 ? scrtop :
               rel > 0 ? sbtop : disptop) + n;
@@ -1280,6 +1308,11 @@ void term_scroll (int rel, int where) {
     if (disptop > scrtop)
        disptop = scrtop;
     update_sbar();
+#ifdef OPTIMISE_SCROLL
+    shift = (disptop - olddisptop) / (cols + 1);
+    if (shift < rows && shift > -rows)
+       scroll_display(0, rows - 1, shift);
+#endif /* OPTIMISE_SCROLL */
     term_update();
 }
 
@@ -1345,7 +1378,13 @@ void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {
     
     if (y<0) y = 0;
     if (y>=rows) y = rows-1;
-    if (x<0) x = 0;
+    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;
@@ -1433,7 +1472,7 @@ void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) {
                back->send (q, p-q);
                if (p <= data+len-sizeof(sel_nl) &&
                    !memcmp(p, sel_nl, sizeof(sel_nl))) {
-                   back->send ("\r", 1);
+                   back->send ("\015", 1);
                    p += sizeof(sel_nl);
                }
                q = p;