summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-04-19 19:59:29 +0200
committerBoris Faure <billiob@gmail.com>2015-04-23 20:02:53 +0200
commitbe62d87f89e5e0ada3d8cbfe3dd091eeb9b45391 (patch)
tree5b56caddf7c7b372bff7759a04fad4ac458f36f5 /src
parentcaf4e9230261d05c006f58a62bce7bfa58e83b3f (diff)
separate "termstate" from cursor state and screens. Closes T725
Diffstat (limited to 'src')
-rw-r--r--src/bin/keyin.c14
-rw-r--r--src/bin/miniview.c2
-rw-r--r--src/bin/termio.c8
-rw-r--r--src/bin/termpty.c52
-rw-r--r--src/bin/termpty.h54
-rw-r--r--src/bin/termptydbl.c2
-rw-r--r--src/bin/termptyesc.c417
-rw-r--r--src/bin/termptygfx.c6
-rw-r--r--src/bin/termptygfx.h2
-rw-r--r--src/bin/termptyops.c173
-rw-r--r--src/bin/termptyops.h2
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
69 const struct _s *s = NULL; 69 const struct _s *s = NULL;
70 const Key_Values *kv; 70 const Key_Values *kv;
71 71
72 if (!ty->state.appcursor) kv = &map[i].default_mode; 72 if (!ty->termstate.appcursor) kv = &map[i].default_mode;
73 else kv = &map[i].cursor; 73 else kv = &map[i].cursor;
74 if (!alt && !ctrl && !shift) s = &kv->plain; 74 if (!alt && !ctrl && !shift) s = &kv->plain;
75 else if (alt && !ctrl && !shift) s = &kv->alt; 75 else if (alt && !ctrl && !shift) s = &kv->alt;
76 else if (!alt && ctrl && !shift) s = &kv->ctrl; 76 else if (!alt && ctrl && !shift) s = &kv->ctrl;
@@ -112,7 +112,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
112 { 112 {
113 if (alt) 113 if (alt)
114 termpty_write(ty, "\033", 1); 114 termpty_write(ty, "\033", 1);
115 if (ty->state.send_bs) 115 if (ty->termstate.send_bs)
116 { 116 {
117 termpty_write(ty, "\b", 1); 117 termpty_write(ty, "\b", 1);
118 } 118 }
@@ -135,7 +135,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
135 { 135 {
136 if (alt) 136 if (alt)
137 termpty_write(ty, "\033", 1); 137 termpty_write(ty, "\033", 1);
138 if (ty->state.crlf) 138 if (ty->termstate.crlf)
139 { 139 {
140 termpty_write(ty, "\r\n", sizeof("\r\n") - 1); 140 termpty_write(ty, "\r\n", sizeof("\r\n") - 1);
141 return; 141 return;
@@ -150,7 +150,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
150 { 150 {
151 if (!evas_key_lock_is_set(ev->locks, "Num_Lock")) 151 if (!evas_key_lock_is_set(ev->locks, "Num_Lock"))
152 { 152 {
153 if (ty->state.alt_kp) 153 if (ty->termstate.alt_kp)
154 { 154 {
155 if (_key_try(ty, tty_keys_kp_app, 155 if (_key_try(ty, tty_keys_kp_app,
156 sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]), 156 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,
242 } 242 }
243 243
244 // if term app asked for kbd lock - dont handle here 244 // if term app asked for kbd lock - dont handle here
245 if (ty->state.kbd_lock) return EINA_TRUE; 245 if (ty->termstate.kbd_lock) return EINA_TRUE;
246 // if app asked us to not do autorepeat - ignore press if is it is the same 246 // if app asked us to not do autorepeat - ignore press if is it is the same
247 // timestamp as last one 247 // timestamp as last one
248 if ((ty->state.no_autorepeat) && 248 if ((ty->termstate.no_autorepeat) &&
249 (ev->timestamp == khdl->last_keyup)) return EINA_TRUE; 249 (ev->timestamp == khdl->last_keyup)) return EINA_TRUE;
250 if (!khdl->composing) 250 if (!khdl->composing)
251 { 251 {
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
81_draw_cell(const Termpty *ty, unsigned int *pixel, const Termcell *cell, unsigned int *colors) 81_draw_cell(const Termpty *ty, unsigned int *pixel, const Termcell *cell, unsigned int *colors)
82{ 82{
83 int fg, bg, fgext, bgext; 83 int fg, bg, fgext, bgext;
84 int inv = ty->state.reverse; 84 int inv = ty->termstate.reverse;
85 Eina_Unicode codepoint; 85 Eina_Unicode codepoint;
86 86
87 codepoint = cell->codepoint; 87 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)
4512 blk->was_active = blk->active; 4512 blk->was_active = blk->active;
4513 blk->active = EINA_FALSE; 4513 blk->active = EINA_FALSE;
4514 } 4514 }
4515 inv = sd->pty->state.reverse; 4515 inv = sd->pty->termstate.reverse;
4516 termpty_cellcomp_freeze(sd->pty); 4516 termpty_cellcomp_freeze(sd->pty);
4517 for (y = 0; y < sd->grid.h; y++) 4517 for (y = 0; y < sd->grid.h; y++)
4518 { 4518 {
@@ -4753,12 +4753,12 @@ _smart_apply(Evas_Object *obj)
4753 (sd->pty->block.active, l); 4753 (sd->pty->block.active, l);
4754 } 4754 }
4755 } 4755 }
4756 if ((sd->scroll != 0) || (sd->pty->state.hidecursor)) 4756 if ((sd->scroll != 0) || (sd->pty->termstate.hide_cursor))
4757 evas_object_hide(sd->cursor.obj); 4757 evas_object_hide(sd->cursor.obj);
4758 else 4758 else
4759 evas_object_show(sd->cursor.obj); 4759 evas_object_show(sd->cursor.obj);
4760 sd->cursor.x = sd->pty->state.cx; 4760 sd->cursor.x = sd->pty->cursor_state.cx;
4761 sd->cursor.y = sd->pty->state.cy; 4761 sd->cursor.y = sd->pty->cursor_state.cy;
4762 evas_object_move(sd->cursor.obj, 4762 evas_object_move(sd->cursor.obj,
4763 ox + ((sd->cursor.x + preedit_x) * sd->font.chw), 4763 ox + ((sd->cursor.x + preedit_x) * sd->font.chw),
4764 oy + ((sd->cursor.y + preedit_y) * sd->font.chh)); 4764 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)
268} 268}
269 269
270static void 270static void
271_limit_coord(Termpty *ty, Termstate *state) 271_limit_coord(Termpty *ty)
272{ 272{
273 state->wrapnext = 0; 273 ty->termstate.wrapnext = 0;
274 if (state->cx >= ty->w) state->cx = ty->w - 1; 274 if (ty->termstate.had_cr_x >= ty->w)
275 if (state->cy >= ty->h) state->cy = ty->h - 1; 275 ty->termstate.had_cr_x = ty->w - 1;
276 if (state->had_cr_x >= ty->w) state->had_cr_x = ty->w - 1; 276 if (ty->termstate.had_cr_y >= ty->h)
277 if (state->had_cr_y >= ty->h) state->had_cr_y = ty->h - 1; 277 ty->termstate.had_cr_y = ty->h - 1;
278
279 if (ty->cursor_state.cx >= ty->w)
280 ty->cursor_state.cx = ty->w - 1;
281 if (ty->cursor_state.cy >= ty->h)
282 ty->cursor_state.cy = ty->h - 1;
283
284 if (ty->cursor_save.cx >= ty->w)
285 ty->cursor_save.cx = ty->w - 1;
286 if (ty->cursor_save.cy >= ty->h)
287 ty->cursor_save.cy = ty->h - 1;
278} 288}
279 289
280Termpty * 290Termpty *
@@ -298,8 +308,6 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
298 ty->backmax = backscroll; 308 ty->backmax = backscroll;
299 309
300 _termpty_reset_state(ty); 310 _termpty_reset_state(ty);
301 ty->save = ty->state;
302 ty->swap = ty->state;
303 311
304 ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h); 312 ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
305 if (!ty->screen) 313 if (!ty->screen)
@@ -799,7 +807,7 @@ termpty_line_rewrap(Termpty *ty, int y_start, int y_end,
799 new_back[new_y + ty->backmax] = new_ts; 807 new_back[new_y + ty->backmax] = new_ts;
800 } 808 }
801 } 809 }
802 if (y == ty->state.cy) 810 if (y == ty->cursor_state.cy)
803 { 811 {
804 *new_cyp = new_y_start; 812 *new_cyp = new_y_start;
805 } 813 }
@@ -831,7 +839,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
831 Termcell *new_screen = NULL; 839 Termcell *new_screen = NULL;
832 Termsave **new_back = NULL; 840 Termsave **new_back = NULL;
833 int y_start = 0, y_end = 0, new_y_start = 0, new_y_end, 841 int y_start = 0, y_end = 0, new_y_start = 0, new_y_end,
834 new_cy = ty->state.cy; 842 new_cy = ty->cursor_state.cy;
835 int i, altbuf = 0; 843 int i, altbuf = 0;
836 844
837 if ((ty->w == new_w) && (ty->h == new_h)) return; 845 if ((ty->w == new_w) && (ty->h == new_h)) return;
@@ -855,7 +863,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
855 goto bad; 863 goto bad;
856 new_back = calloc(sizeof(Termsave *), ty->backmax); 864 new_back = calloc(sizeof(Termsave *), ty->backmax);
857 865
858 y_end = ty->state.cy; 866 y_end = ty->cursor_state.cy;
859 new_y_end = new_h - 1; 867 new_y_end = new_h - 1;
860 /* For each "full line" in old buffers, rewrap. 868 /* For each "full line" in old buffers, rewrap.
861 * From most recent to oldest */ 869 * From most recent to oldest */
@@ -885,15 +893,13 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
885 ty->circular_offset = MAX(new_y_start, 0); 893 ty->circular_offset = MAX(new_y_start, 0);
886 ty->backpos = 0; 894 ty->backpos = 0;
887 ty->backscroll_num = MAX(-new_y_start, 0); 895 ty->backscroll_num = MAX(-new_y_start, 0);
888 ty->state.had_cr = 0; 896 ty->termstate.had_cr = 0;
889 897
890 ty->state.cy = (new_cy + new_h - ty->circular_offset) % new_h; 898 ty->cursor_state.cy = (new_cy + new_h - ty->circular_offset) % new_h;
891 899
892 if (altbuf) termpty_screen_swap(ty); 900 if (altbuf) termpty_screen_swap(ty);
893 901
894 _limit_coord(ty, &(ty->state)); 902 _limit_coord(ty);
895 _limit_coord(ty, &(ty->swap));
896 _limit_coord(ty, &(ty->save));
897 903
898 _pty_size(ty); 904 _pty_size(ty);
899 905
@@ -1100,25 +1106,11 @@ termpty_screen_swap(Termpty *ty)
1100{ 1106{
1101 Termcell *tmp_screen; 1107 Termcell *tmp_screen;
1102 int tmp_circular_offset; 1108 int tmp_circular_offset;
1103 Termstate tmp;
1104 1109
1105 tmp_screen = ty->screen; 1110 tmp_screen = ty->screen;
1106 ty->screen = ty->screen2; 1111 ty->screen = ty->screen2;
1107 ty->screen2 = tmp_screen; 1112 ty->screen2 = tmp_screen;
1108 1113
1109 if (ty->altbuf)
1110 {
1111 tmp = ty->state;
1112 ty->state = ty->swap;
1113 ty->swap = tmp;
1114 }
1115 else
1116 {
1117 tmp = ty->swap;
1118 ty->swap = ty->state;
1119 ty->state = tmp;
1120 }
1121
1122 tmp_circular_offset = ty->circular_offset; 1114 tmp_circular_offset = ty->circular_offset;
1123 ty->circular_offset = ty->circular_offset2; 1115 ty->circular_offset = ty->circular_offset2;
1124 ty->circular_offset2 = tmp_circular_offset; 1116 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 @@
6typedef struct _Termpty Termpty; 6typedef struct _Termpty Termpty;
7typedef struct _Termcell Termcell; 7typedef struct _Termcell Termcell;
8typedef struct _Termatt Termatt; 8typedef struct _Termatt Termatt;
9typedef struct _Termstate Termstate;
10typedef struct _Termsave Termsave; 9typedef struct _Termsave Termsave;
11typedef struct _Termsavecomp Termsavecomp; 10typedef struct _Termsavecomp Termsavecomp;
12typedef struct _Termblock Termblock; 11typedef struct _Termblock Termblock;
@@ -84,32 +83,6 @@ struct _Termatt
84#endif 83#endif
85}; 84};
86 85
87struct _Termstate
88{
89 int cx, cy;
90 Termatt att;
91 unsigned char charset;
92 unsigned char charsetch;
93 unsigned char chset[4];
94 int scroll_y1, scroll_y2;
95 int had_cr_x, had_cr_y;
96 int margin_top; // soon, more to come...
97 unsigned int multibyte : 1;
98 unsigned int alt_kp : 1;
99 unsigned int insert : 1;
100 unsigned int appcursor : 1;
101 unsigned int wrap : 1;
102 unsigned int wrapnext : 1;
103 unsigned int hidecursor : 1;
104 unsigned int crlf : 1;
105 unsigned int had_cr : 1;
106 unsigned int send_bs : 1;
107 unsigned int kbd_lock : 1;
108 unsigned int reverse : 1;
109 unsigned int no_autorepeat : 1;
110 unsigned int cjk_ambiguous_wide : 1;
111};
112
113struct _Termpty 86struct _Termpty
114{ 87{
115 Evas_Object *obj; 88 Evas_Object *obj;
@@ -158,7 +131,32 @@ struct _Termpty
158 unsigned char by_line : 1; 131 unsigned char by_line : 1;
159 unsigned char is_top_to_bottom : 1; 132 unsigned char is_top_to_bottom : 1;
160 } selection; 133 } selection;
161 Termstate state, save, swap; 134 struct {
135 Termatt att;
136 unsigned char charset;
137 unsigned char charsetch;
138 unsigned char chset[4];
139 int scroll_y1, scroll_y2;
140 int had_cr_x, had_cr_y;
141 int margin_top; // soon, more to come...
142 unsigned int multibyte : 1;
143 unsigned int alt_kp : 1;
144 unsigned int insert : 1;
145 unsigned int appcursor : 1;
146 unsigned int wrap : 1;
147 unsigned int wrapnext : 1;
148 unsigned int crlf : 1;
149 unsigned int had_cr : 1;
150 unsigned int send_bs : 1;
151 unsigned int kbd_lock : 1;
152 unsigned int reverse : 1;
153 unsigned int no_autorepeat : 1;
154 unsigned int cjk_ambiguous_wide : 1;
155 unsigned int hide_cursor : 1;
156 } termstate;
157 struct {
158 int cx, cy;
159 } cursor_state, cursor_save;
162 int exit_code; 160 int exit_code;
163 pid_t pid; 161 pid_t pid;
164 unsigned int altbuf : 1; 162 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)
41 return EINA_TRUE; 41 return EINA_TRUE;
42 // FIXME: can optimize by breaking into tree and ranges 42 // FIXME: can optimize by breaking into tree and ranges
43 // (A) 43 // (A)
44 if (ty->state.cjk_ambiguous_wide) 44 if (ty->termstate.cjk_ambiguous_wide)
45 { 45 {
46 // grep ';A #' EastAsianWidth.txt | wc -l 46 // grep ';A #' EastAsianWidth.txt | wc -l
47 // :( 47 // :(
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)
58 switch (*cc) 58 switch (*cc)
59 { 59 {
60 case 0x07: // BEL '\a' (bell) 60 case 0x07: // BEL '\a' (bell)
61 ty->state.had_cr = 0; 61 ty->termstate.had_cr = 0;
62 if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data); 62 if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
63 return; 63 return;
64 case 0x08: // BS '\b' (backspace) 64 case 0x08: // BS '\b' (backspace)
65 DBG("->BS"); 65 DBG("->BS");
66 ty->state.had_cr = 0; 66 ty->termstate.had_cr = 0;
67 ty->state.wrapnext = 0; 67 ty->termstate.wrapnext = 0;
68 ty->state.cx--; 68 ty->cursor_state.cx--;
69 if (ty->state.cx < 0) ty->state.cx = 0; 69 if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
70 return; 70 return;
71 case 0x09: // HT '\t' (horizontal tab) 71 case 0x09: // HT '\t' (horizontal tab)
72 DBG("->HT"); 72 DBG("->HT");
73 ty->state.had_cr = 0; 73 ty->termstate.had_cr = 0;
74 TERMPTY_SCREEN(ty, ty->state.cx, ty->state.cy).att.tab = 1; 74 TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy).att.tab = 1;
75 ty->state.wrapnext = 0; 75 ty->termstate.wrapnext = 0;
76 ty->state.cx += 8; 76 ty->cursor_state.cx += 8;
77 ty->state.cx = (ty->state.cx / 8) * 8; 77 ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
78 if (ty->state.cx >= ty->w) 78 if (ty->cursor_state.cx >= ty->w)
79 ty->state.cx = ty->w - 1; 79 ty->cursor_state.cx = ty->w - 1;
80 return; 80 return;
81 case 0x0a: // LF '\n' (new line) 81 case 0x0a: // LF '\n' (new line)
82 case 0x0b: // VT '\v' (vertical tab) 82 case 0x0b: // VT '\v' (vertical tab)
83 case 0x0c: // FF '\f' (form feed) 83 case 0x0c: // FF '\f' (form feed)
84 DBG("->LF"); 84 DBG("->LF");
85 if (ty->state.had_cr) 85 if (ty->termstate.had_cr)
86 { 86 {
87 TERMPTY_SCREEN(ty, ty->state.had_cr_x, 87 TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
88 ty->state.had_cr_y).att.newline = 1; 88 ty->termstate.had_cr_y).att.newline = 1;
89 } 89 }
90 ty->state.had_cr = 0; 90 ty->termstate.had_cr = 0;
91 ty->state.wrapnext = 0; 91 ty->termstate.wrapnext = 0;
92 if (ty->state.crlf) ty->state.cx = 0; 92 if (ty->termstate.crlf) ty->cursor_state.cx = 0;
93 ty->state.cy++; 93 ty->cursor_state.cy++;
94 _termpty_text_scroll_test(ty, EINA_TRUE); 94 _termpty_text_scroll_test(ty, EINA_TRUE);
95 return; 95 return;
96 case 0x0d: // CR '\r' (carriage ret) 96 case 0x0d: // CR '\r' (carriage ret)
97 DBG("->CR"); 97 DBG("->CR");
98 if (ty->state.cx != 0) 98 if (ty->cursor_state.cx != 0)
99 { 99 {
100 ty->state.had_cr_x = ty->state.cx; 100 ty->termstate.had_cr_x = ty->cursor_state.cx;
101 ty->state.had_cr_y = ty->state.cy; 101 ty->termstate.had_cr_y = ty->cursor_state.cy;
102 ty->state.wrapnext = 0; 102 ty->termstate.wrapnext = 0;
103 } 103 }
104 ty->state.cx = 0; 104 ty->cursor_state.cx = 0;
105// ty->state.had_cr = 1; 105// ty->termstate.had_cr = 1;
106 return; 106 return;
107 default: 107 default:
108 return; 108 return;
@@ -149,14 +149,14 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
149 switch (arg) 149 switch (arg)
150 { 150 {
151 case 1: 151 case 1:
152 ty->state.appcursor = mode; 152 ty->termstate.appcursor = mode;
153 break; 153 break;
154 case 2: 154 case 2:
155 ty->state.kbd_lock = mode; 155 ty->termstate.kbd_lock = mode;
156 break; 156 break;
157 case 3: // 132 column mode… should we handle this? 157 case 3: // 132 column mode… should we handle this?
158#if defined(SUPPORT_80_132_COLUMNS) 158#if defined(SUPPORT_80_132_COLUMNS)
159 if (ty->state.att.is_80_132_mode_allowed) 159 if (ty->termstate.att.is_80_132_mode_allowed)
160 { 160 {
161 /* ONLY FOR TESTING PURPOSE FTM */ 161 /* ONLY FOR TESTING PURPOSE FTM */
162 Evas_Object *wn; 162 Evas_Object *wn;
@@ -180,18 +180,18 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
180 WRN("TODO: scrolling mode (DECSCLM): %i", mode); 180 WRN("TODO: scrolling mode (DECSCLM): %i", mode);
181 break; 181 break;
182 case 5: 182 case 5:
183 ty->state.reverse = mode; 183 ty->termstate.reverse = mode;
184 break; 184 break;
185 case 6: 185 case 6:
186 if (mode) 186 if (mode)
187 { 187 {
188 ty->state.margin_top = ty->state.cy; 188 ty->termstate.margin_top = ty->cursor_state.cy;
189 ty->state.cx = 0; 189 ty->cursor_state.cx = 0;
190 } 190 }
191 else 191 else
192 { 192 {
193 ty->state.cx = 0; 193 ty->cursor_state.cx = 0;
194 ty->state.margin_top = 0; 194 ty->termstate.margin_top = 0;
195 } 195 }
196 DBG("origin mode (%d): cursor is at 0,0" 196 DBG("origin mode (%d): cursor is at 0,0"
197 " cursor limited to screen/start point" 197 " cursor limited to screen/start point"
@@ -200,10 +200,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
200 break; 200 break;
201 case 7: 201 case 7:
202 DBG("set wrap mode to %i", mode); 202 DBG("set wrap mode to %i", mode);
203 ty->state.wrap = mode; 203 ty->termstate.wrap = mode;
204 break; 204 break;
205 case 8: 205 case 8:
206 ty->state.no_autorepeat = !mode; 206 ty->termstate.no_autorepeat = !mode;
207 DBG("auto repeat %i", mode); 207 DBG("auto repeat %i", mode);
208 break; 208 break;
209 case 9: 209 case 9:
@@ -218,10 +218,10 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
218 WRN("TODO: set print extent to full screen"); 218 WRN("TODO: set print extent to full screen");
219 break; 219 break;
220 case 20: // crfl==1 -> cur moves to col 0 on LF, FF or VT, ==0 -> mode is cr+lf 220 case 20: // crfl==1 -> cur moves to col 0 on LF, FF or VT, ==0 -> mode is cr+lf
221 ty->state.crlf = mode; 221 ty->termstate.crlf = mode;
222 break; 222 break;
223 case 25: 223 case 25:
224 ty->state.hidecursor = !mode; 224 ty->termstate.hide_cursor = !mode;
225 DBG("hide cursor: %d", !mode); 225 DBG("hide cursor: %d", !mode);
226 break; 226 break;
227 case 30: // ignore 227 case 30: // ignore
@@ -242,7 +242,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
242 case 40: 242 case 40:
243 DBG("Allow 80 -> 132 Mode %i", mode); 243 DBG("Allow 80 -> 132 Mode %i", mode);
244#if defined(SUPPORT_80_132_COLUMNS) 244#if defined(SUPPORT_80_132_COLUMNS)
245 ty->state.att.is_80_132_mode_allowed = mode; 245 ty->termstate.att.is_80_132_mode_allowed = mode;
246#endif 246#endif
247 break; 247 break;
248 case 45: // ignore 248 case 45: // ignore
@@ -255,7 +255,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
255 WRN("TODO: app keypad mode %i", mode); 255 WRN("TODO: app keypad mode %i", mode);
256 break; 256 break;
257 case 67: 257 case 67:
258 ty->state.send_bs = mode; 258 ty->termstate.send_bs = mode;
259 DBG("backspace send bs not del = %i", mode); 259 DBG("backspace send bs not del = %i", mode);
260 break; 260 break;
261 case 1000: 261 case 1000:
@@ -312,10 +312,7 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
312 break; 312 break;
313 case 1048: 313 case 1048:
314 case 1049: 314 case 1049:
315 if (mode) 315 _termpty_cursor_copy(ty, mode);
316 _termpty_cursor_copy(&(ty->state), &(ty->save));
317 else
318 _termpty_cursor_copy(&(ty->save), &(ty->state));
319 if (arg == 1049) 316 if (arg == 1049)
320 _switch_to_alternative_screen(ty, mode); 317 _switch_to_alternative_screen(ty, mode);
321 break; 318 break;
@@ -345,11 +342,11 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
345 switch (arg) 342 switch (arg)
346 { 343 {
347 case 1: 344 case 1:
348 ty->state.appcursor = mode; 345 ty->termstate.appcursor = mode;
349 break; 346 break;
350 case 4: 347 case 4:
351 DBG("set insert mode to %i", mode); 348 DBG("set insert mode to %i", mode);
352 ty->state.insert = mode; 349 ty->termstate.insert = mode;
353 break; 350 break;
354 case 34: 351 case 34:
355 WRN("TODO: hebrew keyboard mapping: %i", mode); 352 WRN("TODO: hebrew keyboard mapping: %i", mode);
@@ -381,75 +378,75 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
381 { 378 {
382 int arg = _csi_arg_get(&b); 379 int arg = _csi_arg_get(&b);
383 if ((first) && (!b)) 380 if ((first) && (!b))
384 _termpty_reset_att(&(ty->state.att)); 381 _termpty_reset_att(&(ty->termstate.att));
385 else if (b) 382 else if (b)
386 { 383 {
387 first = 0; 384 first = 0;
388 switch (arg) 385 switch (arg)
389 { 386 {
390 case 0: // reset to normal 387 case 0: // reset to normal
391 _termpty_reset_att(&(ty->state.att)); 388 _termpty_reset_att(&(ty->termstate.att));
392 break; 389 break;
393 case 1: // bold/bright 390 case 1: // bold/bright
394 ty->state.att.bold = 1; 391 ty->termstate.att.bold = 1;
395 break; 392 break;
396 case 2: // faint 393 case 2: // faint
397 ty->state.att.faint = 1; 394 ty->termstate.att.faint = 1;
398 break; 395 break;
399 case 3: // italic 396 case 3: // italic
400#if defined(SUPPORT_ITALIC) 397#if defined(SUPPORT_ITALIC)
401 ty->state.att.italic = 1; 398 ty->termstate.att.italic = 1;
402#endif 399#endif
403 break; 400 break;
404 case 4: // underline 401 case 4: // underline
405 ty->state.att.underline = 1; 402 ty->termstate.att.underline = 1;
406 break; 403 break;
407 case 5: // blink 404 case 5: // blink
408 ty->state.att.blink = 1; 405 ty->termstate.att.blink = 1;
409 break; 406 break;
410 case 6: // blink rapid 407 case 6: // blink rapid
411 ty->state.att.blink2 = 1; 408 ty->termstate.att.blink2 = 1;
412 break; 409 break;
413 case 7: // reverse 410 case 7: // reverse
414 ty->state.att.inverse = 1; 411 ty->termstate.att.inverse = 1;
415 break; 412 break;
416 case 8: // invisible 413 case 8: // invisible
417 ty->state.att.invisible = 1; 414 ty->termstate.att.invisible = 1;
418 break; 415 break;
419 case 9: // strikethrough 416 case 9: // strikethrough
420 ty->state.att.strike = 1; 417 ty->termstate.att.strike = 1;
421 break; 418 break;
422 case 20: // fraktur! 419 case 20: // fraktur!
423 ty->state.att.fraktur = 1; 420 ty->termstate.att.fraktur = 1;
424 break; 421 break;
425 case 21: // no bold/bright 422 case 21: // no bold/bright
426 ty->state.att.bold = 0; 423 ty->termstate.att.bold = 0;
427 break; 424 break;
428 case 22: // no bold/bright, no faint 425 case 22: // no bold/bright, no faint
429 ty->state.att.bold = 0; 426 ty->termstate.att.bold = 0;
430 ty->state.att.faint = 0; 427 ty->termstate.att.faint = 0;
431 break; 428 break;
432 case 23: // no italic, not fraktur 429 case 23: // no italic, not fraktur
433#if defined(SUPPORT_ITALIC) 430#if defined(SUPPORT_ITALIC)
434 ty->state.att.italic = 0; 431 ty->termstate.att.italic = 0;
435#endif 432#endif
436 ty->state.att.fraktur = 0; 433 ty->termstate.att.fraktur = 0;
437 break; 434 break;
438 case 24: // no underline 435 case 24: // no underline
439 ty->state.att.underline = 0; 436 ty->termstate.att.underline = 0;
440 break; 437 break;
441 case 25: // no blink 438 case 25: // no blink
442 ty->state.att.blink = 0; 439 ty->termstate.att.blink = 0;
443 ty->state.att.blink2 = 0; 440 ty->termstate.att.blink2 = 0;
444 break; 441 break;
445 case 27: // no reverse 442 case 27: // no reverse
446 ty->state.att.inverse = 0; 443 ty->termstate.att.inverse = 0;
447 break; 444 break;
448 case 28: // no invisible 445 case 28: // no invisible
449 ty->state.att.invisible = 0; 446 ty->termstate.att.invisible = 0;
450 break; 447 break;
451 case 29: // no strikethrough 448 case 29: // no strikethrough
452 ty->state.att.strike = 0; 449 ty->termstate.att.strike = 0;
453 break; 450 break;
454 case 30: // fg 451 case 30: // fg
455 case 31: 452 case 31:
@@ -459,9 +456,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
459 case 35: 456 case 35:
460 case 36: 457 case 36:
461 case 37: 458 case 37:
462 ty->state.att.fg256 = 0; 459 ty->termstate.att.fg256 = 0;
463 ty->state.att.fg = (arg - 30) + COL_BLACK; 460 ty->termstate.att.fg = (arg - 30) + COL_BLACK;
464 ty->state.att.fgintense = 0; 461 ty->termstate.att.fgintense = 0;
465 break; 462 break;
466 case 38: // xterm 256 fg color ??? 463 case 38: // xterm 256 fg color ???
467 // now check if next arg is 5 464 // now check if next arg is 5
@@ -474,16 +471,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
474 if (!b) ERR("Failed xterm 256 color fg esc val"); 471 if (!b) ERR("Failed xterm 256 color fg esc val");
475 else 472 else
476 { 473 {
477 ty->state.att.fg256 = 1; 474 ty->termstate.att.fg256 = 1;
478 ty->state.att.fg = arg; 475 ty->termstate.att.fg = arg;
479 } 476 }
480 } 477 }
481 ty->state.att.fgintense = 0; 478 ty->termstate.att.fgintense = 0;
482 break; 479 break;
483 case 39: // default fg color 480 case 39: // default fg color
484 ty->state.att.fg256 = 0; 481 ty->termstate.att.fg256 = 0;
485 ty->state.att.fg = COL_DEF; 482 ty->termstate.att.fg = COL_DEF;
486 ty->state.att.fgintense = 0; 483 ty->termstate.att.fgintense = 0;
487 break; 484 break;
488 case 40: // bg 485 case 40: // bg
489 case 41: 486 case 41:
@@ -493,9 +490,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
493 case 45: 490 case 45:
494 case 46: 491 case 46:
495 case 47: 492 case 47:
496 ty->state.att.bg256 = 0; 493 ty->termstate.att.bg256 = 0;
497 ty->state.att.bg = (arg - 40) + COL_BLACK; 494 ty->termstate.att.bg = (arg - 40) + COL_BLACK;
498 ty->state.att.bgintense = 0; 495 ty->termstate.att.bgintense = 0;
499 break; 496 break;
500 case 48: // xterm 256 bg color ??? 497 case 48: // xterm 256 bg color ???
501 // now check if next arg is 5 498 // now check if next arg is 5
@@ -508,16 +505,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
508 if (!b) ERR("Failed xterm 256 color bg esc val"); 505 if (!b) ERR("Failed xterm 256 color bg esc val");
509 else 506 else
510 { 507 {
511 ty->state.att.bg256 = 1; 508 ty->termstate.att.bg256 = 1;
512 ty->state.att.bg = arg; 509 ty->termstate.att.bg = arg;
513 } 510 }
514 } 511 }
515 ty->state.att.bgintense = 0; 512 ty->termstate.att.bgintense = 0;
516 break; 513 break;
517 case 49: // default bg color 514 case 49: // default bg color
518 ty->state.att.bg256 = 0; 515 ty->termstate.att.bg256 = 0;
519 ty->state.att.bg = COL_DEF; 516 ty->termstate.att.bg = COL_DEF;
520 ty->state.att.bgintense = 0; 517 ty->termstate.att.bgintense = 0;
521 break; 518 break;
522 case 90: // fg 519 case 90: // fg
523 case 91: 520 case 91:
@@ -527,9 +524,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
527 case 95: 524 case 95:
528 case 96: 525 case 96:
529 case 97: 526 case 97:
530 ty->state.att.fg256 = 0; 527 ty->termstate.att.fg256 = 0;
531 ty->state.att.fg = (arg - 90) + COL_BLACK; 528 ty->termstate.att.fg = (arg - 90) + COL_BLACK;
532 ty->state.att.fgintense = 1; 529 ty->termstate.att.fgintense = 1;
533 break; 530 break;
534 case 98: // xterm 256 fg color ??? 531 case 98: // xterm 256 fg color ???
535 // now check if next arg is 5 532 // now check if next arg is 5
@@ -542,16 +539,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
542 if (!b) ERR("Failed xterm 256 color fg esc val"); 539 if (!b) ERR("Failed xterm 256 color fg esc val");
543 else 540 else
544 { 541 {
545 ty->state.att.fg256 = 1; 542 ty->termstate.att.fg256 = 1;
546 ty->state.att.fg = arg; 543 ty->termstate.att.fg = arg;
547 } 544 }
548 } 545 }
549 ty->state.att.fgintense = 1; 546 ty->termstate.att.fgintense = 1;
550 break; 547 break;
551 case 99: // default fg color 548 case 99: // default fg color
552 ty->state.att.fg256 = 0; 549 ty->termstate.att.fg256 = 0;
553 ty->state.att.fg = COL_DEF; 550 ty->termstate.att.fg = COL_DEF;
554 ty->state.att.fgintense = 1; 551 ty->termstate.att.fgintense = 1;
555 break; 552 break;
556 case 100: // bg 553 case 100: // bg
557 case 101: 554 case 101:
@@ -561,9 +558,9 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
561 case 105: 558 case 105:
562 case 106: 559 case 106:
563 case 107: 560 case 107:
564 ty->state.att.bg256 = 0; 561 ty->termstate.att.bg256 = 0;
565 ty->state.att.bg = (arg - 100) + COL_BLACK; 562 ty->termstate.att.bg = (arg - 100) + COL_BLACK;
566 ty->state.att.bgintense = 1; 563 ty->termstate.att.bgintense = 1;
567 break; 564 break;
568 case 108: // xterm 256 bg color ??? 565 case 108: // xterm 256 bg color ???
569 // now check if next arg is 5 566 // now check if next arg is 5
@@ -576,16 +573,16 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
576 if (!b) ERR("Failed xterm 256 color bg esc val"); 573 if (!b) ERR("Failed xterm 256 color bg esc val");
577 else 574 else
578 { 575 {
579 ty->state.att.bg256 = 1; 576 ty->termstate.att.bg256 = 1;
580 ty->state.att.bg = arg; 577 ty->termstate.att.bg = arg;
581 } 578 }
582 } 579 }
583 ty->state.att.bgintense = 1; 580 ty->termstate.att.bgintense = 1;
584 break; 581 break;
585 case 109: // default bg color 582 case 109: // default bg color
586 ty->state.att.bg256 = 0; 583 ty->termstate.att.bg256 = 0;
587 ty->state.att.bg = COL_DEF; 584 ty->termstate.att.bg = COL_DEF;
588 ty->state.att.bgintense = 1; 585 ty->termstate.att.bgintense = 1;
589 break; 586 break;
590 default: // not handled??? 587 default: // not handled???
591 ERR("Unhandled color cmd [%i]", arg); 588 ERR("Unhandled color cmd [%i]", arg);
@@ -614,7 +611,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
614 { 611 {
615 case 6: 612 case 6:
616 len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R", 613 len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
617 ty->state.cy + 1, ty->state.cx + 1); 614 ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
618 termpty_write(ty, bf, len); 615 termpty_write(ty, bf, len);
619 break; 616 break;
620 default: 617 default:
@@ -629,7 +626,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
629 { 626 {
630 case 6: 627 case 6:
631 len = snprintf(bf, sizeof(bf), "\033[%d;%dR", 628 len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
632 ty->state.cy + 1, ty->state.cx + 1); 629 ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
633 termpty_write(ty, bf, len); 630 termpty_write(ty, bf, len);
634 break; 631 break;
635 default: 632 default:
@@ -675,16 +672,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
675 if (arg < 1) arg = 1; 672 if (arg < 1) arg = 1;
676 DBG("insert %d blank chars", arg); 673 DBG("insert %d blank chars", arg);
677 { 674 {
678 int pi = ty->state.insert; 675 int pi = ty->termstate.insert;
679 Eina_Unicode blank[1] = { ' ' }; 676 Eina_Unicode blank[1] = { ' ' };
680 int cx = ty->state.cx; 677 int cx = ty->cursor_state.cx;
681 678
682 ty->state.wrapnext = 0; 679 ty->termstate.wrapnext = 0;
683 ty->state.insert = 1; 680 ty->termstate.insert = 1;
684 for (i = 0; i < arg; i++) 681 for (i = 0; i < arg; i++)
685 _termpty_text_append(ty, blank, 1); 682 _termpty_text_append(ty, blank, 1);
686 ty->state.insert = pi; 683 ty->termstate.insert = pi;
687 ty->state.cx = cx; 684 ty->cursor_state.cx = cx;
688 } 685 }
689 break; 686 break;
690 case 'A': // cursor up N 687 case 'A': // cursor up N
@@ -692,25 +689,25 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
692 arg = _csi_arg_get(&b); 689 arg = _csi_arg_get(&b);
693 if (arg < 1) arg = 1; 690 if (arg < 1) arg = 1;
694 DBG("cursor up %d", arg); 691 DBG("cursor up %d", arg);
695 ty->state.wrapnext = 0; 692 ty->termstate.wrapnext = 0;
696 ty->state.cy = MAX(0, ty->state.cy - arg); 693 ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
697 break; 694 break;
698 case 'B': // cursor down N 695 case 'B': // cursor down N
699 arg = _csi_arg_get(&b); 696 arg = _csi_arg_get(&b);
700 if (arg < 1) arg = 1; 697 if (arg < 1) arg = 1;
701 DBG("cursor down %d", arg); 698 DBG("cursor down %d", arg);
702 ty->state.wrapnext = 0; 699 ty->termstate.wrapnext = 0;
703 ty->state.cy = MIN(ty->h - 1, ty->state.cy + arg); 700 ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
704 break; 701 break;
705 case 'D': // cursor left N 702 case 'D': // cursor left N
706 arg = _csi_arg_get(&b); 703 arg = _csi_arg_get(&b);
707 if (arg < 1) arg = 1; 704 if (arg < 1) arg = 1;
708 DBG("cursor left %d", arg); 705 DBG("cursor left %d", arg);
709 ty->state.wrapnext = 0; 706 ty->termstate.wrapnext = 0;
710 for (i = 0; i < arg; i++) 707 for (i = 0; i < arg; i++)
711 { 708 {
712 ty->state.cx--; 709 ty->cursor_state.cx--;
713 if (ty->state.cx < 0) ty->state.cx = 0; 710 if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
714 } 711 }
715 break; 712 break;
716 case 'C': // cursor right N 713 case 'C': // cursor right N
@@ -718,21 +715,21 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
718 arg = _csi_arg_get(&b); 715 arg = _csi_arg_get(&b);
719 if (arg < 1) arg = 1; 716 if (arg < 1) arg = 1;
720 DBG("cursor right %d", arg); 717 DBG("cursor right %d", arg);
721 ty->state.wrapnext = 0; 718 ty->termstate.wrapnext = 0;
722 for (i = 0; i < arg; i++) 719 for (i = 0; i < arg; i++)
723 { 720 {
724 ty->state.cx++; 721 ty->cursor_state.cx++;
725 if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1; 722 if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
726 } 723 }
727 break; 724 break;
728 case 'H': // cursor pos set 725 case 'H': // cursor pos set
729 case 'f': // cursor pos set 726 case 'f': // cursor pos set
730 DBG("cursor pos set"); 727 DBG("cursor pos set");
731 ty->state.wrapnext = 0; 728 ty->termstate.wrapnext = 0;
732 if (!*b) 729 if (!*b)
733 { 730 {
734 ty->state.cx = 0; 731 ty->cursor_state.cx = 0;
735 ty->state.cy = 0; 732 ty->cursor_state.cy = 0;
736 } 733 }
737 else 734 else
738 { 735 {
@@ -742,7 +739,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
742 if (arg >= ty->h) arg = ty->h - 1; 739 if (arg >= ty->h) arg = ty->h - 1;
743 if (b) 740 if (b)
744 { 741 {
745 ty->state.cy = arg; 742 ty->cursor_state.cy = arg;
746 arg = _csi_arg_get(&b); 743 arg = _csi_arg_get(&b);
747 if (arg < 1) arg = 1; 744 if (arg < 1) arg = 1;
748 arg--; 745 arg--;
@@ -750,47 +747,47 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
750 else arg = 0; 747 else arg = 0;
751 748
752 if (arg >= ty->w) arg = ty->w - 1; 749 if (arg >= ty->w) arg = ty->w - 1;
753 if (b) ty->state.cx = arg; 750 if (b) ty->cursor_state.cx = arg;
754 } 751 }
755 ty->state.cy += ty->state.margin_top; 752 ty->cursor_state.cy += ty->termstate.margin_top;
756 break; 753 break;
757 case 'G': // to column N 754 case 'G': // to column N
758 arg = _csi_arg_get(&b); 755 arg = _csi_arg_get(&b);
759 if (arg < 1) arg = 1; 756 if (arg < 1) arg = 1;
760 DBG("to column %d", arg); 757 DBG("to column %d", arg);
761 ty->state.wrapnext = 0; 758 ty->termstate.wrapnext = 0;
762 ty->state.cx = arg - 1; 759 ty->cursor_state.cx = arg - 1;
763 if (ty->state.cx < 0) ty->state.cx = 0; 760 if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
764 else if (ty->state.cx >= ty->w) ty->state.cx = ty->w - 1; 761 else if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
765 break; 762 break;
766 case 'd': // to row N 763 case 'd': // to row N
767 arg = _csi_arg_get(&b); 764 arg = _csi_arg_get(&b);
768 if (arg < 1) arg = 1; 765 if (arg < 1) arg = 1;
769 DBG("to row %d", arg); 766 DBG("to row %d", arg);
770 ty->state.wrapnext = 0; 767 ty->termstate.wrapnext = 0;
771 ty->state.cy = arg - 1; 768 ty->cursor_state.cy = arg - 1;
772 if (ty->state.cy < 0) ty->state.cy = 0; 769 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
773 else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1; 770 else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
774 break; 771 break;
775 case 'E': // down relative N rows, and to col 0 772 case 'E': // down relative N rows, and to col 0
776 arg = _csi_arg_get(&b); 773 arg = _csi_arg_get(&b);
777 if (arg < 1) arg = 1; 774 if (arg < 1) arg = 1;
778 DBG("down relative %d rows, and to col 0", arg); 775 DBG("down relative %d rows, and to col 0", arg);
779 ty->state.wrapnext = 0; 776 ty->termstate.wrapnext = 0;
780 ty->state.cy += arg; 777 ty->cursor_state.cy += arg;
781 if (ty->state.cy < 0) ty->state.cy = 0; 778 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
782 else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1; 779 else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
783 ty->state.cx = 0; 780 ty->cursor_state.cx = 0;
784 break; 781 break;
785 case 'F': // up relative N rows, and to col 0 782 case 'F': // up relative N rows, and to col 0
786 arg = _csi_arg_get(&b); 783 arg = _csi_arg_get(&b);
787 if (arg < 1) arg = 1; 784 if (arg < 1) arg = 1;
788 DBG("up relative %d rows, and to col 0", arg); 785 DBG("up relative %d rows, and to col 0", arg);
789 ty->state.wrapnext = 0; 786 ty->termstate.wrapnext = 0;
790 ty->state.cy -= arg; 787 ty->cursor_state.cy -= arg;
791 if (ty->state.cy < 0) ty->state.cy = 0; 788 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
792 else if (ty->state.cy >= ty->h) ty->state.cy = ty->h - 1; 789 else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
793 ty->state.cx = 0; 790 ty->cursor_state.cx = 0;
794 break; 791 break;
795 case 'X': // erase N chars 792 case 'X': // erase N chars
796 arg = _csi_arg_get(&b); 793 arg = _csi_arg_get(&b);
@@ -818,26 +815,26 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
818 { 815 {
819 int sy1, sy2; 816 int sy1, sy2;
820 817
821 sy1 = ty->state.scroll_y1; 818 sy1 = ty->termstate.scroll_y1;
822 sy2 = ty->state.scroll_y2; 819 sy2 = ty->termstate.scroll_y2;
823 if (ty->state.scroll_y2 == 0) 820 if (ty->termstate.scroll_y2 == 0)
824 { 821 {
825 ty->state.scroll_y1 = ty->state.cy; 822 ty->termstate.scroll_y1 = ty->cursor_state.cy;
826 ty->state.scroll_y2 = ty->h; 823 ty->termstate.scroll_y2 = ty->h;
827 } 824 }
828 else 825 else
829 { 826 {
830 ty->state.scroll_y1 = ty->state.cy; 827 ty->termstate.scroll_y1 = ty->cursor_state.cy;
831 if (ty->state.scroll_y2 <= ty->state.scroll_y1) 828 if (ty->termstate.scroll_y2 <= ty->termstate.scroll_y1)
832 ty->state.scroll_y2 = ty->state.scroll_y1 + 1; 829 ty->termstate.scroll_y2 = ty->termstate.scroll_y1 + 1;
833 } 830 }
834 for (i = 0; i < arg; i++) 831 for (i = 0; i < arg; i++)
835 { 832 {
836 if (*cc == 'M') _termpty_text_scroll(ty, EINA_TRUE); 833 if (*cc == 'M') _termpty_text_scroll(ty, EINA_TRUE);
837 else _termpty_text_scroll_rev(ty, EINA_TRUE); 834 else _termpty_text_scroll_rev(ty, EINA_TRUE);
838 } 835 }
839 ty->state.scroll_y1 = sy1; 836 ty->termstate.scroll_y1 = sy1;
840 ty->state.scroll_y2 = sy2; 837 ty->termstate.scroll_y2 = sy2;
841 } 838 }
842 break; 839 break;
843 case 'P': // erase and scrollback N chars 840 case 'P': // erase and scrollback N chars
@@ -848,9 +845,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
848 Termcell *cells; 845 Termcell *cells;
849 int x, lim; 846 int x, lim;
850 847
851 cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy)); 848 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
852 lim = ty->w - arg; 849 lim = ty->w - arg;
853 for (x = ty->state.cx; x < (ty->w); x++) 850 for (x = ty->cursor_state.cx; x < (ty->w); x++)
854 { 851 {
855 if (x < lim) 852 if (x < lim)
856 termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1); 853 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)
929 if (!b) 926 if (!b)
930 { 927 {
931 WRN("no region args reset region"); 928 WRN("no region args reset region");
932 ty->state.scroll_y1 = 0; 929 ty->termstate.scroll_y1 = 0;
933 ty->state.scroll_y2 = 0; 930 ty->termstate.scroll_y2 = 0;
934 } 931 }
935 else 932 else
936 { 933 {
@@ -940,16 +937,16 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
940 if (!b) 937 if (!b)
941 { 938 {
942 WRN("failed to give 2 regions args reset region"); 939 WRN("failed to give 2 regions args reset region");
943 ty->state.scroll_y1 = 0; 940 ty->termstate.scroll_y1 = 0;
944 ty->state.scroll_y2 = 0; 941 ty->termstate.scroll_y2 = 0;
945 } 942 }
946 else 943 else
947 { 944 {
948 if (arg > arg2) 945 if (arg > arg2)
949 { 946 {
950 DBG("scroll region beginning > end [%i %i]", arg, arg2); 947 DBG("scroll region beginning > end [%i %i]", arg, arg2);
951 ty->state.scroll_y1 = 0; 948 ty->termstate.scroll_y1 = 0;
952 ty->state.scroll_y2 = 0; 949 ty->termstate.scroll_y2 = 0;
953 } 950 }
954 else 951 else
955 { 952 {
@@ -957,19 +954,19 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
957 if (arg >= ty->h) arg = ty->h - 1; 954 if (arg >= ty->h) arg = ty->h - 1;
958 if (arg == 0) arg = 1; 955 if (arg == 0) arg = 1;
959 if (arg2 > ty->h) arg2 = ty->h; 956 if (arg2 > ty->h) arg2 = ty->h;
960 ty->state.scroll_y1 = arg - 1; 957 ty->termstate.scroll_y1 = arg - 1;
961 ty->state.scroll_y2 = arg2; 958 ty->termstate.scroll_y2 = arg2;
962 if ((arg == 1) && (arg2 == ty->h)) 959 if ((arg == 1) && (arg2 == ty->h))
963 ty->state.scroll_y2 = 0; 960 ty->termstate.scroll_y2 = 0;
964 } 961 }
965 } 962 }
966 } 963 }
967 break; 964 break;
968 case 's': // store cursor pos 965 case 's': // store cursor pos
969 _termpty_cursor_copy(&(ty->state), &(ty->save)); 966 _termpty_cursor_copy(ty, EINA_TRUE);
970 break; 967 break;
971 case 'u': // restore cursor pos 968 case 'u': // restore cursor pos
972 _termpty_cursor_copy(&(ty->save), &(ty->state)); 969 _termpty_cursor_copy(ty, EINA_FALSE);
973 break; 970 break;
974 case 'p': // define key assignments based on keycode 971 case 'p': // define key assignments based on keycode
975 if (b && *b == '!') 972 if (b && *b == '!')
@@ -1007,7 +1004,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1007 break; 1004 break;
1008 case 'Z': // Cursor Back Tab 1005 case 'Z': // Cursor Back Tab
1009 { 1006 {
1010 int idx, size, cx = ty->state.cx, cy = ty->state.cy; 1007 int idx, size, cx = ty->cursor_state.cx, cy = ty->cursor_state.cy;
1011 1008
1012 arg = _csi_arg_get(&b); 1009 arg = _csi_arg_get(&b);
1013 if (arg < 1) arg = 1; 1010 if (arg < 1) arg = 1;
@@ -1026,8 +1023,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1026 } 1023 }
1027 if (!arg) 1024 if (!arg)
1028 { 1025 {
1029 ty->state.cx = cx; 1026 ty->cursor_state.cx = cx;
1030 ty->state.cy = cy; 1027 ty->cursor_state.cy = cy;
1031 } 1028 }
1032 } 1029 }
1033 break; 1030 break;
@@ -1559,25 +1556,25 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1559 if (len == 0) return 0; 1556 if (len == 0) return 0;
1560 return 1 + len; 1557 return 1 + len;
1561 case '=': // set alternate keypad mode 1558 case '=': // set alternate keypad mode
1562 ty->state.alt_kp = 1; 1559 ty->termstate.alt_kp = 1;
1563 return 1; 1560 return 1;
1564 case '>': // set numeric keypad mode 1561 case '>': // set numeric keypad mode
1565 ty->state.alt_kp = 0; 1562 ty->termstate.alt_kp = 0;
1566 return 1; 1563 return 1;
1567 case 'M': // move to prev line 1564 case 'M': // move to prev line
1568 ty->state.wrapnext = 0; 1565 ty->termstate.wrapnext = 0;
1569 ty->state.cy--; 1566 ty->cursor_state.cy--;
1570 _termpty_text_scroll_rev_test(ty, EINA_TRUE); 1567 _termpty_text_scroll_rev_test(ty, EINA_TRUE);
1571 return 1; 1568 return 1;
1572 case 'D': // move to next line 1569 case 'D': // move to next line
1573 ty->state.wrapnext = 0; 1570 ty->termstate.wrapnext = 0;
1574 ty->state.cy++; 1571 ty->cursor_state.cy++;
1575 _termpty_text_scroll_test(ty, EINA_FALSE); 1572 _termpty_text_scroll_test(ty, EINA_FALSE);
1576 return 1; 1573 return 1;
1577 case 'E': // add \n\r 1574 case 'E': // add \n\r
1578 ty->state.wrapnext = 0; 1575 ty->termstate.wrapnext = 0;
1579 ty->state.cx = 0; 1576 ty->cursor_state.cx = 0;
1580 ty->state.cy++; 1577 ty->cursor_state.cy++;
1581 _termpty_text_scroll_test(ty, EINA_FALSE); 1578 _termpty_text_scroll_test(ty, EINA_FALSE);
1582 return 1; 1579 return 1;
1583 case 'Z': // same a 'ESC [ Pn c' 1580 case 'Z': // same a 'ESC [ Pn c'
@@ -1592,29 +1589,29 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1592 return 1; 1589 return 1;
1593 case '(': // charset 0 1590 case '(': // charset 0
1594 if (len < 2) return 0; 1591 if (len < 2) return 0;
1595 ty->state.chset[0] = c[1]; 1592 ty->termstate.chset[0] = c[1];
1596 ty->state.multibyte = 0; 1593 ty->termstate.multibyte = 0;
1597 ty->state.charsetch = c[1]; 1594 ty->termstate.charsetch = c[1];
1598 return 2; 1595 return 2;
1599 case ')': // charset 1 1596 case ')': // charset 1
1600 if (len < 2) return 0; 1597 if (len < 2) return 0;
1601 ty->state.chset[1] = c[1]; 1598 ty->termstate.chset[1] = c[1];
1602 ty->state.multibyte = 0; 1599 ty->termstate.multibyte = 0;
1603 return 2; 1600 return 2;
1604 case '*': // charset 2 1601 case '*': // charset 2
1605 if (len < 2) return 0; 1602 if (len < 2) return 0;
1606 ty->state.chset[2] = c[1]; 1603 ty->termstate.chset[2] = c[1];
1607 ty->state.multibyte = 0; 1604 ty->termstate.multibyte = 0;
1608 return 2; 1605 return 2;
1609 case '+': // charset 3 1606 case '+': // charset 3
1610 if (len < 2) return 0; 1607 if (len < 2) return 0;
1611 ty->state.chset[3] = c[1]; 1608 ty->termstate.chset[3] = c[1];
1612 ty->state.multibyte = 0; 1609 ty->termstate.multibyte = 0;
1613 return 2; 1610 return 2;
1614 case '$': // charset -2 1611 case '$': // charset -2
1615 if (len < 2) return 0; 1612 if (len < 2) return 0;
1616 ty->state.chset[2] = c[1]; 1613 ty->termstate.chset[2] = c[1];
1617 ty->state.multibyte = 1; 1614 ty->termstate.multibyte = 1;
1618 return 2; 1615 return 2;
1619 case '#': // #8 == test mode -> fill screen with "E"; 1616 case '#': // #8 == test mode -> fill screen with "E";
1620 if (len < 2) return 0; 1617 if (len < 2) return 0;
@@ -1625,8 +1622,6 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1625 1622
1626 DBG("reset to init mode and clear then fill with E"); 1623 DBG("reset to init mode and clear then fill with E");
1627 _termpty_reset_state(ty); 1624 _termpty_reset_state(ty);
1628 ty->save = ty->state;
1629 ty->swap = ty->state;
1630 _termpty_clear_screen(ty, TERMPTY_CLR_ALL); 1625 _termpty_clear_screen(ty, TERMPTY_CLR_ALL);
1631 if (ty->cb.cancel_sel.func) 1626 if (ty->cb.cancel_sel.func)
1632 ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); 1627 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)
1635 if (cells) 1630 if (cells)
1636 { 1631 {
1637 Termatt att; 1632 Termatt att;
1638 1633
1639 memset((&att), 0, sizeof(att)); 1634 memset((&att), 0, sizeof(att));
1640 termpty_cell_codepoint_att_fill(ty, 'E', att, cells, size); 1635 termpty_cell_codepoint_att_fill(ty, 'E', att, cells, size);
1641 } 1636 }
@@ -1645,10 +1640,10 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1645 if (len < 2) return 0; 1640 if (len < 2) return 0;
1646 return 2; 1641 return 2;
1647 case '7': // save cursor pos 1642 case '7': // save cursor pos
1648 _termpty_cursor_copy(&(ty->state), &(ty->save)); 1643 _termpty_cursor_copy(ty, EINA_TRUE);
1649 return 1; 1644 return 1;
1650 case '8': // restore cursor pos 1645 case '8': // restore cursor pos
1651 _termpty_cursor_copy(&(ty->save), &(ty->state)); 1646 _termpty_cursor_copy(ty, EINA_FALSE);
1652 return 1; 1647 return 1;
1653 case 'H': // set tab at current column 1648 case 'H': // set tab at current column
1654 DBG("Character Tabulation Set (HTS)"); 1649 DBG("Character Tabulation Set (HTS)");
@@ -1706,7 +1701,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1706/* 1701/*
1707 case 0x05: // ENQ (enquiry) 1702 case 0x05: // ENQ (enquiry)
1708 _term_txt_write(ty, "ABC\r\n"); 1703 _term_txt_write(ty, "ABC\r\n");
1709 ty->state.had_cr = 0; 1704 ty->termstate.had_cr = 0;
1710 return 1; 1705 return 1;
1711 */ 1706 */
1712/* 1707/*
@@ -1724,14 +1719,14 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1724 return 1; 1719 return 1;
1725 1720
1726 case 0x0e: // SO (shift out) // Maps G1 character set into GL. 1721 case 0x0e: // SO (shift out) // Maps G1 character set into GL.
1727 ty->state.had_cr = 0; 1722 ty->termstate.had_cr = 0;
1728 ty->state.charset = 1; 1723 ty->termstate.charset = 1;
1729 ty->state.charsetch = ty->state.chset[1]; 1724 ty->termstate.charsetch = ty->termstate.chset[1];
1730 return 1; 1725 return 1;
1731 case 0x0f: // SI (shift in) // Maps G0 character set into GL. 1726 case 0x0f: // SI (shift in) // Maps G0 character set into GL.
1732 ty->state.charset = 0; 1727 ty->termstate.charset = 0;
1733 ty->state.had_cr = 0; 1728 ty->termstate.had_cr = 0;
1734 ty->state.charsetch = ty->state.chset[0]; 1729 ty->termstate.charsetch = ty->termstate.chset[0];
1735 return 1; 1730 return 1;
1736/* 1731/*
1737 case 0x10: // DLE (data link escape) 1732 case 0x10: // DLE (data link escape)
@@ -1758,7 +1753,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1758 return 1; 1753 return 1;
1759 */ 1754 */
1760 case 0x1b: // ESC (escape) 1755 case 0x1b: // ESC (escape)
1761 ty->state.had_cr = 0; 1756 ty->termstate.had_cr = 0;
1762 len = _handle_esc(ty, c + 1, ce); 1757 len = _handle_esc(ty, c + 1, ce);
1763 if (len == 0) return 0; 1758 if (len == 0) return 0;
1764 return 1 + len; 1759 return 1 + len;
@@ -1773,20 +1768,20 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1773 return 1; 1768 return 1;
1774 */ 1769 */
1775 default: 1770 default:
1776 ty->state.had_cr = 0; 1771 ty->termstate.had_cr = 0;
1777 //ERR("unhandled char 0x%02x", c[0]); 1772 //ERR("unhandled char 0x%02x", c[0]);
1778 return 1; 1773 return 1;
1779 } 1774 }
1780 } 1775 }
1781 else if (c[0] == 0x7f) // DEL 1776 else if (c[0] == 0x7f) // DEL
1782 { 1777 {
1783 ty->state.had_cr = 0; 1778 ty->termstate.had_cr = 0;
1784 ERR("Unhandled char 0x%02x [DEL]", (unsigned int) c[0]); 1779 ERR("Unhandled char 0x%02x [DEL]", (unsigned int) c[0]);
1785 return 1; 1780 return 1;
1786 } 1781 }
1787 else if (c[0] == 0x9b) // ANSI ESC!!! 1782 else if (c[0] == 0x9b) // ANSI ESC!!!
1788 { 1783 {
1789 ty->state.had_cr = 0; 1784 ty->termstate.had_cr = 0;
1790 DBG("ANSI CSI!!!!!"); 1785 DBG("ANSI CSI!!!!!");
1791 len = _handle_esc_csi(ty, c + 1, ce); 1786 len = _handle_esc_csi(ty, c + 1, ce);
1792 if (len == 0) return 0; 1787 if (len == 0) return 0;
@@ -1797,7 +1792,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1797 Termexp *ex; 1792 Termexp *ex;
1798 Eina_List *l; 1793 Eina_List *l;
1799 1794
1800 ty->state.had_cr = 0; 1795 ty->termstate.had_cr = 0;
1801 EINA_LIST_FOREACH(ty->block.expecting, l, ex) 1796 EINA_LIST_FOREACH(ty->block.expecting, l, ex)
1802 { 1797 {
1803 if (c[0] == ex->ch) 1798 if (c[0] == ex->ch)
@@ -1831,7 +1826,7 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1831 } 1826 }
1832 else 1827 else
1833 { 1828 {
1834 ty->state.had_cr = 0; 1829 ty->termstate.had_cr = 0;
1835 } 1830 }
1836 cc = (Eina_Unicode *)c; 1831 cc = (Eina_Unicode *)c;
1837 DBG("txt: ["); 1832 DBG("txt: [");
@@ -1843,6 +1838,6 @@ termpty_handle_seq(Termpty *ty, Eina_Unicode *c, Eina_Unicode *ce)
1843 } 1838 }
1844 DBG("]"); 1839 DBG("]");
1845 _termpty_text_append(ty, c, len); 1840 _termpty_text_append(ty, c, len);
1846 ty->state.had_cr = 0; 1841 ty->termstate.had_cr = 0;
1847 return len; 1842 return len;
1848} 1843}
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] =
34}; 34};
35 35
36Eina_Unicode 36Eina_Unicode
37_termpty_charset_trans(Eina_Unicode g, Termstate *state) 37_termpty_charset_trans(Eina_Unicode g, Termpty *ty)
38{ 38{
39 switch (state->charsetch) 39 switch (ty->termstate.charsetch)
40 { 40 {
41 case '0': /* DEC Special Character & Line Drawing Set */ 41 case '0': /* DEC Special Character & Line Drawing Set */
42 if ((g >= 0x41) && (g <= 0x7e) && 42 if ((g >= 0x41) && (g <= 0x7e) &&
@@ -49,7 +49,7 @@ _termpty_charset_trans(Eina_Unicode g, Termstate *state)
49 default: 49 default:
50 break; 50 break;
51 } 51 }
52 if (state->att.fraktur) 52 if (ty->termstate.att.fraktur)
53 { 53 {
54 if (g >= 'a' && g <= 'z') 54 if (g >= 'a' && g <= 'z')
55 { 55 {
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 @@
3 3
4#include "termpty.h" 4#include "termpty.h"
5 5
6Eina_Unicode _termpty_charset_trans(Eina_Unicode g, Termstate *state); 6Eina_Unicode _termpty_charset_trans(Eina_Unicode g, Termpty *ty);
7 7
8#endif 8#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_
27 27
28 memset(&src, 0, sizeof(src)); 28 memset(&src, 0, sizeof(src));
29 src.codepoint = val; 29 src.codepoint = val;
30 if (inherit_att) src.att = ty->state.att; 30 if (inherit_att) src.att = ty->termstate.att;
31 termpty_cell_fill(ty, &src, cells, count); 31 termpty_cell_fill(ty, &src, cells, count);
32} 32}
33 33
@@ -65,10 +65,10 @@ _termpty_text_scroll(Termpty *ty, Eina_Bool clear)
65 Termcell *cells = NULL, *cells2; 65 Termcell *cells = NULL, *cells2;
66 int y, start_y = 0, end_y = ty->h - 1; 66 int y, start_y = 0, end_y = ty->h - 1;
67 67
68 if (ty->state.scroll_y2 != 0) 68 if (ty->termstate.scroll_y2 != 0)
69 { 69 {
70 start_y = ty->state.scroll_y1; 70 start_y = ty->termstate.scroll_y1;
71 end_y = ty->state.scroll_y2 - 1; 71 end_y = ty->termstate.scroll_y2 - 1;
72 } 72 }
73 else 73 else
74 if (!ty->altbuf) 74 if (!ty->altbuf)
@@ -108,10 +108,10 @@ _termpty_text_scroll_rev(Termpty *ty, Eina_Bool clear)
108 Termcell *cells, *cells2 = NULL; 108 Termcell *cells, *cells2 = NULL;
109 int y, start_y = 0, end_y = ty->h - 1; 109 int y, start_y = 0, end_y = ty->h - 1;
110 110
111 if (ty->state.scroll_y2 != 0) 111 if (ty->termstate.scroll_y2 != 0)
112 { 112 {
113 start_y = ty->state.scroll_y1; 113 start_y = ty->termstate.scroll_y1;
114 end_y = ty->state.scroll_y2 - 1; 114 end_y = ty->termstate.scroll_y2 - 1;
115 } 115 }
116 DBG("... scroll rev!!!!! [%i->%i]", start_y, end_y); 116 DBG("... scroll rev!!!!! [%i->%i]", start_y, end_y);
117 termio_scroll(ty->obj, 1, start_y, end_y); 117 termio_scroll(ty->obj, 1, start_y, end_y);
@@ -146,11 +146,11 @@ _termpty_text_scroll_test(Termpty *ty, Eina_Bool clear)
146{ 146{
147 int e = ty->h; 147 int e = ty->h;
148 148
149 if (ty->state.scroll_y2 != 0) e = ty->state.scroll_y2; 149 if (ty->termstate.scroll_y2 != 0) e = ty->termstate.scroll_y2;
150 if (ty->state.cy >= e) 150 if (ty->cursor_state.cy >= e)
151 { 151 {
152 _termpty_text_scroll(ty, clear); 152 _termpty_text_scroll(ty, clear);
153 ty->state.cy = e - 1; 153 ty->cursor_state.cy = e - 1;
154 } 154 }
155} 155}
156 156
@@ -159,11 +159,11 @@ _termpty_text_scroll_rev_test(Termpty *ty, Eina_Bool clear)
159{ 159{
160 int b = 0; 160 int b = 0;
161 161
162 if (ty->state.scroll_y1 != 0) b = ty->state.scroll_y1; 162 if (ty->termstate.scroll_y1 != 0) b = ty->termstate.scroll_y1;
163 if (ty->state.cy < b) 163 if (ty->cursor_state.cy < b)
164 { 164 {
165 _termpty_text_scroll_rev(ty, clear); 165 _termpty_text_scroll_rev(ty, clear);
166 ty->state.cy = b; 166 ty->cursor_state.cy = b;
167 } 167 }
168} 168}
169 169
@@ -173,66 +173,68 @@ _termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
173 Termcell *cells; 173 Termcell *cells;
174 int i, j; 174 int i, j;
175 175
176 termio_content_change(ty->obj, ty->state.cx, ty->state.cy, len); 176 termio_content_change(ty->obj, ty->cursor_state.cx, ty->cursor_state.cy, len);
177 177
178 cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy)); 178 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
179 for (i = 0; i < len; i++) 179 for (i = 0; i < len; i++)
180 { 180 {
181 Eina_Unicode g; 181 Eina_Unicode g;
182 182
183 if (ty->state.wrapnext) 183 if (ty->termstate.wrapnext)
184 { 184 {
185 cells[ty->w - 1].att.autowrapped = 1; 185 cells[ty->w - 1].att.autowrapped = 1;
186 ty->state.wrapnext = 0; 186 ty->termstate.wrapnext = 0;
187 ty->state.cx = 0; 187 ty->cursor_state.cx = 0;
188 ty->state.cy++; 188 ty->cursor_state.cy++;
189 _termpty_text_scroll_test(ty, EINA_TRUE); 189 _termpty_text_scroll_test(ty, EINA_TRUE);
190 cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy)); 190 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
191 } 191 }
192 if (ty->state.insert) 192 if (ty->termstate.insert)
193 { 193 {
194 for (j = ty->w - 1; j > ty->state.cx; j--) 194 for (j = ty->w - 1; j > ty->cursor_state.cx; j--)
195 termpty_cell_copy(ty, &(cells[j - 1]), &(cells[j]), 1); 195 termpty_cell_copy(ty, &(cells[j - 1]), &(cells[j]), 1);
196 } 196 }
197 197
198 g = _termpty_charset_trans(codepoints[i], &ty->state); 198 g = _termpty_charset_trans(codepoints[i], ty);
199 199
200 termpty_cell_codepoint_att_fill(ty, g, ty->state.att, 200 termpty_cell_codepoint_att_fill(ty, g, ty->termstate.att,
201 &(cells[ty->state.cx]), 1); 201 &(cells[ty->cursor_state.cx]), 1);
202#if defined(SUPPORT_DBLWIDTH) 202#if defined(SUPPORT_DBLWIDTH)
203 cells[ty->state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g); 203 cells[ty->cursor_state.cx].att.dblwidth = _termpty_is_dblwidth_get(ty, g);
204 if (EINA_UNLIKELY((cells[ty->state.cx].att.dblwidth) && (ty->state.cx < (ty->w - 1)))) 204 if (EINA_UNLIKELY((cells[ty->cursor_state.cx].att.dblwidth) && (ty->cursor_state.cx < (ty->w - 1))))
205 { 205 {
206 TERMPTY_FMTCLR(cells[ty->state.cx].att); 206 TERMPTY_FMTCLR(cells[ty->cursor_state.cx].att);
207 termpty_cell_codepoint_att_fill(ty, 0, cells[ty->state.cx].att, 207 termpty_cell_codepoint_att_fill(ty, 0, cells[ty->cursor_state.cx].att,
208 &(cells[ty->state.cx + 1]), 1); 208 &(cells[ty->cursor_state.cx + 1]), 1);
209 } 209 }
210#endif 210#endif
211 if (ty->state.wrap) 211 if (ty->termstate.wrap)
212 { 212 {
213 unsigned char offset = 1; 213 unsigned char offset = 1;
214 214
215 ty->state.wrapnext = 0; 215 ty->termstate.wrapnext = 0;
216#if defined(SUPPORT_DBLWIDTH) 216#if defined(SUPPORT_DBLWIDTH)
217 if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth)) 217 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
218 offset = 2; 218 offset = 2;
219#endif 219#endif
220 if (EINA_UNLIKELY(ty->state.cx >= (ty->w - offset))) ty->state.wrapnext = 1; 220 if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset)))
221 else ty->state.cx += offset; 221 ty->termstate.wrapnext = 1;
222 else
223 ty->cursor_state.cx += offset;
222 } 224 }
223 else 225 else
224 { 226 {
225 unsigned char offset = 1; 227 unsigned char offset = 1;
226 228
227 ty->state.wrapnext = 0; 229 ty->termstate.wrapnext = 0;
228#if defined(SUPPORT_DBLWIDTH) 230#if defined(SUPPORT_DBLWIDTH)
229 if (EINA_UNLIKELY(cells[ty->state.cx].att.dblwidth)) 231 if (EINA_UNLIKELY(cells[ty->cursor_state.cx].att.dblwidth))
230 offset = 2; 232 offset = 2;
231#endif 233#endif
232 ty->state.cx += offset; 234 ty->cursor_state.cx += offset;
233 if (ty->state.cx > (ty->w - offset)) 235 if (ty->cursor_state.cx > (ty->w - offset))
234 { 236 {
235 ty->state.cx = ty->w - offset; 237 ty->cursor_state.cx = ty->w - offset;
236 return; 238 return;
237 } 239 }
238 } 240 }
@@ -244,16 +246,16 @@ _termpty_clear_line(Termpty *ty, Termpty_Clear mode, int limit)
244{ 246{
245 Termcell *cells; 247 Termcell *cells;
246 int n = 0; 248 int n = 0;
247 Evas_Coord x = 0, y = ty->state.cy; 249 Evas_Coord x = 0, y = ty->cursor_state.cy;
248 250
249 switch (mode) 251 switch (mode)
250 { 252 {
251 case TERMPTY_CLR_END: 253 case TERMPTY_CLR_END:
252 n = ty->w - ty->state.cx; 254 n = ty->w - ty->cursor_state.cx;
253 x = ty->state.cx; 255 x = ty->cursor_state.cx;
254 break; 256 break;
255 case TERMPTY_CLR_BEGIN: 257 case TERMPTY_CLR_BEGIN:
256 n = ty->state.cx + 1; 258 n = ty->cursor_state.cx + 1;
257 break; 259 break;
258 case TERMPTY_CLR_ALL: 260 case TERMPTY_CLR_ALL:
259 n = ty->w; 261 n = ty->w;
@@ -276,33 +278,33 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode)
276 { 278 {
277 case TERMPTY_CLR_END: 279 case TERMPTY_CLR_END:
278 _termpty_clear_line(ty, mode, ty->w); 280 _termpty_clear_line(ty, mode, ty->w);
279 if (ty->state.cy < (ty->h - 1)) 281 if (ty->cursor_state.cy < (ty->h - 1))
280 { 282 {
281 int l = ty->h - (ty->state.cy + 1); 283 int l = ty->h - (ty->cursor_state.cy + 1);
282 284
283 termio_content_change(ty->obj, 0, ty->state.cy, l * ty->w); 285 termio_content_change(ty->obj, 0, ty->cursor_state.cy, l * ty->w);
284 286
285 while (l) 287 while (l)
286 { 288 {
287 cells = &(TERMPTY_SCREEN(ty, 0, (ty->state.cy + l))); 289 cells = &(TERMPTY_SCREEN(ty, 0, (ty->cursor_state.cy + l)));
288 _text_clear(ty, cells, ty->w, 0, EINA_TRUE); 290 _text_clear(ty, cells, ty->w, 0, EINA_TRUE);
289 l--; 291 l--;
290 } 292 }
291 } 293 }
292 break; 294 break;
293 case TERMPTY_CLR_BEGIN: 295 case TERMPTY_CLR_BEGIN:
294 if (ty->state.cy > 0) 296 if (ty->cursor_state.cy > 0)
295 { 297 {
296 // First clear from circular > height, then from 0 to circular 298 // First clear from circular > height, then from 0 to circular
297 int y = ty->state.cy + ty->circular_offset; 299 int y = ty->cursor_state.cy + ty->circular_offset;
298 300
299 termio_content_change(ty->obj, 0, 0, ty->state.cy * ty->w); 301 termio_content_change(ty->obj, 0, 0, ty->cursor_state.cy * ty->w);
300 302
301 cells = &(TERMPTY_SCREEN(ty, 0, 0)); 303 cells = &(TERMPTY_SCREEN(ty, 0, 0));
302 304
303 if (y < ty->h) 305 if (y < ty->h)
304 { 306 {
305 _text_clear(ty, cells, ty->w * ty->state.cy, 0, EINA_TRUE); 307 _text_clear(ty, cells, ty->w * ty->cursor_state.cy, 0, EINA_TRUE);
306 } 308 }
307 else 309 else
308 { 310 {
@@ -318,7 +320,7 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode)
318 case TERMPTY_CLR_ALL: 320 case TERMPTY_CLR_ALL:
319 ty->circular_offset = 0; 321 ty->circular_offset = 0;
320 _text_clear(ty, ty->screen, ty->w * ty->h, 0, EINA_TRUE); 322 _text_clear(ty, ty->screen, ty->w * ty->h, 0, EINA_TRUE);
321 ty->state.scroll_y2 = 0; 323 ty->termstate.scroll_y2 = 0;
322 if (ty->cb.cancel_sel.func) 324 if (ty->cb.cancel_sel.func)
323 ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); 325 ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
324 break; 326 break;
@@ -365,28 +367,32 @@ _termpty_reset_att(Termatt *att)
365void 367void
366_termpty_reset_state(Termpty *ty) 368_termpty_reset_state(Termpty *ty)
367{ 369{
368 ty->state.cx = 0; 370 ty->cursor_state.cx = 0;
369 ty->state.cy = 0; 371 ty->cursor_state.cy = 0;
370 ty->state.scroll_y1 = 0; 372 ty->termstate.scroll_y1 = 0;
371 ty->state.scroll_y2 = 0; 373 ty->termstate.scroll_y2 = 0;
372 ty->state.had_cr_x = 0; 374 ty->termstate.had_cr_x = 0;
373 ty->state.had_cr_y = 0; 375 ty->termstate.had_cr_y = 0;
374 _termpty_reset_att(&(ty->state.att)); 376 _termpty_reset_att(&(ty->termstate.att));
375 ty->state.charset = 0; 377 ty->termstate.charset = 0;
376 ty->state.charsetch = 'B'; 378 ty->termstate.charsetch = 'B';
377 ty->state.chset[0] = 'B'; 379 ty->termstate.chset[0] = 'B';
378 ty->state.chset[1] = 'B'; 380 ty->termstate.chset[1] = 'B';
379 ty->state.chset[2] = 'B'; 381 ty->termstate.chset[2] = 'B';
380 ty->state.chset[3] = 'B'; 382 ty->termstate.chset[3] = 'B';
381 ty->state.multibyte = 0; 383 ty->termstate.multibyte = 0;
382 ty->state.alt_kp = 0; 384 ty->termstate.alt_kp = 0;
383 ty->state.insert = 0; 385 ty->termstate.insert = 0;
384 ty->state.appcursor = 0; 386 ty->termstate.appcursor = 0;
385 ty->state.wrap = 1; 387 ty->termstate.wrap = 1;
386 ty->state.wrapnext = 0; 388 ty->termstate.wrapnext = 0;
387 ty->state.hidecursor = 0; 389 ty->termstate.crlf = 0;
388 ty->state.crlf = 0; 390 ty->termstate.had_cr = 0;
389 ty->state.had_cr = 0; 391 ty->termstate.send_bs = 0;
392 ty->termstate.reverse = 0;
393 ty->termstate.no_autorepeat = 0;
394 ty->termstate.cjk_ambiguous_wide = 0;
395 ty->termstate.hide_cursor = 0;
390 ty->mouse_mode = MOUSE_OFF; 396 ty->mouse_mode = MOUSE_OFF;
391 ty->mouse_ext = MOUSE_EXT_NONE; 397 ty->mouse_ext = MOUSE_EXT_NONE;
392 ty->bracketed_paste = 0; 398 ty->bracketed_paste = 0;
@@ -410,9 +416,16 @@ _termpty_reset_state(Termpty *ty)
410} 416}
411 417
412void 418void
413_termpty_cursor_copy(Termstate *state, Termstate *dest) 419_termpty_cursor_copy(Termpty *ty, Eina_Bool save)
414{ 420{
415 dest->cx = state->cx; 421 if (save)
416 dest->cy = state->cy; 422 {
417 dest->wrapnext = state->wrapnext; 423 ty->cursor_save.cx = ty->cursor_state.cx;
424 ty->cursor_save.cy = ty->cursor_state.cy;
425 }
426 else
427 {
428 ty->cursor_state.cx = ty->cursor_save.cx;
429 ty->cursor_state.cy = ty->cursor_save.cy;
430 }
418} 431}
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);
20void _termpty_clear_all(Termpty *ty); 20void _termpty_clear_all(Termpty *ty);
21void _termpty_reset_att(Termatt *att); 21void _termpty_reset_att(Termatt *att);
22void _termpty_reset_state(Termpty *ty); 22void _termpty_reset_state(Termpty *ty);
23void _termpty_cursor_copy(Termstate *state, Termstate *dest); 23void _termpty_cursor_copy(Termpty *ty, Eina_Bool save);
24 24
25#define _term_txt_write(ty, txt) termpty_write(ty, txt, sizeof(txt) - 1) 25#define _term_txt_write(ty, txt) termpty_write(ty, txt, sizeof(txt) - 1)
26 26