Commit: 9b3eb37506c276ef2d7575f8abc1ece08b3e7f94
Parent: 954a41be31f931d6996d25581de9959d22d3bb83
Author: Randy Palamar
Date: Mon, 28 Oct 2024 06:43:30 -0600
handle missed error case in handle_escape
also don't split lines because of \b,\r etc.
Diffstat:
M | terminal.c | | | 34 | ++++++++++++++++++++-------------- |
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/terminal.c b/terminal.c
@@ -944,10 +944,11 @@ handle_osc(Term *t, s8 *raw, Arena a)
END_TIMED_BLOCK();
}
-static void
+static i32
handle_escape(Term *t, s8 *raw, Arena a)
{
BEGIN_TIMED_BLOCK();
+ i32 result = 0;
u32 cp = get_ascii(raw);
switch (cp) {
case '[': reset_csi(&t->csi, raw); t->escape |= EM_CSI; break;
@@ -957,7 +958,8 @@ handle_escape(Term *t, s8 *raw, Arena a)
case '*': /* G2D4 -- set tertiary charset G2 */
case '+': /* G3D4 -- set quaternary charset G3 */
case '%': /* utf-8 mode */
- get_ascii(raw);
+ if (!raw->len) result = 1;
+ else get_ascii(raw);
break;
case '=': /* DECPAM -- application keypad */
case '>': /* DECPNM -- normal keypad mode */
@@ -993,13 +995,18 @@ handle_escape(Term *t, s8 *raw, Arena a)
break;
}
END_TIMED_BLOCK();
+ return result;
}
-static void
+static i32
push_control(Term *t, s8 *line, u32 cp, Arena a)
{
+ i32 result = 0;
switch (cp) {
- case 0x1B: handle_escape(t, line, a); break;
+ case 0x1B:
+ if (!line->len) result = 1;
+ else result = handle_escape(t, line, a);
+ break;
case '\r': t->cursor.pos.x = 0; break;
case '\n': push_newline(t, t->mode & TM_CRLF); break;
case '\t': push_tab(t, 1); break;
@@ -1011,6 +1018,7 @@ push_control(Term *t, s8 *line, u32 cp, Arena a)
if (cp != 0x1B) {
if (t->escape & EM_CSI) t->csi.raw.len++;
}
+ return result;
}
enum escape_moves_cursor_result {
@@ -1376,22 +1384,20 @@ handle_input(Term *t, Arena a, s8 raw)
ASSERT(cp != (u32)-1);
if (ISCONTROL(cp)) {
- if (cp == 0x1B && raw.len == 0) {
+ i32 old_curs_y = t->cursor.pos.y;
+ if (push_control(t, &raw, cp, a)) {
raw.len = start_len;
goto end;
- } else {
- iv2 old_curs = t->cursor.pos;
- push_control(t, &raw, cp, a);
- if (!equal_iv2(t->cursor.pos, old_curs)) {
- if (line_length(tv->lines.buf + tv->lines.widx))
- feed_line(&tv->lines, raw.data, t->cursor.style);
- }
+ }
+ if (t->cursor.pos.y != old_curs_y) {
+ if (line_length(tv->lines.buf + tv->lines.widx))
+ feed_line(&tv->lines, raw.data, t->cursor.style);
}
continue;
} else if (t->escape & EM_CSI) {
t->csi.raw.len++;
if (BETWEEN(cp, '@', '~')) {
- iv2 old_curs = t->cursor.pos;
+ i32 old_curs_y = t->cursor.pos.y;
i32 mode = t->mode & TM_ALTSCREEN;
handle_csi(t, &t->csi);
t->escape &= ~EM_CSI;
@@ -1408,7 +1414,7 @@ handle_input(Term *t, Arena a, s8 raw)
init_line(nv->lines.buf + nv->lines.widx, raw.data,
t->cursor.style);
tv = nv;
- } else if (!equal_iv2(t->cursor.pos, old_curs)) {
+ } else if (t->cursor.pos.y != old_curs_y) {
if (line_length(tv->lines.buf + tv->lines.widx))
feed_line(&tv->lines, raw.data, t->cursor.style);
}