From 72c3905e4d700f968bd129e2fd008b62c65db7ac Mon Sep 17 00:00:00 2001 From: r Date: Mon, 12 Oct 2026 11:41:11 -0400 Subject: [PATCH] docs: mention the optional standalone ruflo tui in the README, with a user-guide section and animated SVGs README gets a short optional pointer (npx ruflo tui, --plain) and one small animated SVG. docs/USERGUIDE.md gets a Terminal UI (optional) section: requirements, commands, keys, exit codes, what each page shows, the AI page's ask-first card and its Codex/OpenRouter rules, the honest limits and a pointer to the Orbital theme. Both SVGs are built from real frames of ruflo-tui 3.56.7 in a throwaway sample project; scripts/render-tui-svg.mjs rebuilds them (CSS animation only, no scripts or external references, prefers-reduced-motion shows the first frame). Co-Authored-By: RuFlo --- README.md | 4 + docs/USERGUIDE.md | 55 +++++++++ docs/assets/ruflo-tui-compact.svg | 1 + docs/assets/ruflo-tui-walkthrough.svg | 1 + scripts/render-tui-svg.mjs | 157 ++++++++++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 docs/assets/ruflo-tui-compact.svg create mode 100644 docs/assets/ruflo-tui-walkthrough.svg create mode 100644 scripts/render-tui-svg.mjs diff --git a/README.md b/README.md index 9130bb4eea..8c24ab442b 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ npx -y ruflo@latest mcp start MCP exposes Ruflo tools to your client. The console and mods above are Claude Code integrations; hook support depends on the client. + **Prefer a plain terminal? Optional.** The console also runs on its own, with no Claude Code: `npx ruflo tui` (add `--plain` to print one frame for scripts). It shows Overview, Cost, Swarm, Events and Missions, plus an optional AI page. [Terminal UI guide](docs/USERGUIDE.md#terminal-ui-optional) + +

Looping recording of the optional ruflo terminal UI cycling through Overview, Cost, Swarm, Events and Missions in a sample project

