7814
Ta
tiny-c-agent / files
tiny-c-agent / src / tui / stream.h
1.6 KB
1// tiny TUI stream renderers: assistant text and reasoning, projected onto lines. 2// 3// MarkdownStream holds a fenced code block until its close, and a run of prose 4// until its block ends, then colors the whole block. TailStream keeps only the 5// incomplete tail, dimmed. 6 7#ifndef TINY_TUI_STREAM_H 8#define TINY_TUI_STREAM_H 9 10#include <stddef.h> 11 12#include "theme.h" 13 14typedef struct { 15 char *text; // malloc'd, may carry SGR 16 tiny_fg_fn style; // NULL when unstyled 17 const char *bg; // row background, or NULL for Normal 18} tiny_body_line; 19 20// An owned, growable list of owned body lines. Free with bl_free. 21typedef struct { 22 tiny_body_line *v; 23 size_t n; 24 size_t cap; 25} tiny_blist; 26 27void bl_push(tiny_blist *l, char *text, tiny_fg_fn style, const char *bg); 28void bl_free(tiny_blist *l); 29 30typedef struct { 31 char *rest; 32 char *fence_marker; 33 char *fence_info; 34 tiny_strv fence_lines; 35 tiny_strv prose; 36} tiny_mdstream; 37 38void tiny_mdstream_init(tiny_mdstream *s); 39void tiny_mdstream_free(tiny_mdstream *s); 40// feed/pending/flush return a list the caller frees with bl_free. 41tiny_blist tiny_mdstream_feed(tiny_mdstream *s, const char *delta); 42tiny_blist tiny_mdstream_pending(tiny_mdstream *s); 43tiny_blist tiny_mdstream_flush(tiny_mdstream *s); 44void tiny_mdstream_reset(tiny_mdstream *s); 45 46typedef struct { 47 char *rest; 48} tiny_tailstream; 49 50void tiny_tailstream_init(tiny_tailstream *s); 51void tiny_tailstream_free(tiny_tailstream *s); 52tiny_blist tiny_tailstream_feed(tiny_tailstream *s, const char *delta); 53tiny_blist tiny_tailstream_pending(tiny_tailstream *s); 54void tiny_tailstream_reset(tiny_tailstream *s); 55 56#endif