raster pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=074eece5f7d1f749f96bd03a77e82156d551941a

commit 074eece5f7d1f749f96bd03a77e82156d551941a
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Wed Jun 3 15:00:13 2015 +0900

    Revert "ensure cursor coordinates are always valid"
    
    This reverts commit 1f3f779258c86b170edb3e634548a446fe5c9b58.
    
    this breaks terminal scrolling entirely! can't scroll anymore at all
    in standard shell. just try a simple: find / -print
---
 src/bin/termpty.c    | 28 ++++++++++++++++------------
 src/bin/termpty.h    |  8 --------
 src/bin/termptyesc.c | 46 ++++++++++++++++++++--------------------------
 src/bin/termptyops.c | 13 +------------
 4 files changed, 37 insertions(+), 58 deletions(-)

diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 5e49ba4..c9b8b7d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -270,14 +270,21 @@ _cb_fd_read(void *data, Ecore_Fd_Handler *fd_handler 
EINA_UNUSED)
 static void
 _limit_coord(Termpty *ty)
 {
-   TERMPTY_RESTRICT_FIELD(ty->termstate.had_cr_x, 0, ty->w);
-   TERMPTY_RESTRICT_FIELD(ty->termstate.had_cr_y, 0, ty->h);
-
-   TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
-   TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
-
-   TERMPTY_RESTRICT_FIELD(ty->cursor_save.cx, 0, ty->w);
-   TERMPTY_RESTRICT_FIELD(ty->cursor_save.cy, 0, ty->h);
+   ty->termstate.wrapnext = 0;
+   if (ty->termstate.had_cr_x >= ty->w)
+     ty->termstate.had_cr_x = ty->w - 1;
+   if (ty->termstate.had_cr_y >= ty->h)
+     ty->termstate.had_cr_y = ty->h - 1;
+
+   if (ty->cursor_state.cx >= ty->w)
+     ty->cursor_state.cx = ty->w - 1;
+   if (ty->cursor_state.cy >= ty->h)
+     ty->cursor_state.cy = ty->h - 1;
+
+   if (ty->cursor_save.cx >= ty->w)
+     ty->cursor_save.cx = ty->w - 1;
+   if (ty->cursor_save.cy >= ty->h)
+     ty->cursor_save.cy = ty->h - 1;
 }
 
 Termpty *
@@ -890,10 +897,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
 
    ty->cursor_state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
 
-   if (altbuf)
-     termpty_screen_swap(ty);
-
-   ty->termstate.wrapnext = 0;
+   if (altbuf) termpty_screen_swap(ty);
 
    _limit_coord(ty);
 
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 7aba97a..d5aad70 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -260,12 +260,4 @@ extern int _termpty_log_dom;
 #define TERMPTY_FMTCLR(Tatt) \
    (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0
 
-#define TERMPTY_RESTRICT_FIELD(Field, Min, Max) \
-   do {                                         \
-   if (Field >= Max)                            \
-     Field = Max - 1;                           \
-   else if (Field < Min)                        \
-     Field = Min;                               \
-   } while (0)
-
 #endif
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 6de1340..14dbbb7 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -66,7 +66,7 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
          ty->termstate.had_cr = 0;
          ty->termstate.wrapnext = 0;
          ty->cursor_state.cx--;
-         TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+         if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
          return;
       case 0x09: // HT  '\t' (horizontal tab)
          DBG("->HT");
@@ -75,7 +75,8 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
          ty->termstate.wrapnext = 0;
          ty->cursor_state.cx += 8;
          ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
-         TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+         if (ty->cursor_state.cx >= ty->w)
+           ty->cursor_state.cx = ty->w - 1;
          return;
       case 0x0a: // LF  '\n' (new line)
       case 0x0b: // VT  '\v' (vertical tab)
@@ -90,7 +91,6 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
          ty->termstate.wrapnext = 0;
          if (ty->termstate.crlf) ty->cursor_state.cx = 0;
          ty->cursor_state.cy++;
-         TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
          termpty_text_scroll_test(ty, EINA_TRUE);
          return;
       case 0x0d: // CR  '\r' (carriage ret)
@@ -682,7 +682,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
                termpty_text_append(ty, blank, 1);
              ty->termstate.insert = pi;
              ty->cursor_state.cx = cx;
-             TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
           }
         break;
       case 'A': // cursor up N
