Commit: ff7308fc863e49dbf8835c92f363c93dbb93f241
Parent: 5206f56b0bbbdb63c1b9fd6fc8bca6380601aa6d
Author: Randy Palamar
Date: Mon, 28 Oct 2024 07:32:38 -0600
check for line length > 0 directly in feed_line
Diffstat:
M | terminal.c | | | 45 | ++++++++++++++++++++------------------------- |
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/terminal.c b/terminal.c
@@ -101,13 +101,18 @@ init_line(Line *l, u8 *position, CellStyle cursor_state)
l->cursor_state = cursor_state;
}
-static void
+static size
feed_line(LineBuf *lb, u8 *position, CellStyle cursor_state)
{
- lb->buf[lb->widx++].end = position;
- lb->widx = lb->widx >= lb->cap ? 0 : lb->widx;
- lb->filled += lb->filled <= lb->widx;
- init_line(lb->buf + lb->widx, position, cursor_state);
+ size result = 0;
+ if (lb->buf[lb->widx].start != position) {
+ lb->buf[lb->widx++].end = position;
+ lb->widx = lb->widx >= lb->cap ? 0 : lb->widx;
+ lb->filled += lb->filled <= lb->widx;
+ init_line(lb->buf + lb->widx, position, cursor_state);
+ result = 1;
+ }
+ return result;
}
static void
@@ -1173,14 +1178,12 @@ split_raw_input_to_lines(Term *t, s8 raw)
t->unprocessed_bytes = old.len;
goto end;
case EMC_CURSOR_MOVED:
- if (line_length(tv->lines.buf + tv->lines.widx)) {
- parsed_lines++;
- feed_line(&tv->lines, raw.data, t->cursor.style);
- }
+ parsed_lines += feed_line(&tv->lines, raw.data,
+ t->cursor.style);
break;
case EMC_SWAPPED_SCREEN:
- parsed_lines++;
- feed_line(&tv->lines, old.data, t->cursor.style);
+ parsed_lines += feed_line(&tv->lines, old.data,
+ t->cursor.style);
TermView *nv = t->views + t->view_idx;
size nstart = nv->log.widx;
mem_copy(raw, (s8){nv->log.cap, nv->log.buf + nstart});
@@ -1194,8 +1197,7 @@ split_raw_input_to_lines(Term *t, s8 raw)
}
} else if (cp == '\n') {
raw = consume(raw, 1);
- parsed_lines++;
- feed_line(&tv->lines, raw.data, t->cursor.style);
+ parsed_lines += feed_line(&tv->lines, raw.data, t->cursor.style);
} else if (cp & 0x80) {
tv->lines.buf[tv->lines.widx].has_unicode = 1;
/* TODO: this is probably slow */
@@ -1213,8 +1215,7 @@ split_raw_input_to_lines(Term *t, s8 raw)
tv->lines.buf[tv->lines.widx].end = raw.data;
if (line_length(tv->lines.buf + tv->lines.widx) > SPLIT_LONG) {
- parsed_lines++;
- feed_line(&tv->lines, raw.data, t->cursor.style);
+ parsed_lines += feed_line(&tv->lines, raw.data, t->cursor.style);
}
}
t->unprocessed_bytes = 0;
@@ -1377,10 +1378,6 @@ handle_input(Term *t, Arena a, s8 raw)
cp = get_ascii(&raw);
}
- /* TODO: cleanup */
- if (cp == '\n')
- feed_line(&tv->lines, raw.data, t->cursor.style);
-
ASSERT(cp != (u32)-1);
if (ISCONTROL(cp)) {
@@ -1389,10 +1386,9 @@ handle_input(Term *t, Arena a, s8 raw)
raw.len = start_len;
goto end;
}
- 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);
- }
+ if (t->cursor.pos.y != old_curs_y)
+ feed_line(&tv->lines, raw.data, t->cursor.style);
+
continue;
} else if (t->escape & EM_CSI) {
t->csi.raw.len++;
@@ -1415,8 +1411,7 @@ handle_input(Term *t, Arena a, s8 raw)
t->cursor.style);
tv = nv;
} 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);
+ feed_line(&tv->lines, raw.data, t->cursor.style);
}
}
continue;