billiob pushed a commit to branch master.

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

commit be62d87f89e5e0ada3d8cbfe3dd091eeb9b45391
Author: Boris Faure <bill...@gmail.com>
Date:   Sun Apr 19 19:59:29 2015 +0200

    separate "termstate" from cursor state and screens. Closes T725
---
 src/bin/keyin.c      |  14 +-
 src/bin/miniview.c   |   2 +-
 src/bin/termio.c     |   8 +-
 src/bin/termpty.c    |  52 +++----
 src/bin/termpty.h    |  54 ++++---
 src/bin/termptydbl.c |   2 +-
 src/bin/termptyesc.c | 417 +++++++++++++++++++++++++--------------------------
 src/bin/termptygfx.c |   6 +-
 src/bin/termptygfx.h |   2 +-
 src/bin/termptyops.c | 173 +++++++++++----------
 src/bin/termptyops.h |   2 +-
 11 files changed, 365 insertions(+), 367 deletions(-)

diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index e61f210..f5bc81e 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -69,8 +69,8 @@ _key_try(Termpty *ty, const Tty_Key *map, int len, const 
Evas_Event_Key_Down *ev
              const struct _s *s = NULL;
              const Key_Values *kv;
 
-             if (!ty->state.appcursor) kv = &map[i].default_mode;
-             else                      kv = &map[i].cursor;
+             if (!ty->termstate.appcursor) kv = &map[i].default_mode;
+             else                          kv = &map[i].cursor;
              if (!alt && !ctrl && !shift)     s = &kv->plain;
              else if (alt && !ctrl && !shift) s = &kv->alt;
              else if (!alt && ctrl && !shift) s = &kv->ctrl;
@@ -112,7 +112,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down 
*ev,
      {
         if (alt)
           termpty_write(ty, "\033", 1);
-        if (ty->state.send_bs)
+        if (ty->termstate.send_bs)
           {
              termpty_write(ty, "\b", 1);
           }
@@ -135,7 +135,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down 
*ev,
      {
         if (alt)
           termpty_write(ty, "\033", 1);
-        if (ty->state.crlf)
+        if (ty->termstate.crlf)
           {
              termpty_write(ty, "\r\n", sizeof("\r\n") - 1);
              return;
@@ -150,7 +150,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down 
*ev,
      {
         if (!evas_key_lock_is_set(ev->locks, "Num_Lock"))
           {
-             if (ty->state.alt_kp)
+             if (ty->termstate.alt_kp)
                {
                   if (_key_try(ty, tty_keys_kp_app,
                                
sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
@@ -242,10 +242,10 @@ keyin_handle(Keys_Handler *khdl, Termpty *ty, const 
Evas_Event_Key_Down *ev,
      }
 
    // if term app asked for kbd lock - dont handle here
-   if (ty->state.kbd_lock) return EINA_TRUE;
+   if (ty->termstate.kbd_lock) return EINA_TRUE;
    // if app asked us to not do autorepeat - ignore press if is it is the same
    // timestamp as last one
-   if ((ty->state.no_autorepeat) &&
+   if ((ty->termstate.no_autorepeat) &&
        (ev->timestamp == khdl->last_keyup)) return EINA_TRUE;
    if (!khdl->composing)
      {
diff --git a/src/bin/miniview.c b/src/bin/miniview.c
index a468538..06dc287 100644
--- a/src/bin/miniview.c
+++ b/src/bin/miniview.c
@@ -81,7 +81,7 @@ static void
 _draw_cell(const Termpty *ty, unsigned int *pixel, const Termcell *cell, 
unsigned int *colors)
 {
    int fg, bg, fgext, bgext;
-   int inv = ty->state.reverse;
+   int inv = ty->termstate.reverse;
    Eina_Unicode codepoint;
 
    codepoint = cell->codepoint;
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 634813d..44a9015 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -4512,7 +4512,7 @@ _smart_apply(Evas_Object *obj)
         blk->was_active = blk->active;
         blk->active = EINA_FALSE;
      }
-   inv = sd->pty->state.reverse;
+   inv = sd->pty->termstate.reverse;
    termpty_cellcomp_freeze(sd->pty);
    for (y = 0; y < sd->grid.h; y++)
      {
@@ -4753,12 +4753,12 @@ _smart_apply(Evas_Object *obj)
                (sd->pty->block.active, l);
           }
      }
-   if ((sd->scroll != 0) || (sd->pty->state.hidecursor))
+   if ((sd->scroll != 0) || (sd->pty->termstate.hide_cursor))
      evas_object_hide(sd->cursor.obj);
    else
      evas_object_show(sd->cursor.obj);
-   sd->cursor.x = sd->pty->state.cx;
-   sd->cursor.y = sd->pty->state.cy;
+   sd->cursor.x = sd->pty->cursor_state.cx;
+   sd->cursor.y = sd->pty->cursor_state.cy;
    evas_object_move(sd->cursor.obj,
                     ox + ((sd->cursor.x + preedit_x) * sd->font.chw),
                     oy + ((sd->cursor.y + preedit_y) * sd->font.chh));
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index c1590f2..be6d793 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -268,13 +268,23 @@ _cb_fd_read(void *data, Ecore_Fd_Handler *fd_handler 
EINA_UNUSED)
 }
 
 static void
-_limit_coord(Termpty *ty, Termstate *state)
+_limit_coord(Termpty *ty)
 {
-   state->wrapnext = 0;
-   if (state->cx >= ty->w) state->cx = ty->w - 1;
-   if (state->cy >= ty->h) state->cy = ty->h - 1;
-   if (state->had_cr_x >= ty->w) state->had_cr_x = ty->w - 1;
-   if (state->had_cr_y >= ty->h) state->had_cr_y = ty->h - 1;
+   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 *
@@ -298,8 +308,6 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const 
char *cd,
    ty->backmax = backscroll;
 
    _termpty_reset_state(ty);
-   ty->save = ty->state;
-   ty->swap = ty->state;
 
    ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
    if (!ty->screen)
@@ -799,7 +807,7 @@ termpty_line_rewrap(Termpty *ty, int y_start, int y_end,
                        new_back[new_y + ty->backmax] = new_ts;
                     }
                }
-             if (y == ty->state.cy)
+             if (y == ty->cursor_state.cy)
                {
                   *new_cyp = new_y_start;
                }
@@ -831,7 +839,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
    Termcell *new_screen = NULL;
    Termsave **new_back = NULL;
    int y_start = 0, y_end = 0, new_y_start = 0, new_y_end,
-       new_cy = ty->state.cy;
+       new_cy = ty->cursor_state.cy;
    int i, altbuf = 0;
 
    if ((ty->w == new_w) && (ty->h == new_h)) return;
@@ -855,7 +863,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
      goto bad;
    new_back = calloc(sizeof(Termsave *), ty->backmax);
 
-   y_end = ty->state.cy;
+   y_end = ty->cursor_state.cy;
    new_y_end = new_h - 1;
    /* For each "full line" in old buffers, rewrap.
     * From most recent to oldest */
@@ -885,15 +893,13 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
    ty->circular_offset = MAX(new_y_start, 0);
    ty->backpos = 0;
    ty->backscroll_num = MAX(-new_y_start, 0);
-   ty->state.had_cr = 0;
+   ty->termstate.had_cr = 0;
 
-   ty->state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
+   ty->cursor_state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
 
    if (altbuf) termpty_screen_swap(ty);
 
-   _limit_coord(ty, &(ty->state));
-   _limit_coord(ty, &(ty->swap));
-   _limit_coord(ty, &(ty->save));
+   _limit_coord(ty);
 
    _pty_size(ty);
 
@@ -1100,25 +1106,11 @@ termpty_screen_swap(Termpty *ty)
 {
    Termcell *tmp_screen;
    int tmp_circular_offset;
-   Termstate tmp;
 
    tmp_screen = ty->screen;
    ty->screen = ty->screen2;
    ty->screen2 = tmp_screen;
 
-   if (ty->altbuf)
-     {
-        tmp = ty->state;
-        ty->state = ty->swap;
-        ty->swap = tmp;
-     }
-   else
-     {
-        tmp = ty->swap;
-        ty->swap = ty->state;
-        ty->state = tmp;
-     }
-
    tmp_circular_offset = ty->circular_offset;
    ty->circular_offset = ty->circular_offset2;
    ty->circular_offset2 = tmp_circular_offset;
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 057724f..d5aad70 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -6,7 +6,6 @@
 typedef struct _Termpty       Termpty;
 typedef struct _Termcell      Termcell;
 typedef struct _Termatt       Termatt;
-typedef struct _Termstate     Termstate;
 typedef struct _Termsave      Termsave;
 typedef struct _Termsavecomp  Termsavecomp;
 typedef struct _Termblock     Termblock;
@@ -84,32 +83,6 @@ struct _Termatt
 #endif
 };
 
-struct _Termstate
-{
-   int           cx, cy;
-   Termatt       att;
-   unsigned char charset;
-   unsigned char charsetch;
-   unsigned char chset[4];
-   int           scroll_y1, scroll_y2;
-   int           had_cr_x, had_cr_y;
-   int           margin_top; // soon, more to come...
-   unsigned int  multibyte : 1;
-   unsigned int  alt_kp : 1;
-   unsigned int  insert : 1;
-   unsigned int  appcursor : 1;
-   unsigned int  wrap : 1;
-   unsigned int  wrapnext : 1;
-   unsigned int  hidecursor : 1;
-   unsigned int  crlf : 1;
-   unsigned int  had_cr : 1;
-   unsigned int  send_bs : 1;
-   unsigned int  kbd_lock : 1;
-   unsigned int  reverse : 1;
-   unsigned int  no_autorepeat : 1;
-   unsigned int  cjk_ambiguous_wide : 1;
-};
-
 struct _Termpty
 {
    Evas_Object *obj;
@@ -158,7 +131,32 @@ struct _Termpty
       unsigned char by_line   : 1;
       unsigned char is_top_to_bottom : 1;
    } selection;
-   Termstate state, save, swap;
+   struct {
+        Termatt       att;
+        unsigned char charset;
+        unsigned char charsetch;
+        unsigned char chset[4];
+        int           scroll_y1, scroll_y2;
+        int           had_cr_x, had_cr_y;
+        int           margin_top; // soon, more to come...
+        unsigned int  multibyte : 1;
+        unsigned int  alt_kp : 1;
+        unsigned int  insert : 1;
+        unsigned int  appcursor : 1;
+        unsigned int  wrap : 1;
+        unsigned int  wrapnext : 1;
+        unsigned int  crlf : 1;
+        unsigned int  had_cr : 1;
+        unsigned int  send_bs : 1;
+        unsigned int  kbd_lock : 1;
+        unsigned int  reverse : 1;
+        unsigned int  no_autorepeat : 1;
+        unsigned int  cjk_ambiguous_wide : 1;
+        unsigned int  hide_cursor : 1;
+   } termstate;
+   struct {
+        int           cx, cy;
+   } cursor_state, cursor_save;
    int exit_code;
    pid_t pid;
    unsigned int altbuf     : 1;
diff --git a/src/bin/termptydbl.c b/src/bin/termptydbl.c
index b4c442d..7e1e4b0 100644
--- a/src/bin/termptydbl.c
+++ b/src/bin/termptydbl.c
@@ -41,7 +41,7 @@ _termpty_is_dblwidth_slow_get(Termpty *ty, int g)
      return EINA_TRUE;
    // FIXME: can optimize by breaking into tree and ranges
    // (A)
-   if (ty->state.cjk_ambiguous_wide)
+   if (ty->termstate.cjk_ambiguous_wide)
      {
         // grep ';A #' EastAsianWidth.txt | wc -l
         // :(
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 8452d69..530a97a 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -58,51 +58,51 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
    switch (*cc)
      {
       case 0x07: // BEL '\a' (bell)
-         ty->state.had_cr = 0;
+         ty->termstate.had_cr = 0;
          if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
          return;
       case 0x08: // BS  '\b' (backspace)
          DBG("->BS");
-         ty->state.had_cr = 0;
-         ty->state.wrapnext = 0;
-         ty->state.cx--;
-         if (ty->state.cx < 0) ty->state.cx = 0;
+         ty->termstate.had_cr = 0;
+         ty->termstate.wrapnext = 0;
+         ty->cursor_state.cx--;
+         if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
          return;
       case 0x09: // HT  '\t' (horizontal tab)
          DBG("->HT");
-         ty->state.had_cr = 0;
-         TERMPTY_SCREEN(ty, ty->state.cx, ty->state.cy).att.tab = 1;
-         ty->state.wrapnext = 0;
-         ty->state.cx += 8;
-         ty->state.cx = (ty->state.cx / 8) * 8;
-         if (ty->state.cx >= ty->w)
-           ty->state.cx = ty->w - 1;
+         ty->termstate.had_cr = 0;
+         TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy).att.tab 
= 1;
+         ty->termstate.wrapnext = 0;
+         ty->cursor_state.cx += 8;
+         ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
+         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)
       case 0x0c: // FF  '\f' (form feed)
          DBG("->LF");
-         if (ty->state.had_cr)
+         if (ty->termstate.had_cr)
            {
-              TERMPTY_SCREEN(ty, ty->state.had_cr_x,
-                                 ty->state.had_cr_y).att.newline = 1;
+              TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
+                                 ty->termstate.had_cr_y).att.newline = 1;
            }
-         ty->state.had_cr = 0;
-         ty->state.wrapnext = 0;
-         if (ty->state.crlf) ty->state.cx = 0;
-         ty->state.cy++;
+         ty->termstate.had_cr = 0;
+         ty->termstate.wrapnext = 0;
+         if (ty->termstate.crlf) ty->cursor_state.cx = 0;
+         ty->cursor_state.cy++;
          _termpty_text_scroll_test(ty, EINA_TRUE);
          return;
       case 0x0d: // CR  '\r' (carriage ret)
          DBG("->CR");
-         if (ty->state.cx != 0)
+         if (ty->cursor_state.cx != 0)
            {
-              ty->state.had_cr_x = ty->state.cx;
-              ty->state.had_cr_y = ty->state.cy;
-              ty->state.wrapnext = 0;
+              ty->termstate.had_cr_x = ty->cursor_state.cx;
+              ty->termstate.had_cr_y = ty->cursor_state.cy;
+              ty->termstate.wrapnext = 0;
            }
-         ty->state.cx = 0;
-//         ty->state.had_cr = 1;
+         ty->cursor_state.cx = 0;
+//         ty->termstate.had_cr = 1;
          return;
       default:
          return;
@@ -149,14 +149,14 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                   switch (arg)
                     {
                      case 1:
-                        ty->state.appcursor = mode;
+                        ty->termstate.appcursor = mode;
                         break;
                      case 2:
-                        ty->state.kbd_lock = mode;
+                        ty->termstate.kbd_lock = mode;
                         break;
                      case 3: // 132 column modeā€¦ should we handle this?
 #if defined(SUPPORT_80_132_COLUMNS)
-                        if (ty->state.att.is_80_132_mode_allowed)
+                        if (ty->termstate.att.is_80_132_mode_allowed)
                           {
                              /* ONLY FOR TESTING PURPOSE FTM */
                              Evas_Object *wn;
@@ -180,18 +180,18 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         WRN("TODO: scrolling mode (DECSCLM): %i", mode);
                         break;
                      case 5:
-                        ty->state.reverse = mode;
+                        ty->termstate.reverse = mode;
                         break;
                      case 6:
                         if (mode)
                           {
-                             ty->state.margin_top = ty->state.cy;
-                             ty->state.cx = 0;
+                             ty->termstate.margin_top = ty->cursor_state.cy;
+                             ty->cursor_state.cx = 0;
                           }
                         else
                           {
-                             ty->state.cx = 0;
-                             ty->state.margin_top = 0;
+                             ty->cursor_state.cx = 0;
+                             ty->termstate.margin_top = 0;
                           }
                         DBG("origin mode (%d): cursor is at 0,0"
                             " cursor limited to screen/start point"
@@ -200,10 +200,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         break;
                      case 7:
                         DBG("set wrap mode to %i", mode);
-                        ty->state.wrap = mode;
+                        ty->termstate.wrap = mode;
                         break;
                      case 8:
-                        ty->state.no_autorepeat = !mode;
+                        ty->termstate.no_autorepeat = !mode;
                         DBG("auto repeat %i", mode);
                         break;
                      case 9:
@@ -218,10 +218,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         WRN("TODO: set print extent to full screen");
                         break;
                      case 20: // crfl==1 -> cur moves to col 0 on LF, FF or 
VT, ==0 -> mode is cr+lf
-                        ty->state.crlf = mode;
+                        ty->termstate.crlf = mode;
                         break;
                      case 25:
-                        ty->state.hidecursor = !mode;
+                        ty->termstate.hide_cursor = !mode;
                         DBG("hide cursor: %d", !mode);
                         break;
                      case 30: // ignore
@@ -242,7 +242,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                      case 40:
                         DBG("Allow 80 -> 132 Mode %i", mode);
 #if defined(SUPPORT_80_132_COLUMNS)
-                        ty->state.att.is_80_132_mode_allowed = mode;
+                        ty->termstate.att.is_80_132_mode_allowed = mode;
 #endif
                         break;
                      case 45: // ignore
@@ -255,7 +255,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         WRN("TODO: app keypad mode %i", mode);
                         break;
                      case 67:
-                        ty->state.send_bs = mode;
+                        ty->termstate.send_bs = mode;
                         DBG("backspace send bs not del = %i", mode);
                         break;
                      case 1000:
@@ -312,10 +312,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                         break;
                      case 1048:
                      case 1049:
-                        if (mode)
-                          _termpty_cursor_copy(&(ty->state), &(ty->save));
-                        else
-                          _termpty_cursor_copy(&(ty->save), &(ty->state));
+                        _termpty_cursor_copy(ty, mode);
                         if (arg == 1049)
                           _switch_to_alternative_screen(ty, mode);
                         break;
@@ -345,11 +342,11 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, 
Eina_Unicode *b)
                   switch (arg)
                     {
                      case 1:
-                        ty->state.appcursor = mode;
+                        ty->termstate.appcursor = mode;
                         break;
                      case 4:
                         DBG("set insert mode to %i", mode);
-                        ty->state.insert = mode;
+                        ty->termstate.insert = mode;
                         break;
                      case 34:
                         WRN("TODO: hebrew keyboard mapping: %i", mode);
@@ -381,75 +378,75 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
      {
         int arg = _csi_arg_get(&b);
         if ((first) && (!b))
-          _termpty_reset_att(&(ty->state.att));
+          _termpty_reset_att(&(ty->termstate.att));
         else if (b)
           {
              first = 0;
              switch (arg)
                {
                 case 0: // reset to normal
-                   _termpty_reset_att(&(ty->state.att));
+                   _termpty_reset_att(&(ty->termstate.att));
                    break;
                 case 1: // bold/bright
-                   ty->state.att.bold = 1;
+                   ty->termstate.att.bold = 1;
                    break;
                 case 2: // faint
-                   ty->state.att.faint = 1;
+                   ty->termstate.att.faint = 1;
                    break;
                 case 3: // italic
 #if defined(SUPPORT_ITALIC)
-                   ty->state.att.italic = 1;
+                   ty->termstate.att.italic = 1;
 #endif
                    break;
                 case 4: // underline
-                   ty->state.att.underline = 1;
+                   ty->termstate.att.underline = 1;
                    break;
                 case 5: // blink
-                   ty->state.att.blink = 1;
+                   ty->termstate.att.blink = 1;
                    break;
                 case 6: // blink rapid
-                   ty->state.att.blink2 = 1;
+                   ty->termstate.att.blink2 = 1;
                    break;
                 case 7: // reverse
-                   ty->state.att.inverse = 1;
+                   ty->termstate.att.inverse = 1;
                    break;
                 case 8: // invisible
-                   ty->state.att.invisible = 1;
+                   ty->termstate.att.invisible = 1;
                    break;
                 case 9: // strikethrough
-                   ty->state.att.strike = 1;
+                   ty->termstate.att.strike = 1;
                    break;
                 case 20: // fraktur!
-                   ty->state.att.fraktur = 1;
+                   ty->termstate.att.fraktur = 1;
                    break;
                 case 21: // no bold/bright
-                   ty->state.att.bold = 0;
+                   ty->termstate.att.bold = 0;
                    break;
                 case 22: // no bold/bright, no faint
-                   ty->state.att.bold = 0;
-                   ty->state.att.faint = 0;
+                   ty->termstate.att.bold = 0;
+                   ty->termstate.att.faint = 0;
                    break;
                 case 23: // no italic, not fraktur
 #if defined(SUPPORT_ITALIC)
-                   ty->state.att.italic = 0;
+                   ty->termstate.att.italic = 0;
 #endif
-                   ty->state.att.fraktur = 0;
+                   ty->termstate.att.fraktur = 0;
                    break;
                 case 24: // no underline
-                   ty->state.att.underline = 0;
+                   ty->termstate.att.underline = 0;
                    break;
                 case 25: // no blink
-                   ty->state.att.blink = 0;
-                   ty->state.att.blink2 = 0;
+                   ty->termstate.att.blink = 0;
+                   ty->termstate.att.blink2 = 0;
                    break;
                 case 27: // no reverse
-                   ty->state.att.inverse = 0;
+                   ty->termstate.att.inverse = 0;
                    break;
                 case 28: // no invisible
-                   ty->state.att.invisible = 0;
+                   ty->termstate.att.invisible = 0;
                    break;
                 case 29: // no strikethrough
-                   ty->state.att.strike = 0;
+                   ty->termstate.att.strike = 0;
                    break;
                 case 30: // fg
                 case 31:
@@ -459,9 +456,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                 case 35:
                 case 36:
                 case 37:
-                   ty->state.att.fg256 = 0;
-                   ty->state.att.fg = (arg - 30) + COL_BLACK;
-                   ty->state.att.fgintense = 0;
+                   ty->termstate.att.fg256 = 0;
+                   ty->termstate.att.fg = (arg - 30) + COL_BLACK;
+                   ty->termstate.att.fgintense = 0;
                    break;
                 case 38: // xterm 256 fg color ???
                    // now check if next arg is 5
@@ -474,16 +471,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                         if (!b) ERR("Failed xterm 256 color fg esc val");
                         else
                           {
-                             ty->state.att.fg256 = 1;
-                             ty->state.att.fg = arg;
+                             ty->termstate.att.fg256 = 1;
+                             ty->termstate.att.fg = arg;
                           }
                      }
-                   ty->state.att.fgintense = 0;
+                   ty->termstate.att.fgintense = 0;
                    break;
                 case 39: // default fg color
-                   ty->state.att.fg256 = 0;
-                   ty->state.att.fg = COL_DEF;
-                   ty->state.att.fgintense = 0;
+                   ty->termstate.att.fg256 = 0;
+                   ty->termstate.att.fg = COL_DEF;
+                   ty->termstate.att.fgintense = 0;
                    break;
                 case 40: // bg
                 case 41:
@@ -493,9 +490,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                 case 45:
                 case 46:
                 case 47:
-                   ty->state.att.bg256 = 0;
-                   ty->state.att.bg = (arg - 40) + COL_BLACK;
-                   ty->state.att.bgintense = 0;
+                   ty->termstate.att.bg256 = 0;
+                   ty->termstate.att.bg = (arg - 40) + COL_BLACK;
+                   ty->termstate.att.bgintense = 0;
                    break;
                 case 48: // xterm 256 bg color ???
                    // now check if next arg is 5
@@ -508,16 +505,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                         if (!b) ERR("Failed xterm 256 color bg esc val");
                         else
                           {
-                             ty->state.att.bg256 = 1;
-                             ty->state.att.bg = arg;
+                             ty->termstate.att.bg256 = 1;
+                             ty->termstate.att.bg = arg;
                           }
                      }
-                   ty->state.att.bgintense = 0;
+                   ty->termstate.att.bgintense = 0;
                    break;
                 case 49: // default bg color
-                   ty->state.att.bg256 = 0;
-                   ty->state.att.bg = COL_DEF;
-                   ty->state.att.bgintense = 0;
+                   ty->termstate.att.bg256 = 0;
+                   ty->termstate.att.bg = COL_DEF;
+                   ty->termstate.att.bgintense = 0;
                    break;
                 case 90: // fg
                 case 91:
@@ -527,9 +524,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                 case 95:
                 case 96:
                 case 97:
-                   ty->state.att.fg256 = 0;
-                   ty->state.att.fg = (arg - 90) + COL_BLACK;
-                   ty->state.att.fgintense = 1;
+                   ty->termstate.att.fg256 = 0;
+                   ty->termstate.att.fg = (arg - 90) + COL_BLACK;
+                   ty->termstate.att.fgintense = 1;
                    break;
                 case 98: // xterm 256 fg color ???
                    // now check if next arg is 5
@@ -542,16 +539,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                         if (!b) ERR("Failed xterm 256 color fg esc val");
                         else
                           {
-                             ty->state.att.fg256 = 1;
-                             ty->state.att.fg = arg;
+                             ty->termstate.att.fg256 = 1;
+                             ty->termstate.att.fg = arg;
                           }
                      }
-                   ty->state.att.fgintense = 1;
+                   ty->termstate.att.fgintense = 1;
                    break;
                 case 99: // default fg color
-                   ty->state.att.fg256 = 0;
-                   ty->state.att.fg = COL_DEF;
-                   ty->state.att.fgintense = 1;
+                   ty->termstate.att.fg256 = 0;
+                   ty->termstate.att.fg = COL_DEF;
+                   ty->termstate.att.fgintense = 1;
                    break;
                 case 100: // bg
                 case 101:
@@ -561,9 +558,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                 case 105:
                 case 106:
                 case 107:
-                   ty->state.att.bg256 = 0;
-                   ty->state.att.bg = (arg - 100) + COL_BLACK;
-                   ty->state.att.bgintense = 1;
+                   ty->termstate.att.bg256 = 0;
+                   ty->termstate.att.bg = (arg - 100) + COL_BLACK;
+                   ty->termstate.att.bgintense = 1;
                    break;
                 case 108: // xterm 256 bg color ???
                    // now check if next arg is 5
@@ -576,16 +573,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
                         if (!b) ERR("Failed xterm 256 color bg esc val");
                         else
                           {
-                             ty->state.att.bg256 = 1;
-                             ty->state.att.bg = arg;
+                             ty->termstate.att.bg256 = 1;
+                             ty->termstate.att.bg = arg;
                           }
                      }
-                   ty->state.att.bgintense = 1;
+                   ty->termstate.att.bgintense = 1;
                    break;
                 case 109: // default bg color
-                   ty->state.att.bg256 = 0;
-                   ty->state.att.bg = COL_DEF;
-                   ty->state.att.bgintense = 1;
+                   ty->termstate.att.bg256 = 0;
+                   ty->termstate.att.bg = COL_DEF;
+                   ty->termstate.att.bgintense = 1;
                    break;
                 default: //  not handled???
                    ERR("Unhandled color cmd [%i]", arg);
@@ -614,7 +611,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
           {
            case 6:
               len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
-                             ty->state.cy + 1, ty->state.cx + 1);
+                             ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
               termpty_write(ty, bf, len);
               break;
            default:
@@ -629,7 +626,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
           {
            case 6:
               len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
-                             ty->state.cy + 1, ty->state.cx + 1);
+                             ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
               termpty_write(ty, bf, len);
               break;
            default:
@@ -675,16 +672,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         if (arg < 1) arg = 1;
         DBG("insert %d blank chars", arg);
           {
-             int pi = ty->state.insert;
+             int pi = ty->termstate.insert;
              Eina_Unicode blank[1] = { ' ' };
-             int cx = ty->state.cx;
+             int cx = ty->cursor_state.cx;
 
-             ty->state.wrapnext = 0;
-             ty->state.insert = 1;
+             ty->termstate.wrapnext = 0;
+             ty->termstate.insert = 1;
              for (i = 0; i < arg; i++)
                _termpty_text_append(ty, blank, 1);
-             ty->state.insert = pi;
-             ty->state.cx = cx;
+             ty->termstate.insert = pi;
+             ty->cursor_state.cx = cx;
           }
         break;
       case 'A': // cursor up N
@@ -692,25 +689,25 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("cursor up %d", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cy = MAX(0, ty->state.cy - arg);
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
         break;
       case 'B': // cursor down N
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("cursor down %d", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cy = MIN(ty->h - 1, ty->state.cy + arg);
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
         break;
       case 'D': // cursor left N
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("cursor left %d", arg);
-        ty->state.wrapnext = 0;
+        ty->termstate.wrapnext = 0;
         for (i = 0; i < arg; i++)
           {
-             ty->state.cx--;
-             if (ty->state.cx < 0) ty->state.cx = 0;
+             ty->cursor_state.cx--;
+             if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
           }
         break;
       case 'C': // cursor right N
@@ -718,21 +715,21 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("cursor right %d", arg);
-        ty->state.wrapnext = 0;
+        ty->termstate.wrapnext = 0;
         for (i = 0; i < arg; i++)
           {
-             ty->state.cx++;
-             if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1;
+             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
         DBG("cursor pos set");
-        ty->state.wrapnext = 0;
+        ty->termstate.wrapnext = 0;
         if (!*b)
           {
-             ty->state.cx = 0;
-             ty->state.cy = 0;
+             ty->cursor_state.cx = 0;
+             ty->cursor_state.cy = 0;
           }
         else
           {
@@ -742,7 +739,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              if (arg >= ty->h) arg = ty->h - 1;
              if (b)
                {
-                  ty->state.cy = arg;
+                  ty->cursor_state.cy = arg;
                   arg = _csi_arg_get(&b);
                   if (arg < 1) arg = 1;
                   arg--;
@@ -750,47 +747,47 @@ _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->state.cx = arg;
+             if (b) ty->cursor_state.cx = arg;
           }
-        ty->state.cy += ty->state.margin_top;
+        ty->cursor_state.cy += ty->termstate.margin_top;
        break;
       case 'G': // to column N
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("to column %d", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cx = arg - 1;
-        if (ty->state.cx < 0) ty->state.cx = 0;
-        else if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cx = arg - 1;
+        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);
         if (arg < 1) arg = 1;
         DBG("to row %d", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cy = arg - 1;
-        if (ty->state.cy < 0) ty->state.cy = 0;
-        else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy = arg - 1;
+        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);
         if (arg < 1) arg = 1;
         DBG("down relative %d rows, and to col 0", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cy += arg;
-        if (ty->state.cy < 0) ty->state.cy = 0;
-        else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
-        ty->state.cx = 0;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy += arg;
+        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
         arg = _csi_arg_get(&b);
         if (arg < 1) arg = 1;
         DBG("up relative %d rows, and to col 0", arg);
-        ty->state.wrapnext = 0;
-        ty->state.cy -= arg;
-        if (ty->state.cy < 0) ty->state.cy = 0;
-        else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1;
-        ty->state.cx = 0;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy -= arg;
+        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
         arg = _csi_arg_get(&b);
@@ -818,26 +815,26 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
           {
              int sy1, sy2;
 
-             sy1 = ty->state.scroll_y1;
-             sy2 = ty->state.scroll_y2;
-             if (ty->state.scroll_y2 == 0)
+             sy1 = ty->termstate.scroll_y1;
+             sy2 = ty->termstate.scroll_y2;
+             if (ty->termstate.scroll_y2 == 0)
                {
-                  ty->state.scroll_y1 = ty->state.cy;
-                  ty->state.scroll_y2 = ty->h;
+                  ty->termstate.scroll_y1 = ty->cursor_state.cy;
+                  ty->termstate.scroll_y2 = ty->h;
                }
              else
                {
-                  ty->state.scroll_y1 = ty->state.cy;
-                  if (ty->state.scroll_y2 <= ty->state.scroll_y1)
-                    ty->state.scroll_y2 = ty->state.scroll_y1 + 1;
+                  ty->termstate.scroll_y1 = ty->cursor_state.cy;
+                  if (ty->termstate.scroll_y2 <= ty->termstate.scroll_y1)
+                    ty->termstate.scroll_y2 = ty->termstate.scroll_y1 + 1;
                }
              for (i = 0; i < arg; i++)
                {
                   if (*cc == 'M') _termpty_text_scroll(ty, EINA_TRUE);
                   else _termpty_text_scroll_rev(ty, EINA_TRUE);
                }
-             ty->state.scroll_y1 = sy1;
-             ty->state.scroll_y2 = sy2;
+             ty->termstate.scroll_y1 = sy1;
+             ty->termstate.scroll_y2 = sy2;
           }
         break;
       case 'P': // erase and scrollback N chars
@@ -848,9 +845,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              Termcell *cells;
              int x, lim;
 
-             cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy));
+             cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
              lim = ty->w - arg;
-             for (x = ty->state.cx; x < (ty->w); x++)
+             for (x = ty->cursor_state.cx; x < (ty->w); x++)
                {
                   if (x < lim)
                     termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1);
@@ -929,8 +926,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         if (!b)
           {
              WRN("no region args reset region");
-             ty->state.scroll_y1 = 0;
-             ty->state.scroll_y2 = 0;
+             ty->termstate.scroll_y1 = 0;
+             ty->termstate.scroll_y2 = 0;
           }
         else
           {
@@ -940,16 +937,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              if (!b)
                {
                   WRN("failed to give 2 regions args reset region");
-                  ty->state.scroll_y1 = 0;
-                  ty->state.scroll_y2 = 0;
+                  ty->termstate.scroll_y1 = 0;
+                  ty->termstate.scroll_y2 = 0;
                }
              else
                {
                   if (arg > arg2)
                     {
                        DBG("scroll region beginning > end [%i %i]", arg, arg2);
-                       ty->state.scroll_y1 = 0;
-                       ty->state.scroll_y2 = 0;
+                       ty->termstate.scroll_y1 = 0;
+                       ty->termstate.scroll_y2 = 0;
                     }
                   else
                     {
@@ -957,19 +954,19 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
                        if (arg >= ty->h) arg = ty->h - 1;
                        if (arg == 0) arg = 1;
                        if (arg2 > ty->h) arg2 = ty->h;
-                       ty->state.scroll_y1 = arg - 1;
-                       ty->state.scroll_y2 = arg2;
+                       ty->termstate.scroll_y1 = arg - 1;
+                       ty->termstate.scroll_y2 = arg2;
                        if ((arg == 1) && (arg2 == ty->h))
-                          ty->state.scroll_y2 = 0;
+                          ty->termstate.scroll_y2 = 0;
                     }
                }
           }
         break;
       case 's': // store cursor pos
-        _termpty_cursor_copy(&(ty->state), &(ty->save));
+        _termpty_cursor_copy(ty, EINA_TRUE);
         break;
       case 'u': // restore cursor pos
-        _termpty_cursor_copy(&(ty->save), &(ty->state));
+        _termpty_cursor_copy(ty, EINA_FALSE);
         break;
       case 'p': // define key assignments based on keycode
         if (b && *b == '!')
@@ -1007,7 +1004,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         break;
        case 'Z': // Cursor Back Tab
        {
-          int idx, size, cx = ty->state.cx, cy = ty->state.cy;
+          int idx, size, cx = ty->cursor_state.cx, cy = ty->cursor_state.cy;
 
           arg = _csi_arg_get(&b);
           if (arg < 1) arg = 1;
@@ -1026,8 +1023,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
             }
           if (!arg)
             {
-               ty->state.cx = cx;
-               ty->state.cy = cy;
+               ty->cursor_state.cx = cx;
+               ty->cursor_state.cy = cy;
             }
        }
        break;
@@ -1559,25 +1556,25 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         if (len == 0) return 0;
         return 1 + len;
       case '=': // set alternate keypad mode
-        ty->state.alt_kp = 1;
+        ty->termstate.alt_kp = 1;
         return 1;
       case '>': // set numeric keypad mode
-        ty->state.alt_kp = 0;
+        ty->termstate.alt_kp = 0;
         return 1;
       case 'M': // move to prev line
-        ty->state.wrapnext = 0;
-        ty->state.cy--;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy--;
         _termpty_text_scroll_rev_test(ty, EINA_TRUE);
         return 1;
       case 'D': // move to next line
-        ty->state.wrapnext = 0;
-        ty->state.cy++;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cy++;
         _termpty_text_scroll_test(ty, EINA_FALSE);
         return 1;
       case 'E': // add \n\r
-        ty->state.wrapnext = 0;
-        ty->state.cx = 0;
-        ty->state.cy++;
+        ty->termstate.wrapnext = 0;
+        ty->cursor_state.cx = 0;
+        ty->cursor_state.cy++;
         _termpty_text_scroll_test(ty, EINA_FALSE);
         return 1;
       case 'Z': // same a 'ESC [ Pn c'
@@ -1592,29 +1589,29 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         return 1;
       case '(': // charset 0
         if (len < 2) return 0;
-        ty->state.chset[0] = c[1];
-        ty->state.multibyte = 0;
-        ty->state.charsetch = c[1];
+        ty->termstate.chset[0] = c[1];
+        ty->termstate.multibyte = 0;
+        ty->termstate.charsetch = c[1];
         return 2;
       case ')': // charset 1
         if (len < 2) return 0;
-        ty->state.chset[1] = c[1];
-        ty->state.multibyte = 0;
+        ty->termstate.chset[1] = c[1];
+        ty->termstate.multibyte = 0;
         return 2;
       case '*': // charset 2
         if (len < 2) return 0;
-        ty->state.chset[2] = c[1];
-        ty->state.multibyte = 0;
+        ty->termstate.chset[2] = c[1];
+        ty->termstate.multibyte = 0;
         return 2;
       case '+': // charset 3
         if (len < 2) return 0;
-        ty->state.chset[3] = c[1];
-        ty->state.multibyte = 0;
+        ty->termstate.chset[3] = c[1];
+        ty->termstate.multibyte = 0;
         return 2;
       case '$': // charset -2
         if (len < 2) return 0;
-        ty->state.chset[2] = c[1];
-        ty->state.multibyte = 1;
+        ty->termstate.chset[2] = c[1];
+        ty->termstate.multibyte = 1;
         return 2;
       case '#': // #8 == test mode -> fill screen with "E";
         if (len < 2) return 0;
@@ -1625,8 +1622,6 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
 
              DBG("reset to init mode and clear then fill with E");
              _termpty_reset_state(ty);
-             ty->save = ty->state;
-             ty->swap = ty->state;
              _termpty_clear_screen(ty, TERMPTY_CLR_ALL);
              if (ty->cb.cancel_sel.func)
                ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
@@ -1635,7 +1630,7 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
              if (cells)
                {
                   Termatt att;
-                  
+
                   memset((&att), 0, sizeof(att));
                   termpty_cell_codepoint_att_fill(ty, 'E', att, cells, size);
                }
@@ -1645,10 +1640,10 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, 
Eina_Unicode *ce)
         if (len < 2) return 0;
         return 2;
       case '7': // save cursor pos
-        _termpty_cursor_copy(&(ty->state), &(ty->save));
+        _termpty_cursor_copy(ty, EINA_TRUE);
         return 1;
       case '8': // restore cursor pos
-        _termpty_cursor_copy(&(ty->save), &(ty->state));
+        _termpty_cursor_copy(ty, EINA_FALSE);
         return 1;
       case 'H': // set tab at current column
         DBG("Character Tabulation Set (HTS)");
@@ -1706,7 +1701,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
 /*
            case 0x05: // ENQ (enquiry)
              _term_txt_write(ty, "ABC\r\n");
-             ty->state.had_cr = 0;
+             ty->termstate.had_cr = 0;
              return 1;
  */
 /*
@@ -1724,14 +1719,14 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
              return 1;
 
            case 0x0e: // SO  (shift out) // Maps G1 character set into GL.
-             ty->state.had_cr = 0;
-             ty->state.charset = 1;
-             ty->state.charsetch = ty->state.chset[1];
+             ty->termstate.had_cr = 0;
+             ty->termstate.charset = 1;
+             ty->termstate.charsetch = ty->termstate.chset[1];
              return 1;
            case 0x0f: // SI  (shift in) // Maps G0 character set into GL.
-             ty->state.charset = 0;
-             ty->state.had_cr = 0;
-             ty->state.charsetch = ty->state.chset[0];
+             ty->termstate.charset = 0;
+             ty->termstate.had_cr = 0;
+             ty->termstate.charsetch = ty->termstate.chset[0];
              return 1;
 /*
            case 0x10: // DLE (data link escape)
@@ -1758,7 +1753,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
              return 1;
  */
            case 0x1b: // ESC (escape)
-             ty->state.had_cr = 0;
+             ty->termstate.had_cr = 0;
              len = _handle_esc(ty, c + 1, ce);
              if (len == 0) return 0;
              return 1 + len;
@@ -1773,20 +1768,20 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
              return 1;
  */
            default:
-             ty->state.had_cr = 0;
+             ty->termstate.had_cr = 0;
              //ERR("unhandled char 0x%02x", c[0]);
              return 1;
           }
      }
    else if (c[0] == 0x7f) // DEL
      {
-        ty->state.had_cr = 0;
+        ty->termstate.had_cr = 0;
         ERR("Unhandled char 0x%02x [DEL]", (unsigned int) c[0]);
         return 1;
      }
    else if (c[0] == 0x9b) // ANSI ESC!!!
      {
-        ty->state.had_cr = 0;
+        ty->termstate.had_cr = 0;
         DBG("ANSI CSI!!!!!");
         len = _handle_esc_csi(ty, c + 1, ce);
         if (len == 0) return 0;
@@ -1797,7 +1792,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
         Termexp *ex;
         Eina_List *l;
         
-        ty->state.had_cr = 0;
+        ty->termstate.had_cr = 0;
         EINA_LIST_FOREACH(ty->block.expecting, l, ex)
           {
              if (c[0] == ex->ch)
@@ -1831,7 +1826,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
      }
    else
      {
-        ty->state.had_cr = 0;
+        ty->termstate.had_cr = 0;
      }
    cc = (Eina_Unicode *)c;
    DBG("txt: [");
@@ -1843,6 +1838,6 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, 
Eina_Unicode *ce)
      }
    DBG("]");
    _termpty_text_append(ty, c, len);
-   ty->state.had_cr = 0;
+   ty->termstate.had_cr = 0;
    return len;
 }
diff --git a/src/bin/termptygfx.c b/src/bin/termptygfx.c
index 00ffabf..aababb8 100644
--- a/src/bin/termptygfx.c
+++ b/src/bin/termptygfx.c
@@ -34,9 +34,9 @@ static const unsigned short vt100_to_unicode[62] =
 };
 
 Eina_Unicode
-_termpty_charset_trans(Eina_Unicode g, Termstate *state)
+_termpty_charset_trans(Eina_Unicode g, Termpty *ty)
 {
-   switch (state->charsetch)
+   switch (ty->termstate.charsetch)
      {
       case '0': /* DEC Special Character & Line Drawing Set */
         if ((g >= 0x41) && (g <= 0x7e) &&
@@ -49,7 +49,7 @@ _termpty_charset_trans(Eina_Unicode g, Termstate *state)
       default:
         break;
      }
-   if (state->att.fraktur)
+   if (ty->termstate.att.fraktur)
      {
         if (g >= 'a' && g <= 'z')
           {
diff --git a/src/bin/termptygfx.h b/src/bin/termptygfx.h
index a7bbaad..b1dc027 100644
--- a/src/bin/termptygfx.h
+++ b/src/bin/termptygfx.h
@@ -3,6 +3,6 @@
 
 #include "termpty.h"
 
-Eina_Unicode _termpty_charset_trans(Eina_Unicode g, Termstate *state);
+Eina_Unicode _termpty_charset_trans(Eina_Unicode g, Termpty *ty);
 
 #endif
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 4d74570..d1641f1 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -27,7 +27,7 @@ _text_clear(Termpty *ty, Termcell *cells, int count, int val, 
Eina_Bool inherit_
 
    memset(&src, 0, sizeof(src));
    src.codepoint = val;
-   if (inherit_att) src.att = ty->state.att;
+   if (inherit_att) src.att = ty->termstate.att;
    termpty_cell_fill(ty, &src, cells, count);
 }
 
@@ -65,10 +65,10 @@ _termpty_text_scroll(Termpty *ty, Eina_Bool clear)
    Termcell *cells = NULL, *cells2;
    int y, start_y = 0, end_y = ty->h - 1;
 
-   if (ty->state.scroll_y2 != 0)
+   if (ty->termstate.scroll_y2 != 0)
      {
-        start_y = ty->state.scroll_y1;
-        end_y = ty->state.scroll_y2 - 1;
+        start_y = ty->termstate.scroll_y1;
+        end_y = ty->termstate.scroll_y2 - 1;
      }
    else
      if (!ty->altbuf)
@@ -108,10 +108,10 @@ _termpty_text_scroll_rev(Termpty *ty, Eina_Bool clear)
    Termcell *cells, *cells2 = NULL;
    int y, start_y = 0, end_y = ty->h - 1;
 
-   if (ty->state.scroll_y2 != 0)
+   if (ty->termstate.scroll_y2 != 0)
      {
-        start_y = ty->state.scroll_y1;
-        end_y = ty->state.scroll_y2 - 1;
+        start_y = ty->termstate.scroll_y1;
+        end_y = ty->termstate.scroll_y2 - 1;
      }
    DBG("... scroll rev!!!!! [%i->%i]", start_y, end_y);
    termio_scroll(ty->obj, 1, start_y, end_y);
@@ -146,11 +146,11 @@ _termpty_text_scroll_test(Termpty *ty, Eina_Bool clear)
 {
    int e = ty->h;
 
-   if (ty->state.scroll_y2 != 0) e = ty->state.scroll_y2;
-   if (ty->state.cy >= e)
+   if (ty->termstate.scroll_y2 != 0) e = ty->termstate.scroll_y2;
+   if (ty->cursor_state.cy >= e)
      {
         _termpty_text_scroll(ty, clear);
-        ty->state.cy = e - 1;
+        ty->cursor_state.cy = e - 1;
      }
 }
 
@@ -159,11 +159,11 @@ _termpty_text_scroll_rev_test(Termpty *ty, Eina_Bool 
clear)
 {
    int b = 0;
 
-   if (ty->state.scroll_y1 != 0) b = ty->state.scroll_y1;
-   if (ty->state.cy < b)
+   if (ty->termstate.scroll_y1 != 0) b = ty->termstate.scroll_y1;
+   if (ty->cursor_state.cy < b)
      {
         _termpty_text_scroll_rev(ty, clear);
-        ty->state.cy = b;
+        ty->cursor_state.cy = b;
      }
 }
 
@@ -173,66 +173,68 @@ _termpty_text_append(Termpty *ty, const Eina_Unicode 
*codepoints, int len)
    Termcell *cells;
    int i, j;
 
-   termio_content_change(ty->obj, ty->state.cx, ty->state.cy, len);
+   termio_content_change(ty->obj, ty->cursor_state.cx, ty->cursor_state.cy, 
len);
 
-   cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy));
+   cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
    for (i = 0; i < len; i++)
      {
         Eina_Unicode g;
 
-        if (ty->state.wrapnext)
+        if (ty->termstate.wrapnext)
           {
              cells[ty->w - 1].att.autowrapped = 1;
-             ty->state.wrapnext = 0;
-             ty->state.cx = 0;
-             ty->state.cy++;
+             ty->termstate.wrapnext = 0;
+             ty->cursor_state.cx = 0;
+             ty->cursor_state.cy++;
              _termpty_text_scroll_test(ty, EINA_TRUE);
-             cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy));
+             cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
           }
-        if (ty->state.insert)
+        if (ty->termstate.insert)
           {
-             for (j = ty->w - 1; j > ty->state.cx; j--)
+             for (j = ty->w - 1; j > ty->cursor_state.cx; j--)
                termpty_cell_copy(ty, &(cells[j - 1]), &(cells[j]), 1);
           }
 
-        g = _termpty_charset_trans(codepoints[i], &ty->state);
+        g = _termpty_charset_trans(codepoints[i], ty);
 
-        termpty_cell_codepoint_att_fill(ty, g, ty->state.att,
-                                        &(cells[ty->state.cx]), 1);
+        termpty_cell_codepoint_att_fill(ty, g, ty->termstate.att,
+                                        &(cells[ty->cursor_state.cx]), 1);
 #if defined(SUPPORT_DBLWIDTH)
-        cells[ty->state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g);
-        if (EINA_UNLIKELY((cells[ty->state.cx].att.dblwidth) && (ty->state.cx 
< (ty->w - 1))))
+        cells[ty->cursor_state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, 
g);
+        if (EINA_UNLIKELY((cells[ty->cursor_state.cx].att.dblwidth) && 
(ty->cursor_state.cx < (ty->w - 1))))
           {
-             TERMPTY_FMTCLR(cells[ty->state.cx].att);
-             termpty_cell_codepoint_att_fill(ty, 0, cells[ty->state.cx].att,
-                                             &(cells[ty->state.cx + 1]), 1);
+             TERMPTY_FMTCLR(cells[ty->cursor_state.cx].att);
+             termpty_cell_codepoint_att_fill(ty, 0, 
cells[ty->cursor_state.cx].att,
+                                             &(cells[ty->cursor_state.cx + 
1]), 1);
           }
-#endif        
-        if (ty->state.wrap)
+#endif
+        if (ty->termstate.wrap)
           {
              unsigned char offset = 1;
 
-             ty->state.wrapnext = 0;
+             ty->termstate.wrapnext = 0;
 #if defined(SUPPORT_DBLWIDTH)
-            if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth))
+             if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
                offset = 2;
 #endif
-             if (EINA_UNLIKELY(ty->state.cx >= (ty->w - offset))) 
ty->state.wrapnext = 1;
-             else ty->state.cx += offset;
+             if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset)))
+               ty->termstate.wrapnext = 1;
+             else
+               ty->cursor_state.cx += offset;
           }
         else
           {
              unsigned char offset = 1;
 
-             ty->state.wrapnext = 0;
+             ty->termstate.wrapnext = 0;
 #if defined(SUPPORT_DBLWIDTH)
-             if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth))
+             if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
                offset = 2;
 #endif
-             ty->state.cx += offset;
-             if (ty->state.cx > (ty->w - offset))
+             ty->cursor_state.cx += offset;
+             if (ty->cursor_state.cx > (ty->w - offset))
                {
-                  ty->state.cx = ty->w - offset;
+                  ty->cursor_state.cx = ty->w - offset;
                   return;
                }
           }
