[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› allow cell fill for different initialization types

This forces a render of all cells on the very first frame, which is
perfectly acceptable.

Charles Lowell (Apr 10, 2026, 4:06 PM -0500) 0f964786 17c12cd4

+27 -12
+5 -4
src/cell.c
··· 2 2 3 3 #include "cell.h" 4 4 5 - void cells_clear(Cell *buf, int w, int h) { 5 + void cells_fill(Cell *buf, int w, int h, uint32_t ch, uint32_t fg, 6 + uint32_t bg) { 6 7 for (int i = 0; i < w * h; i++) { 7 - buf[i].ch = ' '; 8 - buf[i].fg = ATTR_DEFAULT; 9 - buf[i].bg = ATTR_DEFAULT; 8 + buf[i].ch = ch; 9 + buf[i].fg = fg; 10 + buf[i].bg = bg; 10 11 } 11 12 } 12 13
+1 -1
src/cell.h
··· 24 24 #define ATTR_MASK 0xFF000000 25 25 #define COLOR_MASK 0x00FFFFFF 26 26 27 - void cells_clear(Cell *buf, int w, int h); 27 + void cells_fill(Cell *buf, int w, int h, uint32_t ch, uint32_t fg, uint32_t bg); 28 28 int cell_cmp(Cell *a, Cell *b); 29 29 30 30 #endif
+21 -7
src/clayterm.c
··· 149 149 buf_char(&ct->out, ch); 150 150 } 151 151 152 - /* โ”€โ”€ Double-buffer diff (from termbox2 tb_present) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ */ 153 - 154 - static void present(struct Clayterm *ct) { 152 + /** 153 + * Diff back buffer against front buffer and emit only changed cells 154 + * using absolute CUP positioning (\x1b[row;colH). Unchanged cells are 155 + * skipped, making this efficient for subsequent frames where most of 156 + * the screen is static. Derived from termbox2 tb_present. 157 + */ 158 + static void present_cups(struct Clayterm *ct) { 155 159 ct->lastx = -1; 156 160 ct->lasty = -1; 157 161 ··· 191 195 } 192 196 } 193 197 198 + /** 199 + * Emit back buffer as newline-separated rows without CUP positioning. 200 + * Every cell is written (no diffing), and the front buffer is primed 201 + * so that a subsequent present() call can diff efficiently. This is 202 + * used for inline "region" rendering where the caller manages cursor 203 + * positioning externally and the output must work in pipes. 204 + */ 194 205 static void present_lines(struct Clayterm *ct) { 195 206 for (int y = 0; y < ct->h; y++) { 196 207 if (y > 0) ··· 416 427 .lasty = -1, 417 428 }; 418 429 419 - cells_clear(ct->front, w, h); 420 - cells_clear(ct->back, w, h); 430 + // initialize back buffer with spaces and default fg/bg 431 + cells_fill(ct->back, w, h, ' ', ATTR_DEFAULT, ATTR_DEFAULT); 432 + 433 + // initialize front buffer with zeros. Every cell will be 434 + cells_fill(ct->front, w, h, 0, 0, 0); 421 435 return ct; 422 436 } 423 437 ··· 551 565 ct->lastfg = ct->lastbg = 0xffffffff; 552 566 ct->lastx = ct->lasty = -1; 553 567 554 - cells_clear(ct->back, ct->w, ct->h); 568 + cells_fill(ct->back, ct->w, ct->h, ' ', ATTR_DEFAULT, ATTR_DEFAULT); 555 569 556 570 /* walk Clay render commands into back buffer */ 557 571 for (int32_t j = 0; j < cmds.length; j++) { ··· 590 604 if (mode == 1) { 591 605 present_lines(ct); 592 606 } else { 593 - present(ct); 607 + present_cups(ct); 594 608 } 595 609 } 596 610