billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=566c6d3680dc4509d85b0a1ca05a3729757fb9c4

commit 566c6d3680dc4509d85b0a1ca05a3729757fb9c4
Author: Boris Faure <bill...@gmail.com>
Date:   Tue Oct 18 00:14:19 2016 +0200

    termpty: correctly handle saving cursor + switching to/from altbuf
    
    Closes T4718
---
 src/bin/termpty.c    |  6 ++++--
 src/bin/termpty.h    |  2 +-
 src/bin/termptyesc.c | 42 +++++++++++++++++++++++++++---------------
 src/bin/termptyops.c |  8 ++++----
 4 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index c5e81e4..eaf6a41 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -308,8 +308,10 @@ _limit_coord(Termpty *ty)
    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);
+   TERMPTY_RESTRICT_FIELD(ty->cursor_save[0].cx, 0, ty->w);
+   TERMPTY_RESTRICT_FIELD(ty->cursor_save[0].cy, 0, ty->h);
+   TERMPTY_RESTRICT_FIELD(ty->cursor_save[1].cx, 0, ty->w);
+   TERMPTY_RESTRICT_FIELD(ty->cursor_save[1].cy, 0, ty->h);
 }
 
 Termpty *
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index ac1f553..6de51ba 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -152,7 +152,7 @@ struct _Termpty
    } termstate;
    struct {
         int           cx, cy;
-   } cursor_state, cursor_save;
+   } cursor_state, cursor_save[2];
    int exit_code;
    pid_t pid;
    unsigned int altbuf     : 1;
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index daabe1c..cc4277c 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -173,15 +173,6 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
 static void
 _switch_to_alternative_screen(Termpty *ty, int mode)
 {
-   DBG("switch to alternative screen, mode:%d", mode);
-   if (ty->altbuf)
-     {
-        // if we are looking at alt buf now,
-        // clear main buf before we swap it back
-        // into the screen2 save (so save is
-        // clear)
-        termpty_clear_all(ty);
-     }
    // swap screen content now
    if (mode != ty->altbuf)
      termpty_screen_swap(ty);
@@ -309,6 +300,9 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                      case 45: // ignore
                         WRN("TODO: Reverse-wraparound Mode");
                         break;
+                     case 47:
+                        _switch_to_alternative_screen(ty, mode);
+                        break;
                      case 59: // ignore
                         WRN("TODO: kanji terminal mode %i", mode);
                         break;
@@ -368,14 +362,31 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         DBG("Ignored screen mode %i", arg);
                         break;
                      case 1047:
-                     case 47:
+                        if (!mode && ty->altbuf)
+                            /* clear screen before switching back to normal */
+                            termpty_clear_screen(ty, TERMPTY_CLR_ALL);
                         _switch_to_alternative_screen(ty, mode);
-                        break;
                      case 1048:
-                     case 1049:
                         termpty_cursor_copy(ty, mode);
-                        if (arg == 1049)
-                          _switch_to_alternative_screen(ty, mode);
+                        break;
+                     case 1049:
+                        if (mode)
+                          {
+                             // switch to altbuf
+                             termpty_cursor_copy(ty, mode);
+                             _switch_to_alternative_screen(ty, mode);
+                             if (ty->altbuf)
+                               /* clear screen before switching back to normal 
*/
+                               termpty_clear_screen(ty, TERMPTY_CLR_ALL);
+                          }
+                        else
+                          {
+                             if (ty->altbuf)
+                               /* clear screen before switching back to normal 
*/
+                               termpty_clear_screen(ty, TERMPTY_CLR_ALL);
+                             _switch_to_alternative_screen(ty, mode);
+                             termpty_cursor_copy(ty, mode);
+                          }
                         break;
                      case 2004:
                         ty->bracketed_paste = mode;
@@ -668,7 +679,8 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
           {
            case 6:
               len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
-                             ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
+                             ty->cursor_state.cy + 1,
+                             ty->cursor_state.cx + 1);
               termpty_write(ty, bf, len);
               break;
            default:
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 252e271..3d035f8 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -401,12 +401,12 @@ termpty_cursor_copy(Termpty *ty, Eina_Bool save)
 {
    if (save)
      {
-        ty->cursor_save.cx = ty->cursor_state.cx;
-        ty->cursor_save.cy = ty->cursor_state.cy;
+        ty->cursor_save[ty->altbuf].cx = ty->cursor_state.cx;
+        ty->cursor_save[ty->altbuf].cy = ty->cursor_state.cy;
      }
    else
      {
-        ty->cursor_state.cx = ty->cursor_save.cx;
-        ty->cursor_state.cy = ty->cursor_save.cy;
+        ty->cursor_state.cx = ty->cursor_save[ty->altbuf].cx;
+        ty->cursor_state.cy = ty->cursor_save[ty->altbuf].cy;
      }
 }

-- 


Reply via email to