@@ -692,7 +691,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("cursor up %d", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
         break;
       case 'B': // cursor down N
         arg = _csi_arg_get(&b);
@@ -700,7 +698,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("cursor down %d", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
         break;
       case 'D': // cursor left N
         arg = _csi_arg_get(&b);
@@ -708,8 +705,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("cursor left %d", arg);
         ty->termstate.wrapnext = 0;
         for (i = 0; i < arg; i++)
-          ty->cursor_state.cx--;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+          {
+             ty->cursor_state.cx--;
+             if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
+          }
         break;
       case 'C': // cursor right N
       case 'a': // cursor right N
@@ -718,8 +717,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("cursor right %d", arg);
         ty->termstate.wrapnext = 0;
         for (i = 0; i < arg; i++)
-          ty->cursor_state.cx++;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+          {
+             ty->cursor_state.cx++;
+             if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
+          }
         break;
       case 'H': // cursor pos set
       case 'f': // cursor pos set
@@ -739,7 +740,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              if (b)
                {
                   ty->cursor_state.cy = arg;
-                  TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
                   arg = _csi_arg_get(&b);
                   if (arg < 1) arg = 1;
                   arg--;
@@ -747,14 +747,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              else arg = 0;
 
              if (arg >= ty->w) arg = ty->w - 1;
-             if (b)
-               {
-                  ty->cursor_state.cx = arg;
-                  TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
-               }
+             if (b) ty->cursor_state.cx = arg;
           }
         ty->cursor_state.cy += ty->termstate.margin_top;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
        break;
       case 'G': // to column N
         arg = _csi_arg_get(&b);
@@ -762,7 +757,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("to column %d", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cx = arg - 1;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
+        if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
+        else if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
         break;
       case 'd': // to row N
         arg = _csi_arg_get(&b);
@@ -770,7 +766,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("to row %d", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy = arg - 1;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
+        if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
+        else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
         break;
       case 'E': // down relative N rows, and to col 0
         arg = _csi_arg_get(&b);
@@ -778,7 +775,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("down relative %d rows, and to col 0", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy += arg;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
+        if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
+        else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
         ty->cursor_state.cx = 0;
         break;
       case 'F': // up relative N rows, and to col 0
@@ -787,7 +785,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         DBG("up relative %d rows, and to col 0", arg);
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy -= arg;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
+        if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
+        else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
         ty->cursor_state.cx = 0;
         break;
       case 'X': // erase N chars
@@ -1030,9 +1029,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
           if (!arg)
             {
                ty->cursor_state.cx = cx;
-               TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
                ty->cursor_state.cy = cy;
-               TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
             }
        }
        break;
@@ -1572,20 +1569,17 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
       case 'M': // move to prev line
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy--;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
         termpty_text_scroll_rev_test(ty, EINA_TRUE);
         return 1;
       case 'D': // move to next line
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cy++;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
         termpty_text_scroll_test(ty, EINA_FALSE);
         return 1;
       case 'E': // add \n\r
         ty->termstate.wrapnext = 0;
         ty->cursor_state.cx = 0;
         ty->cursor_state.cy++;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
         termpty_text_scroll_test(ty, EINA_FALSE);
         return 1;
       case 'Z': // same a 'ESC [ Pn c'
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index d35900c..e9d93f8 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -7,7 +7,6 @@
 #include "termptygfx.h"
 #include "termptysave.h"
 #include "miniview.h"
-#include <assert.h>
 
 #undef CRITICAL
 #undef ERR
@@ -152,7 +151,6 @@ termpty_text_scroll_test(Termpty *ty, Eina_Bool clear)
      {
         termpty_text_scroll(ty, clear);
         ty->cursor_state.cy = e - 1;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
      }
 }
 
@@ -166,7 +164,6 @@ termpty_text_scroll_rev_test(Termpty *ty, Eina_Bool clear)
      {
         termpty_text_scroll_rev(ty, clear);
         ty->cursor_state.cy = b;
-        TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
      }
 }
 
@@ -189,7 +186,6 @@ termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
              ty->termstate.wrapnext = 0;
              ty->cursor_state.cx = 0;
              ty->cursor_state.cy++;
-             TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
              termpty_text_scroll_test(ty, EINA_TRUE);
              cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
           }
@@ -224,10 +220,7 @@ termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
              if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset)))
                ty->termstate.wrapnext = 1;
              else
-               {
-                  ty->cursor_state.cx += offset;
-                  TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
-               }
+               ty->cursor_state.cx += offset;
           }
         else
           {
@@ -242,10 +235,8 @@ termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
              if (ty->cursor_state.cx > (ty->w - offset))
                {
                   ty->cursor_state.cx = ty->w - offset;
-                  TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
                   return;
                }
-             TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
           }
      }
 }
@@ -257,8 +248,6 @@ termpty_clear_line(Termpty *ty, Termpty_Clear mode, int 
limit)
    int n = 0;
    Evas_Coord x = 0, y = ty->cursor_state.cy;
 
-   assert (y >= 0 && y < ty->h);
-
    switch (mode)
      {
       case TERMPTY_CLR_END:

-- 


Reply via email to