/* Inline drawing (render.c). The screen is the terminal's own scrollback: * finished output is committed once and left there; only a small live * area at the bottom (the reply being written, status, editor, footer) is * redrawn, and only from its first changed line. Every write is wrapped in * synchronized output (CSI ?2026h ... CSI ?2026l). */ #ifndef PIC_TUI_RENDER_H #define PIC_TUI_RENDER_H #include <stddef.h> typedef struct tui_render tui_render; /* Writes to fd (the terminal). The live area starts empty at the cursor. */ tui_render *tui_render_new(int fd); void tui_render_free(tui_render *r); /* Replaces the live area with lines[0..n) (each already fits in the width, * no newlines; may contain SGR) and puts the cursor at line crow, column * ccol of it (crow < 0: cursor hidden). Lines equal to the previous draw's * are not rewritten: the cursor moves up to the first line that differs, * clears to the end of the screen and writes from there. More lines than * the terminal has rows: only the last rows-1 are drawn. 0, or -1 on a * write error. */ int tui_render_draw(tui_render *r, const char *const *lines, size_t n, int crow, int ccol, int rows); /* Writes lines[0..n) permanently above the live area (they scroll into the * terminal's history and are never redrawn), then redraws the live area * as last drawn below them. */ int tui_render_commit(tui_render *r, const char *const *lines, size_t n); /* After a resize: the next draw rewrites the whole live area. The old live * area is cleared from its first row down (reflow may leave stray lines * above it in the history; they are not chased). */ void tui_render_invalidate(tui_render *r); /* Leaves the cursor on a fresh line below the live area, shown. */ int tui_render_finish(tui_render *r); #endif