vtgl

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

Commit: fa47b8d2a6a4a13ae11edec23f8fe8e193d20f99
Parent: 85b37299588331849b353f3194673995e2db5220
Author: Randy Palamar
Date:   Mon, 24 Jun 2024 20:43:33 -0600

set and store terminal size

Diffstat:
Mos_unix.c | 12++++++++++++
Mterminal.c | 7+++++++
Mutil.h | 1+
Mvtgl.c | 11+++++++++--
4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/os_unix.c b/os_unix.c @@ -240,3 +240,15 @@ os_child_put_char(os_child c, u32 cp) s8 text = {.len = 1, .data = &character}; os_child_put_s8(c, text); } + +static void +os_set_term_size(os_child c, uv2 size, i32 x, i32 y) +{ + struct winsize ws; + ws.ws_col = size.w; + ws.ws_row = size.h; + ws.ws_xpixel = x; + ws.ws_ypixel = y; + if (ioctl(c.fd, TIOCSWINSZ, &ws) < 0) + fputs("os_set_term_size\n", stderr); +} diff --git a/terminal.c b/terminal.c @@ -81,6 +81,13 @@ cursor_reset(Term *t) } static void +cursor_move_to(Term *t, i32 row, i32 col) +{ + t->cursor.row = CLAMP(row, 0, t->size.h - 1); + t->cursor.col = CLAMP(col, 0, t->size.w - 1); +} + +static void dump_csi(CSI *csi) { fputs("raw: ESC[", stderr); diff --git a/util.h b/util.h @@ -196,6 +196,7 @@ typedef struct { os_child child; + uv2 size; Cursor cursor; FT_Library ftlib; diff --git a/vtgl.c b/vtgl.c @@ -216,10 +216,12 @@ push_line(Term *t, Line *line, v2 start_pos) u32 cp = get_ascii(&l); switch (cp) { case 0x1B: handle_escape(t, &l); break; - case '\b': t->cursor.col--; break; /* TODO: make sure cursor is clamped */ case '\r': t->cursor.col = 0; break; case '\n': t->cursor.row++; break; case '\t': push_tab(t); break; + case '\b': + cursor_move_to(t, t->cursor.row, t->cursor.col - 1); + break; default: /* TODO properly make characters are printable */ CLAMP(cp, ' ', '~'); @@ -234,7 +236,7 @@ push_line(Term *t, Line *line, v2 start_pos) static void blit_lines(Term *t) { - size line_count = 16; + size line_count = t->size.h - 1; CLAMP(line_count, 0, t->log_lines.filled); v2 cs = get_cell_size(t); /* TODO: handle case where widx has wrapped around */ @@ -261,6 +263,11 @@ fb_callback(GLFWwindow *win, i32 w, i32 h) t->gl.window_size.w = w; t->gl.window_size.h = h; t->gl.flags |= NEEDS_RESIZE; + + v2 cs = get_cell_size(t); + t->size.w = (u32)(w / cs.w); + t->size.h = (u32)(h / cs.h); + os_set_term_size(t->child, t->size, w, h); } static void