vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: b6025c0413114757296b9fa9f6cba5abf1e42923
Parent: edaaf0ce489f04f6249a5decec53da01753acf17
Author: Randy Palamar
Date:   Sun, 11 Aug 2024 16:37:26 -0600

correct line start/end when the ring buffer wraps around

Diffstat:
Mdebug.c | 6+++---
Mterminal.c | 15+++++++++++----
2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/debug.c b/debug.c @@ -4,7 +4,7 @@ static Cursor simulate_line(Term *t, Line *line) { Cursor saved_cursor = t->cursor; - s8 l = line_to_s8(line); + s8 l = line_to_s8(line, &t->log); t->cursor.state = line->cursor_state; @@ -62,13 +62,13 @@ dump_last_line_to_file(Term *t) fputs("Line Idx -1:\n", f); Line *line = t->log_lines.buf + get_line_idx(&t->log_lines, -1); - s8 l = line_to_s8(line); + s8 l = line_to_s8(line, &t->log); fput_line_info(f, t, line); fwrite(l.data, 1, l.len, f); fputs("\nLine Idx 0:\n", f); line = t->log_lines.buf + get_line_idx(&t->log_lines, 0); - l = line_to_s8(line); + l = line_to_s8(line, &t->log); fput_line_info(f, t, line); fwrite(l.data, 1, l.len, f); diff --git a/terminal.c b/terminal.c @@ -85,10 +85,18 @@ line_length(Line *l) return l->end - l->start; } +/* NOTE: this will adjust the starting so that the line looks like a linear array */ static s8 -line_to_s8(Line *l) +line_to_s8(Line *l, RingBuf *rb) { + if (l->end < l->start) { + if (l->start >= rb->buf) l->start -= rb->cap; + else l->end += rb->cap; + ASSERT(l->end < rb->buf + 2 * rb->cap && l->end > rb->buf - rb->cap); + ASSERT(l->start < rb->buf + 2 * rb->cap && l->start > rb->buf - rb->cap); + } ASSERT(l->start <= l->end); + s8 result = {.len = l->end - l->start, .data = l->start}; return result; } @@ -747,8 +755,7 @@ split_raw_input_to_lines(Term *t, s8 raw) } lb->buf[lb->widx].end = raw.data; - //if (tv->lines.buf[tv->lines.widx].end < tv->lines.buf[tv->lines.widx].start) - // tv->lines.buf[tv->lines.widx].end += tv->log.cap; + if (line_length(lb->buf + lb->widx) > SPLIT_LONG) { parsed_lines++; feed_line(lb, raw.data, t->cursor.state); @@ -779,7 +786,7 @@ push_tab(Term *t) static void push_line(Term *t, Line *line, Arena a) { - s8 l = line_to_s8(line); + s8 l = line_to_s8(line, &t->log); t->cursor.state = line->cursor_state;