vtgl

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

Commit: fb1776d2b5ca53f66ad42c7c08f03a582aaa304f
Parent: 38e2d3ed9825721a3f0b5e61611b527c5b527503
Author: Randy Palamar
Date:   Mon,  4 Nov 2024 06:26:04 -0700

delete dead code from old method of line splitting

The complexity there isn't worth it. It can be re-explored from a
new viewpoint after optimizing the rest of the code with the help
of the debug overlay.

Diffstat:
Mdebug.c | 32--------------------------------
Mterminal.c | 203+------------------------------------------------------------------------------
2 files changed, 2 insertions(+), 233 deletions(-)

diff --git a/debug.c b/debug.c @@ -1,37 +1,5 @@ #include "util.h" -static Cursor -simulate_line(Term *t, Line *line) -{ - Cursor saved_cursor = t->cursor; - s8 l = line_to_s8(line, &t->views[t->view_idx].log); - - t->cursor.style = line->cursor_state; - - while (l.len) { - u32 cp; - if (line->has_unicode) cp = get_utf8(&l); - else cp = get_ascii(&l); - - u32 advance = g_tabstop - (t->cursor.pos.x % g_tabstop); - - switch (cp) { - case 0x1B: check_if_escape_moves_cursor(t, &l); break; - case '\r': t->cursor.pos.x = 0; break; - case '\n': cursor_move_to(t, t->cursor.pos.y + 1, t->cursor.pos.x); break; - case '\t': cursor_move_to(t, t->cursor.pos.y, t->cursor.pos.x + advance); break; - case '\b': cursor_move_to(t, t->cursor.pos.y, t->cursor.pos.x - 1); break; - case '\a': break; - default: cursor_move_to(t, t->cursor.pos.y, t->cursor.pos.x + 1); break; - } - } - - Cursor result = t->cursor; - t->cursor = saved_cursor; - - return result; -} - static void dump_lines_to_file(Term *t) { diff --git a/terminal.c b/terminal.c @@ -6,6 +6,8 @@ static const u8 utf8overhangmask[32] = { 0, 0, 0, 0, 0, 0, 0, 0 }; +#define SPLIT_LONG 4096L + static Range get_word_around_cell(Term *t, iv2 cell) { @@ -1102,207 +1104,6 @@ push_control(Term *t, s8 *line, u32 cp, Arena a) return result; } -enum escape_moves_cursor_result { - EMC_NORMAL_RETURN, - EMC_NEEDS_MORE_BYTES, - EMC_CURSOR_MOVED, - EMC_SWAPPED_SCREEN, -}; - -static enum escape_moves_cursor_result -validate_osc(Term *t, s8 *raw) -{ - enum escape_moves_cursor_result result = EMC_NORMAL_RETURN; - OSC osc; - if (parse_osc(raw, &osc) == -1) - return EMC_NEEDS_MORE_BYTES; - return result; -} - -static enum escape_moves_cursor_result -check_if_csi_moves_cursor(Term *t, s8 *raw) -{ - BEGIN_TIMED_BLOCK(); - enum escape_moves_cursor_result result = EMC_NORMAL_RETURN; - CSI csi = {0}; - if (parse_csi(raw, &csi) == -1) - return EMC_NEEDS_MORE_BYTES; - - i32 mode = t->mode & TM_ALTSCREEN; - switch (csi.mode) { - case 'A': result = EMC_CURSOR_MOVED; break; - case 'B': result = EMC_CURSOR_MOVED; break; - case 'C': result = EMC_CURSOR_MOVED; break; - case 'D': result = EMC_CURSOR_MOVED; break; - case 'E': result = EMC_CURSOR_MOVED; break; - case 'F': result = EMC_CURSOR_MOVED; break; - case 'G': result = EMC_CURSOR_MOVED; break; - case 'H': result = EMC_CURSOR_MOVED; break; - case 'Z': result = EMC_CURSOR_MOVED; break; - case 'a': result = EMC_CURSOR_MOVED; break; - case 'd': result = EMC_CURSOR_MOVED; break; - case 'e': result = EMC_CURSOR_MOVED; break; - case 'f': result = EMC_CURSOR_MOVED; break; - case 'h': set_mode(t, &csi, 1, 1); break; - case 'l': set_mode(t, &csi, 0, 1); break; - case 'm': set_colours(t, &csi); break; /* NOTE: start of line needs right style */ - default: break; - } - - if (mode != (t->mode & TM_ALTSCREEN)) - result = EMC_SWAPPED_SCREEN; - - END_TIMED_BLOCK(); - return result; -} - -static enum escape_moves_cursor_result -check_if_escape_moves_cursor(Term *t, s8 *raw) -{ - BEGIN_TIMED_BLOCK(); - - enum escape_moves_cursor_result result = EMC_NORMAL_RETURN; - if (raw->len < 2) { - result = EMC_NEEDS_MORE_BYTES; - goto end; - } - u32 cp = get_ascii(raw); - switch(cp) { - case '[': - result = check_if_csi_moves_cursor(t, raw); - break; - case ']': - result = validate_osc(t, raw); - break; - case '(': /* GZD4 -- set primary charset G0 */ - case ')': /* G1D4 -- set secondary charset G1 */ - case '*': /* G2D4 -- set tertiary charset G2 */ - case '+': /* G3D4 -- set quaternary charset G3 */ - case '%': /* utf-8 mode */ - get_ascii(raw); - break; - case 'c': /* RIS -- Reset to Initial State */ - result = EMC_CURSOR_MOVED; - break; - case 'D': /* IND -- Linefeed */ - case 'E': /* NEL -- Next Line */ - result = EMC_CURSOR_MOVED; - break; - case 'M': /* RI -- Reverse Index */ - result = EMC_CURSOR_MOVED; - break; - case '8': - result = EMC_CURSOR_MOVED; - break; - default: break; - } -end: - END_TIMED_BLOCK(); - return result; -} - -#define SPLIT_LONG 4096L -#if 0 -static size -split_raw_input_to_lines(Term *t, s8 raw) -{ - BEGIN_TIMED_BLOCK(); - - TermView *tv = t->views + t->view_idx; - size parsed_lines = 0; - __m128i nl = _mm_set1_epi8('\n'); - __m128i esc = _mm_set1_epi8(0x1B); - __m128i uni = _mm_set1_epi8(0x80); - - #define SPLIT_LONG 4096L - while (raw.len) { - __m128i hasutf8 = _mm_setzero_si128(); - size count = raw.len > SPLIT_LONG ? SPLIT_LONG : raw.len; - u8 *data = raw.data; - while (count >= 16) { - __m128i vdat = _mm_loadu_si128((__m128i_u *)data); - __m128i hasnl = _mm_cmpeq_epi8(vdat, nl); - __m128i hasesc = _mm_cmpeq_epi8(vdat, esc); - __m128i hasuni = _mm_and_si128(vdat, uni); - __m128i hasproc = _mm_or_si128(hasuni, _mm_or_si128(hasnl, hasesc)); - i32 needsproc = _mm_movemask_epi8(hasproc); - - if (needsproc) { - u32 advance = _tzcnt_u32(needsproc); - __m128i utf8mask = _mm_loadu_si128((__m128i_u *)(utf8overhangmask + 16 - advance)); - hasuni = _mm_and_si128(utf8mask, hasuni); - hasutf8 = _mm_or_si128(hasutf8, hasuni); - count -= advance; - data += advance; - break; - } - - hasutf8 = _mm_or_si128(hasutf8, hasuni); - count -= 16; - data += 16; - } - tv->lines.buf[tv->lines.widx].has_unicode |= _mm_movemask_epi8(hasutf8); - raw = consume(raw, data - raw.data); - - if (raw.len) { - u32 cp = peek(raw, 0); - if (cp == 0x1B) { - s8 old = raw; - raw = consume(raw, 1); - switch (check_if_escape_moves_cursor(t, &raw)) { - case EMC_NEEDS_MORE_BYTES: - t->unprocessed_bytes = old.len; - goto end; - case EMC_CURSOR_MOVED: - 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); - TermView *nv = t->views + t->view_idx; - size nstart = nv->log.widx; - mem_copy(raw, (s8){nv->log.cap, nv->log.buf + nstart}); - commit_to_rb(tv, -raw.len); - commit_to_rb(nv, raw.len); - raw.data = nv->log.buf + nstart; - init_line(nv->lines.buf + nv->lines.widx, raw.data, t->cursor.style); - tv = nv; - break; - default: break; - } - } else if (cp == '\n') { - raw = consume(raw, 1); - 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 */ - size old_len = raw.len; - if (get_utf8(&raw) == (u32)-1) { - /* NOTE: Need More Bytes! */ - t->unprocessed_bytes = old_len; - goto end; - } - } else { - raw = consume(raw, 1); - } - } - - 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); - } - } - t->unprocessed_bytes = 0; - -end: - END_TIMED_BLOCK(); - - return parsed_lines; -} -#endif - static void push_normal_cp(Term *t, TermView *tv, u32 cp) {