limina 0.0.6 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ //#region src/flow/render-model.ts
2
+ const ANSI_RESET = "\x1B[0m";
3
+ const ANSI_GREEN = "\x1B[32m";
4
+ const ANSI_RED = "\x1B[31m";
5
+ const ANSI_YELLOW = "\x1B[33m";
6
+ const SPINNER_FRAMES = [
7
+ "⠋",
8
+ "⠙",
9
+ "⠹",
10
+ "⠸",
11
+ "⠼",
12
+ "⠴",
13
+ "⠦",
14
+ "⠧",
15
+ "⠇",
16
+ "⠏"
17
+ ];
18
+ const SPINNER_INTERVAL_MS = 80;
19
+ const FLOW_SYMBOL_BY_STATUS = {
20
+ fail: "✕",
21
+ info: "│",
22
+ pass: "◆",
23
+ planned: "◇",
24
+ skip: "◇",
25
+ start: "◇",
26
+ warn: "▲"
27
+ };
28
+ function colorInteractiveSymbol(status, symbol) {
29
+ if (status === "pass") return `${ANSI_GREEN}${symbol}${ANSI_RESET}`;
30
+ if (status === "fail") return `${ANSI_RED}${symbol}${ANSI_RESET}`;
31
+ if (status === "warn") return `${ANSI_YELLOW}${symbol}${ANSI_RESET}`;
32
+ return symbol;
33
+ }
34
+ function formatElapsedTime(milliseconds) {
35
+ if (milliseconds < 1e3) return `${Math.round(milliseconds)}ms`;
36
+ return `${(milliseconds / 1e3).toFixed(2)}s`;
37
+ }
38
+ function formatMessageWithElapsed(message, elapsedTimeMs) {
39
+ return typeof elapsedTimeMs === "number" ? `${message} (${formatElapsedTime(elapsedTimeMs)})` : message;
40
+ }
41
+ function indentMessage(message, depth) {
42
+ if (depth <= 0) return message;
43
+ return `${" ".repeat(depth)}${message}`;
44
+ }
45
+ function formatInteractiveLine(status, message, depth, spinnerFrameIndex) {
46
+ const renderedMessage = indentMessage(message, depth);
47
+ return `${colorInteractiveSymbol(status, status === "start" ? SPINNER_FRAMES[spinnerFrameIndex % SPINNER_FRAMES.length] : FLOW_SYMBOL_BY_STATUS[status])} ${renderedMessage}`;
48
+ }
49
+ function toTreeFlowStatus(status) {
50
+ switch (status) {
51
+ case "failed": return "fail";
52
+ case "passed": return "pass";
53
+ case "planned": return "planned";
54
+ case "running": return "start";
55
+ case "skipped": return "skip";
56
+ }
57
+ throw new Error(`Unsupported flow tree node status: ${status}`);
58
+ }
59
+ function isTreeNodeTerminal(node) {
60
+ return node.status === "failed" || node.status === "passed" || node.status === "skipped";
61
+ }
62
+ function areTreeNodeDescendantsTerminal(node) {
63
+ return node.children.every((child) => isTreeNodeTerminal(child) && areTreeNodeDescendantsTerminal(child));
64
+ }
65
+ function renderTreeNodeLines(node, spinnerFrameIndex) {
66
+ const elapsedTimeMs = isTreeNodeTerminal(node) && areTreeNodeDescendantsTerminal(node) ? node.elapsedTimeMs : void 0;
67
+ return [formatInteractiveLine(toTreeFlowStatus(node.status), formatMessageWithElapsed(node.message, elapsedTimeMs), node.depth, spinnerFrameIndex), ...node.children.flatMap((child) => renderTreeNodeLines(child, spinnerFrameIndex))];
68
+ }
69
+ function renderSnapshotLines(snapshot, spinnerFrameIndex) {
70
+ const lines = snapshot.entries.flatMap((entry) => {
71
+ if (entry.kind === "line") return [entry.line];
72
+ if (entry.kind === "flow-line") return [formatInteractiveLine(entry.status, formatMessageWithElapsed(entry.message, entry.elapsedTimeMs), entry.depth, spinnerFrameIndex)];
73
+ return snapshot.treeRoots.flatMap((root) => renderTreeNodeLines(root, spinnerFrameIndex));
74
+ });
75
+ return snapshot.outroMessage ? [...lines, `└ ${snapshot.outroMessage}`] : lines;
76
+ }
77
+ function hasRunningSnapshotWork(snapshot) {
78
+ const hasRunningTreeNode = (node) => node.status === "running" || node.children.some(hasRunningTreeNode);
79
+ return snapshot.entries.some((entry) => entry.kind === "flow-line" && entry.status === "start") || snapshot.treeRoots.some(hasRunningTreeNode);
80
+ }
81
+ function toWritableText(chunk) {
82
+ if (chunk instanceof Uint8Array) return Buffer.from(chunk).toString();
83
+ return String(chunk);
84
+ }
85
+
86
+ //#endregion
87
+ export { hasRunningSnapshotWork as a, toWritableText as c, formatMessageWithElapsed as i, SPINNER_INTERVAL_MS as n, renderSnapshotLines as o, formatInteractiveLine as r, toTreeFlowStatus as s, SPINNER_FRAMES as t };