+ [Compare install paths](#quick-start) · [Open the console](#console-walkthrough) · [User guide](docs/USERGUIDE.md)
diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md index a703c35da9..92cd4138b0 100644 --- a/docs/USERGUIDE.md +++ b/docs/USERGUIDE.md @@ -578,6 +578,61 @@ Install Ruflo as a native Claude Code plugin -- adds skills, commands, agents, a After installing, new `/slash-commands` and agent types are available immediately. Run `/reload-plugins` if needed. +### Terminal UI (optional) + +The Claude Code console (`/ruflo`) stays the main way to use Ruflo. If you are not in Claude Code, `ruflo tui` shows the same pages in any terminal. It is optional: nothing else depends on it. + +

Looping recording of ruflo tui: Overview, Cost, Swarm, Events and Missions, then the Swarm page in a small 80 by 24 window. Sample project and sample agents only.

+ +*The recording is a real run in a throwaway sample project, so some pages say `n/a` or "none yet".* + +**Requirements:** Node.js 20 or later and `ruflo` 3.56.7 or later (`npx ruflo@latest tui`). Use `ruflo` or `@claude-flow/cli`: `npx claude-flow tui` does not ship the bundle and says so. + +```bash +npx ruflo tui # open it in this terminal +npx ruflo tui --view swarm # start on a page: overview | cost | swarm | events | missions | ai +npx ruflo tui --plain | head -40 # print one plain frame and exit 0 (scripts, CI) +``` + +Without a terminal and without `--plain`, `tui` prints a one-line hint and exits 2. + +| Key | Does | +|---|---| +| `1`–`6`, or `o` `c` `s` `e` `m` `a` | Go to a page (Overview, Cost, Swarm, Events, Missions, AI) | +| `Tab` / `Shift-Tab` | Next / previous page | +| `j` `k` or the arrow keys | Scroll | +| `r` | Read the files again | +| `q` or `Ctrl-C` | Quit | + +**What each page shows.** It reads Ruflo's own files and the CLI's output in the current project, and says `n/a` for anything it cannot measure. + +- **Overview:** setup steps, health findings and the subsystems. +- **Cost:** budget and spend across Claude Code and Codex. Missing cost reports are not counted as zero. +- **Swarm:** topology, agents and the hive-mind. +- **Events:** swarm, claim, memory and mod events. History is kept only when the `eventsPersist` option is on. +- **Missions:** the mission record, read-only. Missions are made from a goal in the Claude Code console. +- **AI (optional):** ask Codex or OpenRouter a question. This is the only page that can send anything, and it always asks first. + +**The AI page asks first.** Pressing Enter does not send. It shows a card with exactly what would go out, and only a `y` typed while the card is on screen sends it. `n` cancels, and an unanswered card expires after 60 seconds. This is a real card: + +```text +Ask first, #1: this goes to OpenRouter +POST https://openrouter.ai/api/v1/chat/completions Authorization: Bearer ‹from +$OPENROUTER_API_KEY› {"model":"openrouter/auto","messages":[{"role":"user","content":"Summarize +what my agents did today"}],"usage":{"include":true}} +The key is read from the named variable, sent in one header and never shown or stored. Metered by the provider. +y sends it · n cancels · it expires in 59 s +``` + +- **Keys on this page:** typing is text, so `Esc` hands the keys back to the page keys. `Ctrl-T` switches between Codex and OpenRouter, `Ctrl-S` stops a running answer, and `Ctrl-C` quits. +- **Codex** runs only as the pinned `0.162.0` release found under `~/.codex/packages/standalone/releases`, read-only. It never uses the `current` link or `PATH` (0.162.1 crashes). If that release is not installed the page says so. +- **OpenRouter** needs `OPENROUTER_API_KEY` in your environment. The key is named by its variable and never shown. Requests go only to `https://openrouter.ai` and to the HTTPS hosts you name with `--convo-targets` (or `RUFLO_TUI_CONVO_TARGETS`, syntax `endpoint:=||;...`), with no redirects. `--model` picks the model (default `openrouter/auto`), and `--max-spend-usd` stops sending once the provider-reported spend reaches the cap (default `0.5`). +- `--no-ai` turns the AI page off. + +**Limits.** Read-only except the AI page. Tested on Linux in tmux with Node 22; Windows, macOS and Node 20 are untested. Design and decisions: [ADR-489](../v3/docs/adr/ADR-489-ruflo-tui-standalone-console.md). + +**In Claude Code**, the same console has an optional Orbital look and a Theme Studio: run `/ruflo themes`. See the [console README](../plugins/ruflo-console/README.md#orbital-theme). +
🤖 OpenAI Codex CLI Support — Full Codex integration with self-learning diff --git a/docs/assets/ruflo-tui-compact.svg b/docs/assets/ruflo-tui-compact.svg new file mode 100644 index 0000000000..42d6d37eac --- /dev/null +++ b/docs/assets/ruflo-tui-compact.svg @@ -0,0 +1 @@ +ruflo tui: the console in your terminalA looping recording of the optional standalone ruflo terminal UI cycling through five read-only pages: Overview, Cost, Swarm, Events and Missions. Sample project and sample agents only.1Overview2Cost3Swarm4Events5Missions6AI🏠Overview—whatrufloisdoinghere:subsystems,mods,healthalertsandliveactivityStarthere:Setruflouphere2of3done✔1.Initialiseruflointhisprojectcreates.claude-flowandthemods▶2.Startthedaemonbackgroundworkers:map,audit,optimize,consolidate✔3.Startaswarmhierarchical,upto8agentsOptimizer6findings·1needattention·fixesaskfirstscope●Safe·readsandlightupkeep○Balanced·localcomputethatwritesruflo’sownstore⚠ruflohaslearnednothinghereyet·learning·patternsn/anopatternsintheneuralstore:routingandrecallstartfromnothing.Pretrainingreads…ℹnomodel-routerstateyet·learning·decisionsn/athemodelrouterhasmadenodecisionhere,sothereisnothingtotune:itfillsasagen…ℹasecondmemorystoreisnotinthecounts·memory·unread11rowsin.swarm/agentdb-memory.db(theMCPpath’sstore)areoutsidetheCLI’scountsan…ℹwherethetimegoeshasnotbeenmeasured·performance·bottlenecksn/afindthebottleneckbeforeoptimising:alocalmeasurementshowsit,andoptimiseapplies…ℹruflo-modsnotseated:noin-processroutingorbudgetladder·install·infohowtofixit:npxruflomodsinstallℹrunthefullhealthcheck·health·doctorn/adoctorchecksNode,git,config,thedaemon,memory,MCP,AIDefence,disk,helpersandmo…SubsystemsrufloCLIv3.56.7(npx-offline)projectruflostateinwork/my-appdaemonn/a—nodaemon-state.json1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only·1-28/521Overview2Cost3Swarm4Events5Missions6AI💰Cost—setabudget,seespendacrossClaudeCodeandCodex,andhowtocutitCostthissessionSetabudgetruflo-mods·asksfirstBudgetsetterunavailable:setcostBudgetUsdin/config→ruflo-mods;restart/reloadmaybene…nobudgetsetcontextn/abudgetn/a—ruflo-modsnotseatedWhereitgoesreportedUSD·sourcesarenotadditiveClaudeCoden/a·thissessionAIterminaln/a·reportedsubtotalthissession(0costreports)terminalturnscodex0·claude0·per-agentdollarsn/aruflomodelsn/aUSD·tokensn/a·0decisionshaiku0routes·spendn/a·tokensn/asonnet0routes·spendn/a·tokensn/aopus0routes·spendn/a·tokensn/ainherit0routes·spendn/a·tokensn/aRoutercountsarepersistedacrosssessions,notbills.Missingcostreportsarenotzero.model-stats:rufloCLI,0sagoheadroomn/aAcrossprovidersClaudeCode+Codex·locallogsledgern/a—ruflo-cost-trackerisnotinstalled1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only·1-28/441Overview2Cost3Swarm4Events5Missions6AI🐝Swarm—theswarmasruflowroteit:topology,agentsatwork,andthehive-mindvotesSwarmswarm-1791818984348-rdvqemtopologyhierarchical·specialized·running·3agents·max6·updated4magographneedsaterminal:3swarmmembers★leader·◉busy(adotrunstoitwhileitworks)·●idle·greystopped·awhiteflash=a…Agents3agentsondisk(everyswarm)·j/kpick·dopen·xactions▸●coderidletasks0·health100%·#scp6s1●testeridletasks0·health100%·#w2vk28●revieweridletasks0·health100%·#k3dpdsHive-mindnotinitialisedNohive-mindyet:queen-ledconsensusfortheswarm.1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only1Overview2Cost3Swarm4Events5Missions6AI📡Events—everyswarm,claim,memoryandmodeventasithappensEvents0of0·allkept·livekind●all0level●any○✖bad0○⚠warn0○✓ok0○ℹinfo0window○session○15min○1h○24h●allkeptallkept···············now·barsof1min,bykindlast15min···············Nothinghaschangedsincetheconsoleloaded,andnohistoryiskeptforthisprojectyet.Even…notkept:theeventsPersistoptionisoff·read0eventsfrom0kB1Overview2Cost3Swarm4Events5Missions6AI🎯Missions—themissionrecordruflowrote:state,tasksandevidenceasrecorded(read-only)MissionrecordnoobservationResearchdeep-researcherrecordsn/a—ruflo-goalsisnotinstalledNomissionrecordyet(ADR-406).MissionsaremadefromagoalintheClaudeCodeconsole;thi…npx ruflo tuiOverview: what ruflo is doing in this project1 / 5Cost: budget and spend. n/a means not measured here2 / 5Swarm: topology and agents at a glance3 / 5Events: swarm, memory and mod activity (quiet in a new project)4 / 5Missions: the mission record, read-only (none yet in this sample)5 / 5 diff --git a/docs/assets/ruflo-tui-walkthrough.svg b/docs/assets/ruflo-tui-walkthrough.svg new file mode 100644 index 0000000000..e20632d94c --- /dev/null +++ b/docs/assets/ruflo-tui-walkthrough.svg @@ -0,0 +1 @@ +ruflo tui walkthroughA looping walkthrough of the optional standalone ruflo terminal UI: the five read-only pages, then the same Swarm page in a small 80 by 24 window. Sample project and sample agents only.1Overview2Cost3Swarm4Events5Missions6AI🏠Overview—whatrufloisdoinghere:subsystems,mods,healthalertsandliveactivityStarthere:Setruflouphere2of3done✔1.Initialiseruflointhisprojectcreates.claude-flowandthemods▶2.Startthedaemonbackgroundworkers:map,audit,optimize,consolidate✔3.Startaswarmhierarchical,upto8agentsOptimizer6findings·1needattention·fixesaskfirstscope●Safe·readsandlightupkeep○Balanced·localcomputethatwritesruflo’sownstore⚠ruflohaslearnednothinghereyet·learning·patternsn/anopatternsintheneuralstore:routingandrecallstartfromnothing.Pretrainingreads…ℹnomodel-routerstateyet·learning·decisionsn/athemodelrouterhasmadenodecisionhere,sothereisnothingtotune:itfillsasagen…ℹasecondmemorystoreisnotinthecounts·memory·unread11rowsin.swarm/agentdb-memory.db(theMCPpath’sstore)areoutsidetheCLI’scountsan…ℹwherethetimegoeshasnotbeenmeasured·performance·bottlenecksn/afindthebottleneckbeforeoptimising:alocalmeasurementshowsit,andoptimiseapplies…ℹruflo-modsnotseated:noin-processroutingorbudgetladder·install·infohowtofixit:npxruflomodsinstallℹrunthefullhealthcheck·health·doctorn/adoctorchecksNode,git,config,thedaemon,memory,MCP,AIDefence,disk,helpersandmo…SubsystemsrufloCLIv3.56.7(npx-offline)projectruflostateinwork/my-appdaemonn/a—nodaemon-state.json1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only·1-28/521Overview2Cost3Swarm4Events5Missions6AI💰Cost—setabudget,seespendacrossClaudeCodeandCodex,andhowtocutitCostthissessionSetabudgetruflo-mods·asksfirstBudgetsetterunavailable:setcostBudgetUsdin/config→ruflo-mods;restart/reloadmaybene…nobudgetsetcontextn/abudgetn/a—ruflo-modsnotseatedWhereitgoesreportedUSD·sourcesarenotadditiveClaudeCoden/a·thissessionAIterminaln/a·reportedsubtotalthissession(0costreports)terminalturnscodex0·claude0·per-agentdollarsn/aruflomodelsn/aUSD·tokensn/a·0decisionshaiku0routes·spendn/a·tokensn/asonnet0routes·spendn/a·tokensn/aopus0routes·spendn/a·tokensn/ainherit0routes·spendn/a·tokensn/aRoutercountsarepersistedacrosssessions,notbills.Missingcostreportsarenotzero.model-stats:rufloCLI,0sagoheadroomn/aAcrossprovidersClaudeCode+Codex·locallogsledgern/a—ruflo-cost-trackerisnotinstalled1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only·1-28/441Overview2Cost3Swarm4Events5Missions6AI🐝Swarm—theswarmasruflowroteit:topology,agentsatwork,andthehive-mindvotesSwarmswarm-1791818984348-rdvqemtopologyhierarchical·specialized·running·3agents·max6·updated4magographneedsaterminal:3swarmmembers★leader·◉busy(adotrunstoitwhileitworks)·●idle·greystopped·awhiteflash=a…Agents3agentsondisk(everyswarm)·j/kpick·dopen·xactions▸●coderidletasks0·health100%·#scp6s1●testeridletasks0·health100%·#w2vk28●revieweridletasks0·health100%·#k3dpdsHive-mindnotinitialisedNohive-mindyet:queen-ledconsensusfortheswarm.1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-only1Overview2Cost3Swarm4Events5Missions6AI📡Events—everyswarm,claim,memoryandmodeventasithappensEvents0of0·allkept·livekind●all0level●any○✖bad0○⚠warn0○✓ok0○ℹinfo0window○session○15min○1h○24h●allkeptallkept···············now·barsof1min,bykindlast15min···············Nothinghaschangedsincetheconsoleloaded,andnohistoryiskeptforthisprojectyet.Even…notkept:theeventsPersistoptionisoff·read0eventsfrom0kB1Overview2Cost3Swarm4Events5Missions6AI🎯Missions—themissionrecordruflowrote:state,tasksandevidenceasrecorded(read-only)MissionrecordnoobservationResearchdeep-researcherrecordsn/a—ruflo-goalsisnotinstalledNomissionrecordyet(ADR-406).MissionsaremadefromagoalintheClaudeCodeconsole;thi…1Overview2Cost3Swarm4Events5Missions6AI🐝Swarm—theswarmasruflowroteit:topology,agentsatwork,andthehive-…Swarmswarm-1791818984348-rdvqemtopologyhierarchical·specialized·running·3agents·max6·…graphneedsaterminal:3swarmmembers★leader·◉busy(adotrunstoitwhileitworks)·●idle·greystopped…Agents3agentsondisk(everyswarm)·j/kpick·dopen·xactions▸●coderidletasks0·health100%·#scp6s1●testeridletasks0·health100%·#w2vk28●revieweridletasks0·health100%·#k3dpdsHive-mindnotinitialisedNohive-mindyet:queen-ledconsensusfortheswarm.1-6orocsemapage·tabnext·rrefresh·j/kscroll·qquit·read-onlynpx ruflo tui1 Overview: setup steps, health alerts and subsystems for this project1 / 62 Cost: set a budget and see spend. n/a means ruflo did not measure it2 / 63 Swarm: topology, agents and hive-mind, as ruflo wrote them3 / 64 Events: every swarm, claim, memory and mod event (quiet in a new project)4 / 65 Missions: the mission record, read-only (none yet in this sample)5 / 6Small window (80x24): the same Swarm page, tighter6 / 6 diff --git a/scripts/render-tui-svg.mjs b/scripts/render-tui-svg.mjs new file mode 100644 index 0000000000..87b9f669e1 --- /dev/null +++ b/scripts/render-tui-svg.mjs @@ -0,0 +1,157 @@ +#!/usr/bin/env node +/** + * Renders captured terminal frames (`tmux capture-pane -p -e`, ANSI text) as ONE animated, self-contained SVG: CSS keyframes + * only, no scripts, images, fonts or external references, and `prefers-reduced-motion` shows the first frame. Node only. + * + * node scripts/render-tui-svg.mjs spec.json + * + * spec.json: { "out": "docs/assets/x.svg", "title": "...", "desc": "...", "seconds": 2.5, "chrome": "npx ruflo tui", + * "frames": [{ "ansi": "frame.ans", "caption": "plain-language caption" }] } + * Frames may differ in size; the canvas fits the largest and each frame is centred. + */ +import { readFileSync, writeFileSync } from 'node:fs' +import { dirname, resolve } from 'node:path' + +const CW = 10, CH = 19, FONT = 'DejaVu Sans Mono, Menlo, Consolas, monospace' +const BG = '#0d1117', FG = '#c9d1d9' +const esc = s => s.replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]) + +/** xterm 256-colour palette. */ +function xterm(n) { + const base = ['#000000', '#cd3131', '#0dbc79', '#e5e510', '#2472c8', '#bc3fbc', '#11a8cd', '#e5e5e5', + '#666666', '#f14c4c', '#23d18b', '#f5f543', '#3b8eea', '#d670d6', '#29b8db', '#ffffff'] + if (n < 16) return base[n] + if (n >= 232) { const v = 8 + (n - 232) * 10; return `rgb(${v},${v},${v})` } + const i = n - 16, lv = k => (k === 0 ? 0 : 55 + k * 40) + return `rgb(${lv(Math.floor(i / 36))},${lv(Math.floor(i / 6) % 6)},${lv(i % 6)})` +} + +/** Terminal cell width: emoji and CJK take two cells, variation selectors none. */ +function width(cp) { + if (cp === 0xfe0f || cp === 0xfe0e || cp === 0x200d) return 0 + if ((cp >= 0x1f300 && cp <= 0x1faff) || (cp >= 0x2e80 && cp <= 0xa4cf) || (cp >= 0xff00 && cp <= 0xff60)) return 2 + return 1 +} + +/** One ANSI line to cells [{ ch, w, fg, bg, bold }] on a fixed-width grid. */ +function parseLine(line, cols) { + const cells = [] + let fg = null, bg = null, bold = false, dim = false, rev = false + const re = /\x1b\[([0-9;:]*)m|\x1b\[[0-9;?]*[A-Za-z]|([\s\S])/gu + let m + while ((m = re.exec(line))) { + if (m[2] === undefined) { + if (m[1] === undefined) continue + const p = m[1] === '' ? [0] : m[1].split(/[;:]/).map(Number) + for (let i = 0; i < p.length; i++) { + const c = p[i] + if (c === 0) { fg = bg = null; bold = dim = rev = false } + else if (c === 1) bold = true + else if (c === 2) dim = true + else if (c === 22) bold = dim = false + else if (c === 7) rev = true + else if (c === 27) rev = false + else if (c >= 30 && c <= 37) fg = xterm(c - 30) + else if (c >= 90 && c <= 97) fg = xterm(c - 90 + 8) + else if (c >= 40 && c <= 47) bg = xterm(c - 40) + else if (c >= 100 && c <= 107) bg = xterm(c - 100 + 8) + else if (c === 39) fg = null + else if (c === 49) bg = null + else if ((c === 38 || c === 48) && p[i + 1] === 5) { const v = xterm(p[i + 2]); if (c === 38) fg = v; else bg = v; i += 2 } + else if ((c === 38 || c === 48) && p[i + 1] === 2) { const v = `rgb(${p[i + 2]},${p[i + 3]},${p[i + 4]})`; if (c === 38) fg = v; else bg = v; i += 4 } + } + continue + } + const ch = m[2] + if (ch === '\n' || ch === '\r') continue + const w = width(ch.codePointAt(0)) + if (w === 0) continue + let f = fg ?? FG, b = bg + if (rev) { const t = f; f = b ?? BG; b = t } + if (dim) f = `color-mix(in srgb, ${f} 60%, ${BG})` + cells.push({ ch, w, fg: f, bg: b, bold }) + } + let x = 0 + for (const c of cells) { c.x = x; x += c.w } + while (x < cols) { cells.push({ ch: ' ', w: 1, fg: FG, bg: null, bold: false, x }); x++ } + return cells +} + +const LINES = { '─': 'M0 9.5H10', '│': 'M5 0V19', '╭': 'M5 19V12Q5 9.5 8 9.5H10', '╮': 'M5 19V12Q5 9.5 2 9.5H0', '╰': 'M5 0V7Q5 9.5 8 9.5H10', '╯': 'M5 0V7Q5 9.5 2 9.5H0' } +const rows = new Map() + +/** Deduplicated row definition shared by every frame (borders and headers repeat a lot). */ +function rowId(cells) { + const key = JSON.stringify(cells.map(c => [c.ch, c.fg, c.bg, c.bold])) + if (rows.has(key)) return rows.get(key) + const id = `r${rows.size}`, out = [] + for (let s = 0, e; s < cells.length; s = e) { + const color = cells[s].bg + for (e = s + 1; e < cells.length && cells[e].bg === color; e++); + if (color) out.push(``) + } + let run = null, hl = null + // Monospace runs use textLength so every font lands on the 10px grid without a per-glyph x list (keeps the file small). + const flush = () => { + if (run) out.push(`${esc(run.t)}`) + run = null + } + const flushHl = () => { if (hl) out.push(``); hl = null } + for (const c of cells) { + const x = c.x * CW + if (c.ch !== '─') flushHl() + if (c.ch === '█' || c.ch === '▀' || c.ch === '▄') { + flush() + out.push(``) + } else if (c.ch === '─') { + flush() + if (hl && hl.fg === c.fg && hl.x0 + hl.n * CW === x) hl.n++ + else { flushHl(); hl = { fg: c.fg, x0: x, n: 1 } } + } else if (LINES[c.ch]) { + flush() + out.push(``) + } else if (c.w === 2) { + flush() + out.push(`${esc(c.ch)}`) + } else if (c.ch === ' ') flush() + else if (run && run.fg === c.fg && run.bold === c.bold && run.x0 + run.n * CW === x) { run.t += c.ch; run.n++ } + else { flush(); run = { fg: c.fg, bold: c.bold, t: c.ch, x0: x, n: 1 } } + } + flush() + flushHl() + rows.set(key, id) + rows.set(`def:${id}`, `${out.join('')}`) + return id +} + +const specPath = resolve(process.argv[2] ?? '') +const spec = JSON.parse(readFileSync(specPath, 'utf8')) +const base = dirname(specPath) +const frames = spec.frames.map(f => { + const lines = readFileSync(resolve(base, f.ansi), 'utf8').replace(/\s+$/, '').split('\n') + const cols = Math.max(...lines.map(l => parseLine(l, 0).reduce((a, c) => a + c.w, 0)), 1) + return { caption: f.caption, grid: lines.map(l => parseLine(l, cols)), cols } +}) +const cols = Math.max(...frames.map(f => f.cols)), nrows = Math.max(...frames.map(f => f.grid.length)) +const PAD = 12, BAR = 30, CAP = 54 +const W = cols * CW + PAD * 2, H = BAR + nrows * CH + PAD + CAP +const secs = spec.seconds ?? 2.5, total = +(secs * frames.length).toFixed(3) +const groups = frames.map((f, n) => { + const dx = PAD + Math.floor(((cols - f.cols) * CW) / 2) + const uses = f.grid.map((cells, y) => ``).join('') + const cap = `${esc(f.caption)}${n + 1} / ${frames.length}` + return `${uses}${cap}` +}) +const css = `.t{font-family:${FONT};font-size:16px}.cap{font:600 18px system-ui,Segoe UI,Helvetica,Arial,sans-serif;fill:#e6edf3}.num{font:14px ${FONT};fill:#8b949e}` + + `.p{opacity:0;animation:show ${total}s infinite}${frames.map((_, n) => `.p${n}{animation-delay:${+(n * secs).toFixed(3)}s}`).join('')}` + + `@keyframes show{0%,${(100 / frames.length - 0.01).toFixed(3)}%{opacity:1}${(100 / frames.length).toFixed(3)}%,100%{opacity:0}}` + + `@media (prefers-reduced-motion:reduce){.p{animation:none}.p0{opacity:1}}` +const defs = [...rows.entries()].filter(([k]) => k.startsWith('def:')).map(([, v]) => v).join('') +const svg = `` + + `${esc(spec.title)}${esc(spec.desc)}${defs}` + + `` + + `` + + `${esc(spec.chrome ?? '')}` + + `${groups.join('')}\n` +writeFileSync(resolve(base, spec.out), svg) +console.log(`${spec.out}: ${(svg.length / 1024).toFixed(1)} KB, ${frames.length} frames, ${rows.size / 2} unique rows, ${W}x${H}`)