Artifact 5a240161fe67161f1049f2a2b15de2407eb26976acb605d7765971bcd59f05da:
- File
src/tui/view.h
— part of check-in
[e476149026]
at
2026-11-19 21:41:15
on branch tui-parity-1
— TUI: closer to Pi, round 1
Each tool call is a block with its state, the arguments that matter, the duration and collapsed output; an edit shows as a coloured diff; Ctrl+O expands every block still on screen. Thinking stays in the transcript (dim italic) and Ctrl+T hides or shows it, saved as hideThinking. Up/Down history is seeded from the conversation being continued. The footer shows the git branch, the conversation name, cache tokens, and context use in colour near the limit. Retries and replies cut at the length limit are reported as Pi does. Ctrl+L and Ctrl+P work while a reply runs. (user: dmestas, size: 3211) [annotate] [blame] [check-ins using] [more...]
/* What the transcript and footer look like (view.c): tool-call blocks, edit * diffs, durations, the footer lines, the retry status. Pure functions * (the git branch reads one file): no terminal, no events, no globals. */ #ifndef PIC_TUI_VIEW_H #define PIC_TUI_VIEW_H #include <stddef.h> #include "width.h" /* Pi's formatToolDuration: "4.2s", "1m 5s", "1h 2m 3s". */ void tui_fmt_duration(long ms, char *out, size_t cap); /* Pi's formatTokens: "999", "1.5k", "15k", "1.5M". */ void tui_fmt_tokens(long long n, char *out, size_t cap); /* "12B", "1.5KB", "2.0MB". */ void tui_fmt_size(size_t bytes, char *out, size_t cap); /* One replacement as unified-diff lines, malloc'd, "\n"-separated, each * starting with ' ' (context, up to 2 lines each side), '-' or '+'. The * common leading and trailing lines are trimmed, so interleaved changes * show as one removed block and one added block. "" when the texts are * equal; NULL when out of memory. */ char *tui_diff_text(const char *old_text, const char *new_text); enum { TUI_TOOL_PENDING, TUI_TOOL_OK, TUI_TOOL_ERROR }; typedef struct { const char *name; /* the tool */ const char *title; /* what it acts on: "$ ls -la", "t.txt:10-20" */ const char *diff; /* edit: tui_diff_text output, else NULL */ const char *output; /* the result text; NULL while pending */ int state; long ms; /* elapsed so far (pending) or how long it took; < 0: unknown */ } tui_tool; /* A tool call as a block of lines for cols columns, appended to out: a header * (state mark, title), the diff or output indented two columns and dimmed * (errors red), and "Took 4.2s" / "Elapsed 1.2s". Collapsed (expanded = 0) a * block shows the last 5 lines of bash output and the first 10 of other output * (24 of a diff), with "... (N more lines, ctrl+o to expand)". 0, or -1 (out * of memory). */ int tui_tool_lines(const tui_tool *t, int expanded, size_t cols, tui_lines *out); typedef struct { long long in, out, cache_read, cache_write, context; long window; /* context window in tokens; <= 0: unknown */ const char *model; const char *level; /* thinking level; NULL or "": the model has none */ int expanded; /* tool output is expanded */ } tui_footer; /* Footer line 1: "~/dir (branch) • name"; ws is shortened to ~ under home. */ void tui_footer_where(const char *ws, const char *home, const char *branch, const char *name, char *out, size_t cap); /* Footer line 2, dimmed and fitted to cols: "↑in ↓out Rcache Wcache pct%/window", * the percentage yellow past 70 and red past 90, the model right-aligned with * " • level" (" • thinking off" for "off"). */ void tui_footer_stats(const tui_footer *f, size_t cols, char *out, size_t cap); /* The branch of the git checkout at or above dir (a ".git" directory, or a * file pointing at one): its name, or "detached". 1 found, 0 none (out is "" then). */ int tui_git_branch(const char *dir, char *out, size_t cap); /* "Retrying (2/3) in 8s… (esc to cancel)"; the delay part only when delay_ms * is > 0, counted down by elapsed_ms. */ void tui_retry_status(int attempt, int max_attempts, long delay_ms, long elapsed_ms, char *out, size_t cap); #endif