Artifact 23a35f5af40f5ea02dd3a4cc55cdb944f225c31a82fdc9fbac32b05cfac5a8db:
- File
src/tui/markdown.h
— part of check-in
[e6887db767]
at
2026-11-19 22:44:19
on branch tui-parity-2
— TUI: closer to Pi, round 2
!cmd runs a command and adds its output to the next message; !!cmd runs it without. Editor: a kill ring (Ctrl+K, Ctrl+U, Ctrl+W, Alt+D into it; Ctrl+Y, Alt+Y out), undo (Ctrl+-), Ctrl+] to jump to a character, Ctrl+G to edit in $VISUAL or $EDITOR, Ctrl+Z to suspend. Markdown: tables, ordered and nested lists, quotes, italics, strikethrough, links (OSC 8 where the terminal draws them), code-fence labels; user messages on a background. Alt+Up restores queued messages. Startup shows Pi's key hints and the loaded context files, skills and prompt templates, and sets the terminal title. Double Esc opens /tree, Shift+Ctrl+P cycles models backwards, Ctrl+X copies the last reply. (user: dmestas, size: 1979) [annotate] [blame] [check-ins using] [more...]
/* Markdown as Pi's terminal UI draws it (markdown.c): headings, paragraphs * with `code`, bold, italic, strikethrough and links, bulleted, numbered and * nested lists, block quotes, fenced code with its language label, rules and * tables. Pure functions: text in, styled and wrapped lines out. */ #ifndef PIC_TUI_MARKDOWN_H #define PIC_TUI_MARKDOWN_H #include <stddef.h> #include "width.h" typedef struct { const char *base; /* SGR set again after every style change; NULL or "": none */ int links; /* link text is an OSC 8 hyperlink (and the url is not printed) */ int preserve; /* a user message: list markers and backslashes stay as typed */ } tui_md_opts; /* text[0..len) as lines of at most cols columns, appended to out. Blocks are * separated by one blank line; no trailing blank line. 0 or -1 (out of memory). */ int tui_markdown(const char *text, size_t len, size_t cols, const tui_md_opts *o, tui_lines *out); /* A streamed reply is flushed block by block: the bytes of the first block of * s that is finished (it ends in a blank line outside a code fence), blank * line included; 0 when the first block is still open. */ size_t tui_markdown_block_len(const char *s); /* One line of a block too long to wait for: inside a code fence (*fence) it is * code; a fence line opens or closes it; otherwise it is rendered as text. */ int tui_markdown_line(const char *line, size_t len, int *fence, size_t cols, const tui_md_opts *o, tui_lines *out); /* Pi's user message: the text rendered as markdown on the user-message * background, one column of padding on each side and a blank row above and * below, every row padded to cols. */ int tui_user_message_lines(const char *text, size_t cols, int links, tui_lines *out); /* Whether the terminal is known to handle OSC 8 hyperlinks (Pi's list: * kitty, ghostty, wezterm, iTerm2, Warp, VS Code, Alacritty...; not inside * tmux or screen). */ int tui_hyperlinks_supported(void); #endif