limina 0.0.6 → 0.1.2

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,101 @@
1
+ import { a as SPINNER_FRAMES, l as hasRunningSnapshotWork, n as TerminalFrameTracker, o as SPINNER_INTERVAL_MS, t as DEFAULT_TERMINAL_COLUMNS, u as renderSnapshotLinesForTerminal } from "./chunks/dep-mnWOqiGN.js";
2
+
3
+ //#region src/flow/renderer-process.ts
4
+ let snapshot = {
5
+ entries: [],
6
+ treeRoots: []
7
+ };
8
+ const terminalFrame = new TerminalFrameTracker(getTerminalColumns);
9
+ const FLOW_RENDERER_TEST_COLUMNS_ENV = "LIMINA_FLOW_RENDERER_TEST_COLUMNS";
10
+ let spinnerFrameIndex = 0;
11
+ let spinnerTimer;
12
+ let closed = false;
13
+ function send(message) {
14
+ if (typeof process.send === "function") process.send(message);
15
+ }
16
+ function readPositiveInteger(value) {
17
+ if (value === void 0) return;
18
+ const parsed = Number.parseInt(value, 10);
19
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
20
+ }
21
+ function getTerminalColumns() {
22
+ return Math.max(1, readPositiveInteger(process.env[FLOW_RENDERER_TEST_COLUMNS_ENV]) ?? process.stdout.columns ?? snapshot.terminalDimensions?.columns ?? DEFAULT_TERMINAL_COLUMNS);
23
+ }
24
+ function getTerminalRows() {
25
+ return readPositiveInteger(process.env.LIMINA_FLOW_RENDERER_TEST_ROWS) ?? process.stdout.rows;
26
+ }
27
+ function writeTracked(message, stream) {
28
+ terminalFrame.record(message);
29
+ stream.write(message);
30
+ }
31
+ function clearRenderedFrame() {
32
+ if (terminalFrame.lineCount <= 0) return;
33
+ process.stdout.write(`\r\u001B[${terminalFrame.lineCount}A\u001B[J`);
34
+ terminalFrame.reset();
35
+ }
36
+ function render() {
37
+ clearRenderedFrame();
38
+ const dimensions = {
39
+ columns: getTerminalColumns(),
40
+ rows: snapshot.terminalDimensions?.rows ?? getTerminalRows()
41
+ };
42
+ const renderedLines = renderSnapshotLinesForTerminal(snapshot, spinnerFrameIndex, dimensions);
43
+ for (const line of renderedLines) writeTracked(`${line}\n`, process.stdout);
44
+ }
45
+ function syncSpinnerTimer() {
46
+ if (closed || !hasRunningSnapshotWork(snapshot)) {
47
+ if (spinnerTimer) {
48
+ clearInterval(spinnerTimer);
49
+ spinnerTimer = void 0;
50
+ }
51
+ return;
52
+ }
53
+ if (spinnerTimer) return;
54
+ spinnerTimer = setInterval(() => {
55
+ spinnerFrameIndex = (spinnerFrameIndex + 1) % SPINNER_FRAMES.length;
56
+ render();
57
+ }, SPINNER_INTERVAL_MS);
58
+ }
59
+ function writeOutput(message) {
60
+ clearRenderedFrame();
61
+ writeTracked(message.output.text, message.output.stream === "stderr" ? process.stderr : process.stdout);
62
+ terminalFrame.reset();
63
+ render();
64
+ }
65
+ process.on("message", (rawMessage) => {
66
+ try {
67
+ if (process.env.LIMINA_FLOW_RENDERER_TEST_CRASH === "1" && rawMessage.type === "snapshot") process.exit(1);
68
+ switch (rawMessage.type) {
69
+ case "snapshot":
70
+ snapshot = rawMessage.snapshot;
71
+ syncSpinnerTimer();
72
+ render();
73
+ break;
74
+ case "output":
75
+ writeOutput(rawMessage);
76
+ break;
77
+ case "close":
78
+ closed = true;
79
+ snapshot = rawMessage.snapshot;
80
+ if (spinnerTimer) {
81
+ clearInterval(spinnerTimer);
82
+ spinnerTimer = void 0;
83
+ }
84
+ render();
85
+ send({ type: "closed" });
86
+ setImmediate(() => {
87
+ process.exit(0);
88
+ });
89
+ break;
90
+ }
91
+ } catch (error) {
92
+ send({
93
+ message: error instanceof Error ? error.message : String(error),
94
+ type: "failed"
95
+ });
96
+ }
97
+ });
98
+ send({ type: "ready" });
99
+
100
+ //#endregion
101
+ export { };