@flux-lang/cli 0.1.2 → 0.1.4-canary.078fd1eea
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.
- package/README.md +43 -4
- package/dist/bin/flux.js +1214 -200
- package/dist/ui-routing.js +5 -0
- package/dist/version.js +1 -1
- package/dist/view/runViewer.js +115 -0
- package/package.json +9 -5
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// packages/cli/src/version.ts
|
|
2
|
-
export const FLUX_CLI_VERSION = "0.1.
|
|
2
|
+
export const FLUX_CLI_VERSION = "0.1.4";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
import { computeGridLayout, getDocstepIntervalHint } from "@flux-lang/core";
|
|
3
|
+
export async function runViewer(runtime, options) {
|
|
4
|
+
const materialLabels = options.materialLabels ?? new Map();
|
|
5
|
+
let snapshot = runtime.snapshot();
|
|
6
|
+
let autoplay = false;
|
|
7
|
+
let autoplayTimer = null;
|
|
8
|
+
const headerTitle = options.title ? `${options.title} (${options.docPath})` : options.docPath;
|
|
9
|
+
const render = (snap) => {
|
|
10
|
+
process.stdout.write("\x1b[2J\x1b[H");
|
|
11
|
+
console.log("Flux viewer");
|
|
12
|
+
console.log(headerTitle);
|
|
13
|
+
const hint = getDocstepIntervalHint(runtime.doc, runtime.state);
|
|
14
|
+
console.log(`Docstep ${snap.docstep}${hint.ms ? ` · timer hint ${hint.ms} ms` : ""}`);
|
|
15
|
+
console.log("Press [enter] to step, [space] to toggle autoplay, [q] to quit.");
|
|
16
|
+
console.log("");
|
|
17
|
+
const layout = computeGridLayout(runtime.doc, snap);
|
|
18
|
+
for (const grid of layout.grids) {
|
|
19
|
+
console.log(`grid ${grid.name} (${grid.rows} x ${grid.cols}), docstep ${layout.docstep}`);
|
|
20
|
+
const lines = Array.from({ length: grid.rows }, () => Array(grid.cols).fill("."));
|
|
21
|
+
for (const cell of grid.cells) {
|
|
22
|
+
const ch = formatCell(cell.content, cell.tags, materialLabels);
|
|
23
|
+
if (cell.row < grid.rows && cell.col < grid.cols) {
|
|
24
|
+
lines[cell.row][cell.col] = ch;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const row of lines) {
|
|
28
|
+
console.log(` ${row.join(" ")}`);
|
|
29
|
+
}
|
|
30
|
+
console.log("");
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const stopAutoplay = () => {
|
|
34
|
+
autoplay = false;
|
|
35
|
+
if (autoplayTimer) {
|
|
36
|
+
clearInterval(autoplayTimer);
|
|
37
|
+
autoplayTimer = null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const startAutoplay = () => {
|
|
41
|
+
if (autoplay)
|
|
42
|
+
return;
|
|
43
|
+
autoplay = true;
|
|
44
|
+
autoplayTimer = setInterval(() => {
|
|
45
|
+
snapshot = runtime.step();
|
|
46
|
+
render(snapshot);
|
|
47
|
+
}, 700);
|
|
48
|
+
};
|
|
49
|
+
render(snapshot);
|
|
50
|
+
readline.emitKeypressEvents(process.stdin);
|
|
51
|
+
const wasRaw = process.stdin.isTTY ? process.stdin.isRaw : false;
|
|
52
|
+
if (process.stdin.isTTY) {
|
|
53
|
+
process.stdin.setRawMode(true);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await new Promise((resolve) => {
|
|
57
|
+
const cleanup = () => {
|
|
58
|
+
process.stdin.off("keypress", onKeypress);
|
|
59
|
+
};
|
|
60
|
+
const onKeypress = (_, key) => {
|
|
61
|
+
if (key.name === "q" || (key.ctrl && key.name === "c")) {
|
|
62
|
+
stopAutoplay();
|
|
63
|
+
cleanup();
|
|
64
|
+
resolve();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (key.name === "r") {
|
|
68
|
+
stopAutoplay();
|
|
69
|
+
snapshot = runtime.reset();
|
|
70
|
+
render(snapshot);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (key.name === "space") {
|
|
74
|
+
if (autoplay) {
|
|
75
|
+
stopAutoplay();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
startAutoplay();
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (key.name === "return" || key.name === "enter" || key.sequence === "\n") {
|
|
83
|
+
if (!autoplay) {
|
|
84
|
+
snapshot = runtime.step();
|
|
85
|
+
render(snapshot);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
process.stdin.on("keypress", onKeypress);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
stopAutoplay();
|
|
94
|
+
process.stdin.removeAllListeners("keypress");
|
|
95
|
+
if (process.stdin.isTTY) {
|
|
96
|
+
process.stdin.setRawMode(Boolean(wasRaw));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function formatCell(content, tags, labels) {
|
|
101
|
+
const value = content ?? "";
|
|
102
|
+
const labelChar = labels.get(value)?.[0];
|
|
103
|
+
if (labelChar)
|
|
104
|
+
return labelChar.toUpperCase();
|
|
105
|
+
const tagSet = new Set(tags);
|
|
106
|
+
if (value === "seed" || tagSet.has("seed"))
|
|
107
|
+
return "S";
|
|
108
|
+
if (value === "pulse" || tagSet.has("pulse"))
|
|
109
|
+
return "P";
|
|
110
|
+
if (value === "noise" || tagSet.has("noise"))
|
|
111
|
+
return "N";
|
|
112
|
+
if (value)
|
|
113
|
+
return value.slice(0, 1).toUpperCase();
|
|
114
|
+
return ".";
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flux-lang/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4-canary.078fd1eea",
|
|
4
4
|
"description": "CLI tooling for the Flux score language",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sebastian Suarez-Solis",
|
|
@@ -14,20 +14,24 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
"LICENSE"
|
|
17
|
+
"README.md"
|
|
19
18
|
],
|
|
20
19
|
"scripts": {
|
|
20
|
+
"prebuild": "npm run build --workspace @flux-lang/cli-core && npm run build --workspace @flux-lang/cli-ui",
|
|
21
21
|
"build": "tsc -p tsconfig.json",
|
|
22
22
|
"dev": "tsc -p tsconfig.json --watch",
|
|
23
23
|
"lint": "eslint src --ext .ts",
|
|
24
|
-
"
|
|
24
|
+
"pretest": "npm run build --workspace @flux-lang/core",
|
|
25
|
+
"test": "npm run build && vitest",
|
|
25
26
|
"prepublishOnly": "npm run build && chmod +x dist/bin/flux.js"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@flux-lang/core": "0.1.
|
|
29
|
+
"@flux-lang/core": "0.1.4-canary.078fd1eea",
|
|
30
|
+
"@flux-lang/cli-core": "0.1.4-canary.078fd1eea",
|
|
31
|
+
"@flux-lang/cli-ui": "0.1.4-canary.078fd1eea"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
31
35
|
"execa": "^8.0.0",
|
|
32
36
|
"vitest": "^2.1.0",
|
|
33
37
|
"typescript": "^5.6.0"
|