Commit: 0940841f6decc5c9eeaca2997a06ad5eb4aa2438
Parent: 9f1013ae9084c9abe499a2b58e108731b196cea5
Author: Randy Palamar
Date: Sun, 7 Jul 2024 09:38:43 -0600
handle case when line buf wraps around
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/terminal.c b/terminal.c
@@ -662,15 +662,22 @@ push_line(Term *t, Line *line)
}
}
+static size
+get_line_idx(LineBuf *lb, size off)
+{
+ ASSERT(-off <= lb->filled);
+ size result = lb->widx + off;
+ if (result < 0)
+ result += lb->filled;
+ return result;
+}
+
static void
blit_lines(Term *t)
{
size line_count = t->size.h;
if (line_count > t->log_lines.filled)
line_count = t->log_lines.filled;
- /* TODO: handle case where widx has wrapped around */
- ASSERT(t->log_lines.widx >= line_count);
- size line_off = t->log_lines.widx - line_count;
/* TODO: Performance!!! */
fb_clear_region(t, 0, t->size.h, 0, t->size.w);
@@ -679,6 +686,7 @@ blit_lines(Term *t)
t->cursor.row = 0;
t->cursor.col = 0;
for (size i = 0; i <= line_count; i++) {
- push_line(t, t->log_lines.buf + line_off + i);
+ size line_idx = get_line_idx(&t->log_lines, -line_count + i);
+ push_line(t, t->log_lines.buf + line_idx);
}
}