summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-06-03 15:00:13 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-06-03 15:00:13 +0900
commit074eece5f7d1f749f96bd03a77e82156d551941a (patch)
tree5a554d7592048d5f2afe78a1b22521fbd3cb7e9d /src
parent7b72052773c5e13cf2c2b55710efa4b716004775 (diff)
Revert "ensure cursor coordinates are always valid"
This reverts commit 1f3f779258c86b170edb3e634548a446fe5c9b58. this breaks terminal scrolling entirely! can't scroll anymore at all in standard shell. just try a simple: find / -print
Diffstat (limited to 'src')
-rw-r--r--src/bin/termpty.c28
-rw-r--r--src/bin/termpty.h8
-rw-r--r--src/bin/termptyesc.c46
-rw-r--r--src/bin/termptyops.c13
4 files changed, 37 insertions, 58 deletions
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 5e49ba4..c9b8b7d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -270,14 +270,21 @@ _cb_fd_read(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
270static void 270static void
271_limit_coord(Termpty *ty) 271_limit_coord(Termpty *ty)
272{ 272{
273 TERMPTY_RESTRICT_FIELD(ty->termstate.had_cr_x, 0, ty->w); 273 ty->termstate.wrapnext = 0;
274 TERMPTY_RESTRICT_FIELD(ty->termstate.had_cr_y, 0, ty->h); 274 if (ty->termstate.had_cr_x >= ty->w)
275 275 ty->termstate.had_cr_x = ty->w - 1;
276 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 276 if (ty->termstate.had_cr_y >= ty->h)
277 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); 277 ty->termstate.had_cr_y = ty->h - 1;
278 278
279 TERMPTY_RESTRICT_FIELD(ty->cursor_save.cx, 0, ty->w); 279 if (ty->cursor_state.cx >= ty->w)
280 TERMPTY_RESTRICT_FIELD(ty->cursor_save.cy, 0, ty->h); 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;
281} 288}
282 289
283Termpty * 290Termpty *
@@ -890,10 +897,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
890 897
891 ty->cursor_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;
892 899
893 if (altbuf) 900 if (altbuf) termpty_screen_swap(ty);
894 termpty_screen_swap(ty);
895
896 ty->termstate.wrapnext = 0;
897 901
898 _limit_coord(ty); 902 _limit_coord(ty);
899 903
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 7aba97a..d5aad70 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -260,12 +260,4 @@ extern int _termpty_log_dom;
260#define TERMPTY_FMTCLR(Tatt) \ 260#define TERMPTY_FMTCLR(Tatt) \
261 (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0 261 (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0
262 262
263#define TERMPTY_RESTRICT_FIELD(Field, Min, Max) \
264 do { \
265 if (Field >= Max) \
266 Field = Max - 1; \
267 else if (Field < Min) \
268 Field = Min; \
269 } while (0)
270
271#endif 263#endif
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 6de1340..14dbbb7 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -66,7 +66,7 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
66 ty->termstate.had_cr = 0; 66 ty->termstate.had_cr = 0;
67 ty->termstate.wrapnext = 0; 67 ty->termstate.wrapnext = 0;
68 ty->cursor_state.cx--; 68 ty->cursor_state.cx--;
69 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 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");
@@ -75,7 +75,8 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
75 ty->termstate.wrapnext = 0; 75 ty->termstate.wrapnext = 0;
76 ty->cursor_state.cx += 8; 76 ty->cursor_state.cx += 8;
77 ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8; 77 ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
78 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 78 if (ty->cursor_state.cx >= ty->w)
79 ty->cursor_state.cx = ty->w - 1;
79 return; 80 return;
80 case 0x0a: // LF '\n' (new line) 81 case 0x0a: // LF '\n' (new line)
81 case 0x0b: // VT '\v' (vertical tab) 82 case 0x0b: // VT '\v' (vertical tab)
@@ -90,7 +91,6 @@ _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
90 ty->termstate.wrapnext = 0; 91 ty->termstate.wrapnext = 0;
91 if (ty->termstate.crlf) ty->cursor_state.cx = 0; 92 if (ty->termstate.crlf) ty->cursor_state.cx = 0;
92 ty->cursor_state.cy++; 93 ty->cursor_state.cy++;
93 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
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)
@@ -682,7 +682,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
682 termpty_text_append(ty, blank, 1); 682 termpty_text_append(ty, blank, 1);
683 ty->termstate.insert = pi; 683 ty->termstate.insert = pi;
684 ty->cursor_state.cx = cx; 684 ty->cursor_state.cx = cx;
685 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
686 } 685 }
687 break; 686 break;
688 case 'A': // cursor up N 687 case 'A': // cursor up N
@@ -692,7 +691,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
692 DBG("cursor up %d", arg); 691 DBG("cursor up %d", arg);
693 ty->termstate.wrapnext = 0; 692 ty->termstate.wrapnext = 0;
694 ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg); 693 ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
695 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
696 break; 694 break;
697 case 'B': // cursor down N 695 case 'B': // cursor down N
698 arg = _csi_arg_get(&b); 696 arg = _csi_arg_get(&b);
@@ -700,7 +698,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
700 DBG("cursor down %d", arg); 698 DBG("cursor down %d", arg);
701 ty->termstate.wrapnext = 0; 699 ty->termstate.wrapnext = 0;
702 ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg); 700 ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
703 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
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);
@@ -708,8 +705,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
708 DBG("cursor left %d", arg); 705 DBG("cursor left %d", arg);
709 ty->termstate.wrapnext = 0; 706 ty->termstate.wrapnext = 0;
710 for (i = 0; i < arg; i++) 707 for (i = 0; i < arg; i++)
711 ty->cursor_state.cx--; 708 {
712 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 709 ty->cursor_state.cx--;
710 if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
711 }
713 break; 712 break;
714 case 'C': // cursor right N 713 case 'C': // cursor right N
715 case 'a': // cursor right N 714 case 'a': // cursor right N
@@ -718,8 +717,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
718 DBG("cursor right %d", arg); 717 DBG("cursor right %d", arg);
719 ty->termstate.wrapnext = 0; 718 ty->termstate.wrapnext = 0;
720 for (i = 0; i < arg; i++) 719 for (i = 0; i < arg; i++)
721 ty->cursor_state.cx++; 720 {
722 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 721 ty->cursor_state.cx++;
722 if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
723 }
723 break; 724 break;
724 case 'H': // cursor pos set 725 case 'H': // cursor pos set
725 case 'f': // cursor pos set 726 case 'f': // cursor pos set
@@ -739,7 +740,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
739 if (b) 740 if (b)
740 { 741 {
741 ty->cursor_state.cy = arg; 742 ty->cursor_state.cy = arg;
742 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
743 arg = _csi_arg_get(&b); 743 arg = _csi_arg_get(&b);
744 if (arg < 1) arg = 1; 744 if (arg < 1) arg = 1;
745 arg--; 745 arg--;
@@ -747,14 +747,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
747 else arg = 0; 747 else arg = 0;
748 748
749 if (arg >= ty->w) arg = ty->w - 1; 749 if (arg >= ty->w) arg = ty->w - 1;
750 if (b) 750 if (b) ty->cursor_state.cx = arg;
751 {
752 ty->cursor_state.cx = arg;
753 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
754 }
755 } 751 }
756 ty->cursor_state.cy += ty->termstate.margin_top; 752 ty->cursor_state.cy += ty->termstate.margin_top;
757 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
758 break; 753 break;
759 case 'G': // to column N 754 case 'G': // to column N
760 arg = _csi_arg_get(&b); 755 arg = _csi_arg_get(&b);
@@ -762,7 +757,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
762 DBG("to column %d", arg); 757 DBG("to column %d", arg);
763 ty->termstate.wrapnext = 0; 758 ty->termstate.wrapnext = 0;
764 ty->cursor_state.cx = arg - 1; 759 ty->cursor_state.cx = arg - 1;
765 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w); 760 if (ty->cursor_state.cx < 0) ty->cursor_state.cx = 0;
761 else if (ty->cursor_state.cx >= ty->w) ty->cursor_state.cx = ty->w - 1;
766 break; 762 break;
767 case 'd': // to row N 763 case 'd': // to row N
768 arg = _csi_arg_get(&b); 764 arg = _csi_arg_get(&b);
@@ -770,7 +766,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
770 DBG("to row %d", arg); 766 DBG("to row %d", arg);
771 ty->termstate.wrapnext = 0; 767 ty->termstate.wrapnext = 0;
772 ty->cursor_state.cy = arg - 1; 768 ty->cursor_state.cy = arg - 1;
773 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); 769 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
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);
@@ -778,7 +775,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
778 DBG("down relative %d rows, and to col 0", arg); 775 DBG("down relative %d rows, and to col 0", arg);
779 ty->termstate.wrapnext = 0; 776 ty->termstate.wrapnext = 0;
780 ty->cursor_state.cy += arg; 777 ty->cursor_state.cy += arg;
781 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); 778 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
779 else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
782 ty->cursor_state.cx = 0; 780 ty->cursor_state.cx = 0;
783 break; 781 break;
784 case 'F': // up relative N rows, and to col 0 782 case 'F': // up relative N rows, and to col 0
@@ -787,7 +785,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
787 DBG("up relative %d rows, and to col 0", arg); 785 DBG("up relative %d rows, and to col 0", arg);
788 ty->termstate.wrapnext = 0; 786 ty->termstate.wrapnext = 0;
789 ty->cursor_state.cy -= arg; 787 ty->cursor_state.cy -= arg;
790 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); 788 if (ty->cursor_state.cy < 0) ty->cursor_state.cy = 0;
789 else if (ty->cursor_state.cy >= ty->h) ty->cursor_state.cy = ty->h - 1;
791 ty->cursor_state.cx = 0; 790 ty->cursor_state.cx = 0;
792 break; 791 break;
793 case 'X': // erase N chars 792 case 'X': // erase N chars
@@ -1030,9 +1029,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1030 if (!arg) 1029 if (!arg)
1031 { 1030 {
1032 ty->cursor_state.cx = cx; 1031 ty->cursor_state.cx = cx;
1033 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
1034 ty->cursor_state.cy = cy; 1032 ty->cursor_state.cy = cy;
1035 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
1036 } 1033 }
1037 } 1034 }
1038 break; 1035 break;
@@ -1572,20 +1569,17 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
1572 case 'M': // move to prev line 1569 case 'M': // move to prev line
1573 ty->termstate.wrapnext = 0; 1570 ty->termstate.wrapnext = 0;
1574 ty->cursor_state.cy--; 1571 ty->cursor_state.cy--;
1575 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
1576 termpty_text_scroll_rev_test(ty, EINA_TRUE); 1572 termpty_text_scroll_rev_test(ty, EINA_TRUE);
1577 return 1; 1573 return 1;
1578 case 'D': // move to next line 1574 case 'D': // move to next line
1579 ty->termstate.wrapnext = 0; 1575 ty->termstate.wrapnext = 0;
1580 ty->cursor_state.cy++; 1576 ty->cursor_state.cy++;
1581 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
1582 termpty_text_scroll_test(ty, EINA_FALSE); 1577 termpty_text_scroll_test(ty, EINA_FALSE);
1583 return 1; 1578 return 1;
1584 case 'E': // add \n\r 1579 case 'E': // add \n\r
1585 ty->termstate.wrapnext = 0; 1580 ty->termstate.wrapnext = 0;
1586 ty->cursor_state.cx = 0; 1581 ty->cursor_state.cx = 0;
1587 ty->cursor_state.cy++; 1582 ty->cursor_state.cy++;
1588 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
1589 termpty_text_scroll_test(ty, EINA_FALSE); 1583 termpty_text_scroll_test(ty, EINA_FALSE);
1590 return 1; 1584 return 1;
1591 case 'Z': // same a 'ESC [ Pn c' 1585 case 'Z': // same a 'ESC [ Pn c'
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index d35900c..e9d93f8 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -7,7 +7,6 @@
7#include "termptygfx.h" 7#include "termptygfx.h"
8#include "termptysave.h" 8#include "termptysave.h"
9#include "miniview.h" 9#include "miniview.h"
10#include <assert.h>
11 10
12#undef CRITICAL 11#undef CRITICAL
13#undef ERR 12#undef ERR
@@ -152,7 +151,6 @@ termpty_text_scroll_test(Termpty *ty, Eina_Bool clear)
152 { 151 {
153 termpty_text_scroll(ty, clear); 152 termpty_text_scroll(ty, clear);
154 ty->cursor_state.cy = e - 1; 153 ty->cursor_state.cy = e - 1;
155 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
156 } 154 }
157} 155}
158 156
@@ -166,7 +164,6 @@ termpty_text_scroll_rev_test(Termpty *ty, Eina_Bool clear)
166 { 164 {
167 termpty_text_scroll_rev(ty, clear); 165 termpty_text_scroll_rev(ty, clear);
168 ty->cursor_state.cy = b; 166 ty->cursor_state.cy = b;
169 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
170 } 167 }
171} 168}
172 169
@@ -189,7 +186,6 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
189 ty->termstate.wrapnext = 0; 186 ty->termstate.wrapnext = 0;
190 ty->cursor_state.cx = 0; 187 ty->cursor_state.cx = 0;
191 ty->cursor_state.cy++; 188 ty->cursor_state.cy++;
192 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
193 termpty_text_scroll_test(ty, EINA_TRUE); 189 termpty_text_scroll_test(ty, EINA_TRUE);
194 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy)); 190 cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
195 } 191 }
@@ -224,10 +220,7 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
224 if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset))) 220 if (EINA_UNLIKELY(ty->cursor_state.cx >= (ty->w - offset)))
225 ty->termstate.wrapnext = 1; 221 ty->termstate.wrapnext = 1;
226 else 222 else
227 { 223 ty->cursor_state.cx += offset;
228 ty->cursor_state.cx += offset;
229 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
230 }
231 } 224 }
232 else 225 else
233 { 226 {
@@ -242,10 +235,8 @@ termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len)
242 if (ty->cursor_state.cx > (ty->w - offset)) 235 if (ty->cursor_state.cx > (ty->w - offset))
243 { 236 {
244 ty->cursor_state.cx = ty->w - offset; 237 ty->cursor_state.cx = ty->w - offset;
245 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
246 return; 238 return;
247 } 239 }
248 TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
249 } 240 }
250 } 241 }
251} 242}
@@ -257,8 +248,6 @@ termpty_clear_line(Termpty *ty, Termpty_Clear mode, int limit)
257 int n = 0; 248 int n = 0;
258 Evas_Coord x = 0, y = ty->cursor_state.cy; 249 Evas_Coord x = 0, y = ty->cursor_state.cy;
259 250
260 assert (y >= 0 && y < ty->h);
261
262 switch (mode) 251 switch (mode)
263 { 252 {
264 case TERMPTY_CLR_END: 253 case TERMPTY_CLR_END: