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/vega.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/vega.h') diff --git a/src/vega.h b/src/vega.h index 062639b..2d0a29f 100644 --- a/src/vega.h +++ b/src/vega.h @@ -66,7 +66,9 @@ void vega_print(FILE *, PureApp *, const VegaScreen *, bool color); void vega_say(FILE *, PureApp *, const VegaScreen *, bool all); /* TUI: a grid of cells, redrawn from the app on every change. first keeps each - * list's scroll between frames; the focused row stays visible. */ + * list's scroll between frames; the focused row stays visible. shown is what + * the terminal shows, so a paint sends only the cells that changed (all of + * them until the first paint after a resize). */ typedef struct { uint32_t ch, mark; /* a character and at most one combining mark; ch 0 continues a wide one */ uint8_t tone; @@ -74,7 +76,8 @@ typedef struct { } VegaCell; typedef struct { unsigned width, height; - VegaCell *cells; + VegaCell *cells, *shown; + bool painted; /* shown holds what the terminal shows */ size_t first[VEGA_PARTS]; int cursor_row, cursor_column; /* where the terminal cursor goes, or -1 */ } VegaGrid; -- cgit v1.2.3