From 04e883a310fd3914d6f4294a92b08b3fe9f55686 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 10:52:12 +0100 Subject: Send the terminal only the cells that changed The TUI rebuilt its grid from the app on every change and then sent all of it. It now keeps what the terminal shows and sends each run of changed cells after a cursor move (short unchanged gaps stay in a run, being cheaper than another move; a run that starts in the second half of a wide character starts at its first). A resize sends everything again. vega tui --paint WxH writes the bytes of each frame; the checks replay them with a small terminal emulator and compare with the dumped frame: 4,800 random frames at three sizes agree, and a change costs 139 bytes on average against 1,220 for a whole frame. The interactive check now reads the final screen from the replayed bytes. --- src/draw.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index cf4e227..bec3804 100644 --- a/src/draw.c +++ b/src/draw.c @@ -192,10 +192,13 @@ void vega_say(FILE *out, PureApp *app, const VegaScreen *screen, bool all) { bool vega_grid(VegaGrid *grid, unsigned width, unsigned height) { size_t count = (size_t)width * height; - VegaCell *cells = calloc(count ? count : 1, sizeof(*cells)); - if (!cells) return false; + VegaCell *cells = calloc(count ? count : 1, sizeof(*cells)), *shown = calloc(count ? count : 1, sizeof(*shown)); + if (!cells || !shown) { free(cells); free(shown); return false; } free(grid->cells); + free(grid->shown); grid->cells = cells; + grid->shown = shown; + grid->painted = false; grid->width = width; grid->height = height; return true; @@ -203,6 +206,7 @@ bool vega_grid(VegaGrid *grid, unsigned width, unsigned height) { void vega_grid_free(VegaGrid *grid) { free(grid->cells); + free(grid->shown); *grid = (VegaGrid){0}; } -- cgit v1.2.3