@@ -244,16 +246,16 @@ _termpty_clear_line(Termpty *ty, Termpty_Clear mode, int 
limit)
 {
    Termcell *cells;
    int n = 0;
-   Evas_Coord x = 0, y = ty->state.cy;
+   Evas_Coord x = 0, y = ty->cursor_state.cy;
 
    switch (mode)
      {
       case TERMPTY_CLR_END:
-        n = ty->w - ty->state.cx;
-        x = ty->state.cx;
+        n = ty->w - ty->cursor_state.cx;
+        x = ty->cursor_state.cx;
         break;
       case TERMPTY_CLR_BEGIN:
-        n = ty->state.cx + 1;
+        n = ty->cursor_state.cx + 1;
         break;
       case TERMPTY_CLR_ALL:
         n = ty->w;
@@ -276,33 +278,33 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode)
      {
       case TERMPTY_CLR_END:
         _termpty_clear_line(ty, mode, ty->w);
-        if (ty->state.cy < (ty->h - 1))
+        if (ty->cursor_state.cy < (ty->h - 1))
           {
-             int l = ty->h - (ty->state.cy + 1);
+             int l = ty->h - (ty->cursor_state.cy + 1);
 
-             termio_content_change(ty->obj, 0, ty->state.cy, l * ty->w);
+             termio_content_change(ty->obj, 0, ty->cursor_state.cy, l * ty->w);
 
              while (l)
                {
-                  cells = &(TERMPTY_SCREEN(ty, 0, (ty->state.cy + l)));
+                  cells = &(TERMPTY_SCREEN(ty, 0, (ty->cursor_state.cy + l)));
                   _text_clear(ty, cells, ty->w, 0, EINA_TRUE);
                   l--;
                }
           }
         break;
       case TERMPTY_CLR_BEGIN:
-        if (ty->state.cy > 0)
+        if (ty->cursor_state.cy > 0)
           {
              // First clear from circular > height, then from 0 to circular
-             int y = ty->state.cy + ty->circular_offset;
+             int y = ty->cursor_state.cy + ty->circular_offset;
 
-             termio_content_change(ty->obj, 0, 0, ty->state.cy * ty->w);
+             termio_content_change(ty->obj, 0, 0, ty->cursor_state.cy * ty->w);
 
              cells = &(TERMPTY_SCREEN(ty, 0, 0));
 
              if (y < ty->h)
                {
-                  _text_clear(ty, cells, ty->w * ty->state.cy, 0, EINA_TRUE);
+                  _text_clear(ty, cells, ty->w * ty->cursor_state.cy, 0, 
EINA_TRUE);
                }
              else
                {
@@ -318,7 +320,7 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode)
       case TERMPTY_CLR_ALL:
         ty->circular_offset = 0;
         _text_clear(ty, ty->screen, ty->w * ty->h, 0, EINA_TRUE);
-        ty->state.scroll_y2 = 0;
+        ty->termstate.scroll_y2 = 0;
         if (ty->cb.cancel_sel.func)
           ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
         break;
@@ -365,28 +367,32 @@ _termpty_reset_att(Termatt *att)
 void
 _termpty_reset_state(Termpty *ty)
 {
-   ty->state.cx = 0;
-   ty->state.cy = 0;
-   ty->state.scroll_y1 = 0;
-   ty->state.scroll_y2 = 0;
-   ty->state.had_cr_x = 0;
-   ty->state.had_cr_y = 0;
-   _termpty_reset_att(&(ty->state.att));
-   ty->state.charset = 0;
-   ty->state.charsetch = 'B';
-   ty->state.chset[0] = 'B';
-   ty->state.chset[1] = 'B';
-   ty->state.chset[2] = 'B';
-   ty->state.chset[3] = 'B';
-   ty->state.multibyte = 0;
-   ty->state.alt_kp = 0;
-   ty->state.insert = 0;
-   ty->state.appcursor = 0;
-   ty->state.wrap = 1;
-   ty->state.wrapnext = 0;
-   ty->state.hidecursor = 0;
-   ty->state.crlf = 0;
-   ty->state.had_cr = 0;
+   ty->cursor_state.cx = 0;
+   ty->cursor_state.cy = 0;
+   ty->termstate.scroll_y1 = 0;
+   ty->termstate.scroll_y2 = 0;
+   ty->termstate.had_cr_x = 0;
+   ty->termstate.had_cr_y = 0;
+   _termpty_reset_att(&(ty->termstate.att));
+   ty->termstate.charset = 0;
+   ty->termstate.charsetch = 'B';
+   ty->termstate.chset[0] = 'B';
+   ty->termstate.chset[1] = 'B';
+   ty->termstate.chset[2] = 'B';
+   ty->termstate.chset[3] = 'B';
+   ty->termstate.multibyte = 0;
+   ty->termstate.alt_kp = 0;
+   ty->termstate.insert = 0;
+   ty->termstate.appcursor = 0;
+   ty->termstate.wrap = 1;
+   ty->termstate.wrapnext = 0;
+   ty->termstate.crlf = 0;
+   ty->termstate.had_cr = 0;
+   ty->termstate.send_bs = 0;
+   ty->termstate.reverse = 0;
+   ty->termstate.no_autorepeat = 0;
+   ty->termstate.cjk_ambiguous_wide = 0;
+   ty->termstate.hide_cursor = 0;
    ty->mouse_mode = MOUSE_OFF;
    ty->mouse_ext = MOUSE_EXT_NONE;
    ty->bracketed_paste = 0;
@@ -410,9 +416,16 @@ _termpty_reset_state(Termpty *ty)
 }
 
 void
-_termpty_cursor_copy(Termstate *state, Termstate *dest)
+_termpty_cursor_copy(Termpty *ty, Eina_Bool save)
 {
-   dest->cx = state->cx;
-   dest->cy = state->cy;
-   dest->wrapnext = state->wrapnext;
+   if (save)
+     {
+        ty->cursor_save.cx = ty->cursor_state.cx;
+        ty->cursor_save.cy = ty->cursor_state.cy;
+     }
+   else
+     {
+        ty->cursor_state.cx = ty->cursor_save.cx;
+        ty->cursor_state.cy = ty->cursor_save.cy;
+     }
 }
diff --git a/src/bin/termptyops.h b/src/bin/termptyops.h
index 23ff810..890c61d 100644
--- a/src/bin/termptyops.h
+++ b/src/bin/termptyops.h
@@ -20,7 +20,7 @@ void _termpty_clear_screen(Termpty *ty, Termpty_Clear mode);
 void _termpty_clear_all(Termpty *ty);
 void _termpty_reset_att(Termatt *att);
 void _termpty_reset_state(Termpty *ty);
-void _termpty_cursor_copy(Termstate *state, Termstate *dest);
+void _termpty_cursor_copy(Termpty *ty, Eina_Bool save);
 
 #define _term_txt_write(ty, txt) termpty_write(ty, txt, sizeof(txt) - 1)
 

-- 


Reply via email to