app/tui/textExport.ts
zzmq.dev@gmail.com/zz / app / tui / textExport.ts
@ 5c562752
Download
Ladder Summary
- file The module provides plain‑text exporters for the TUI’s data views, generating full (unfiltered, untruncated) string representations that can be copied to the clipboard. It exports three functions – **laneListText** (formats a list of lane snapshots as tab‑separated rows), **liveLogText** (produces a log of flat events with a human‑readable description), and **ladderText** (renders ladder‑tree snapshots as an indented outline). Internal helpers like **describeEvent** and **flattenRungText** support the formatting but are not exported.
// Plain-text dumps of each view's full (unfiltered, untruncated) data,
// for the "y" copy-to-clipboard key in TabView -- separate from each
// component's own rendering so copying doesn't depend on whatever
// filter/scroll state that component's UI happens to be in right now.
import type { LaneSnapshot, FlatEvent } from "./types.js";
import type { LadderSnapshot } from "./useLadderTrees.js";
import type { ResolvedRung } from "../engine/ladderRender.js";
function describeEvent(e: FlatEvent): string {
if (e.entry.type === "ASK") return `ASK ${e.entry.kind} from ${e.entry.from}`;
if (e.entry.type === "ANSWER") return `ANSWER ${e.entry.action} (${e.entry.ask}) from ${e.entry.from}`;
return `NOTE ${e.entry.kind}: ${e.entry.text}`;
}
export function laneListText(snapshots: LaneSnapshot[]): string {
return snapshots.map(({ repo, lane }) => `${repo}\t${lane.id}\t${lane.status}\tcoord: ${lane.coordinators.join(", ")}`).join("\n");
}
export function liveLogText(events: FlatEvent[]): string {
return events.map((e) => `${e.repo}\t${e.laneId}\t${describeEvent(e)}`).join("\n");
}
function flattenRungText(repo: string, rung: ResolvedRung, depth: number, out: string[]): void {
out.push(`${" ".repeat(depth)}[${rung.kind}] ${rung.path} -- ${rung.summary}`);
for (const child of rung.children) flattenRungText(repo, child, depth + 1, out);
}
export function ladderText(snapshots: LadderSnapshot[]): string {
const out: string[] = [];
for (const { repo, tree } of snapshots) {
out.push(`# ${repo}`);
flattenRungText(repo, tree, 0, out);
}
return out.join("\n");
}