1/* @ajax/tui-render: ratatui's Terminal over crossterm's backend. Each frame is drawn into a fresh
2 * buffer; only the cells that differ from the previous frame are written, with ratatui's diff rules
3 * (cells under a wide character are skipped, a shrunk wide cell with a visible background
4 * repaints what it covered) and crossterm's escapes (cursor moves only when not contiguous,
5 * modifier diffs, truecolor). The size is followed: a resize clears and redraws everything. */
6#ifndef TUI_RENDER_H
7#define TUI_RENDER_H
89#include "tui/buffer.h"
1011#include <stdbool.h>
12#include <stddef.h>
1314typedef struct {
15 char *data;
16 size_t len, cap;
17} tui_out;
1819void tui_out_put(tui_out *o, const char *s, size_t n);
20void tui_out_free(tui_out *o);
2122/* The escapes that turn prev into next on a terminal showing prev (same area). */
23void tui_render_diff(const tui_buffer *prev, const tui_buffer *next, tui_out *out);
2425typedef struct {
26 tui_buffer buffers[2];
27 int current;
28 bool cleared; /* the next frame must repaint everything */
29} tui_terminal;
3031/* Sizes the buffers to the terminal (or width x height when the size can't be read). */
32void tui_terminal_init(tui_terminal *t, uint16_t width, uint16_t height);
33void tui_terminal_free(tui_terminal *t);
34/* Starts a frame: follows the terminal's size, and returns the empty buffer to draw into. */
35tui_buffer *tui_terminal_begin(tui_terminal *t);
36/* Ends it: writes the changes to stdout, hides the cursor, keeps this frame for the next diff. */
37void tui_terminal_end(tui_terminal *t);
3839#endif