aether-code 0.43.1 → 0.43.3

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/src/menu.js CHANGED
@@ -1,83 +1,83 @@
1
- // Interactive multiple-choice menu — arrow/number selectable, cmd.exe-safe.
2
- //
3
- // Deliberately NOT Ink (which ghosts in the legacy Windows console). Uses a
4
- // simple manual redraw: print the list, and on each keypress move the cursor
5
- // back up to the top of the menu (ESC[nA) and clear-to-end (ESC[J), then
6
- // reprint. That's the same VT layer that already renders our ANSI colours, so
7
- // it works in cmd.exe, Windows Terminal, and POSIX terminals alike.
8
- //
9
- // Returns the chosen option object ({label, description}), or null if cancelled.
10
-
11
- import readline from "node:readline";
12
- import { c } from "./render.js";
13
-
14
- const ellip = (s, n) => (s && s.length > n ? s.slice(0, n - 1) + "…" : s || "");
15
-
16
- export function promptChoice({ question, options }) {
17
- const opts = (options || [])
18
- .map((o) => (typeof o === "string" ? { label: o } : o))
19
- .filter((o) => o && o.label);
20
-
21
- return new Promise((resolve) => {
22
- // Non-interactive (piped / CI): pick the first option so automation never
23
- // hangs waiting on a keypress that can't come. Print a note so it's visible.
24
- if (!process.stdin.isTTY || opts.length === 0) {
25
- const pick = opts[0] ?? null;
26
- if (pick) process.stdout.write(c.cyan("● ") + c.bold(question) + c.gray(` → ${pick.label} (auto)\n`));
27
- resolve(pick);
28
- return;
29
- }
30
-
31
- let sel = 0;
32
- const total = opts.length + 3; // question line + options + blank + hint line
33
-
34
- const draw = (first) => {
35
- if (!first) process.stdout.write(`\x1b[${total}A`); // cursor up to menu top
36
- process.stdout.write("\x1b[J"); // clear from cursor to end of screen
37
- process.stdout.write(c.cyan("● ") + c.bold(question) + "\n");
38
- opts.forEach((o, i) => {
39
- const active = i === sel;
40
- const pointer = active ? c.cyan("→") : " ";
41
- const num = active ? c.cyan(c.bold(`${i + 1}.`)) : c.gray(`${i + 1}.`);
42
- const label = active ? c.bold(o.label) : o.label;
43
- const desc = o.description ? c.gray(" " + ellip(o.description, 60)) : "";
44
- process.stdout.write(` ${pointer} ${num} ${label}${desc}\n`);
45
- });
46
- process.stdout.write("\n" + c.gray(" ↑/↓ move · 1-9 pick · Enter select · Esc cancel") + "\n");
47
- };
48
-
49
- const cleanup = () => {
50
- process.stdin.removeListener("keypress", onKey);
51
- if (process.stdin.isTTY) process.stdin.setRawMode(false);
52
- process.stdin.pause();
53
- };
54
-
55
- const finish = (result) => {
56
- cleanup();
57
- // Collapse the menu to a compact answer line so the transcript stays clean.
58
- process.stdout.write(`\x1b[${total}A\x1b[J`);
59
- process.stdout.write(c.cyan("● ") + c.bold(question) + "\n");
60
- if (result) process.stdout.write(" " + c.cyan("→") + " " + c.green(result.label) + "\n\n");
61
- else process.stdout.write(" " + c.gray("(cancelled — proceeding with best judgment)") + "\n\n");
62
- resolve(result);
63
- };
64
-
65
- const onKey = (str, key) => {
66
- if (!key) return;
67
- if (key.name === "up" || key.name === "k") { sel = (sel - 1 + opts.length) % opts.length; draw(false); }
68
- else if (key.name === "down" || key.name === "j" || key.name === "tab") { sel = (sel + 1) % opts.length; draw(false); }
69
- else if (str && /^[1-9]$/.test(str)) {
70
- const i = parseInt(str, 10) - 1;
71
- if (i < opts.length) finish(opts[i]);
72
- }
73
- else if (key.name === "return") finish(opts[sel]);
74
- else if (key.name === "escape" || (key.ctrl && key.name === "c")) finish(null);
75
- };
76
-
77
- readline.emitKeypressEvents(process.stdin);
78
- if (process.stdin.isTTY) process.stdin.setRawMode(true);
79
- process.stdin.resume();
80
- process.stdin.on("keypress", onKey);
81
- draw(true);
82
- });
83
- }
1
+ // Interactive multiple-choice menu — arrow/number selectable, cmd.exe-safe.
2
+ //
3
+ // Deliberately NOT Ink (which ghosts in the legacy Windows console). Uses a
4
+ // simple manual redraw: print the list, and on each keypress move the cursor
5
+ // back up to the top of the menu (ESC[nA) and clear-to-end (ESC[J), then
6
+ // reprint. That's the same VT layer that already renders our ANSI colours, so
7
+ // it works in cmd.exe, Windows Terminal, and POSIX terminals alike.
8
+ //
9
+ // Returns the chosen option object ({label, description}), or null if cancelled.
10
+
11
+ import readline from "node:readline";
12
+ import { c } from "./render.js";
13
+
14
+ const ellip = (s, n) => (s && s.length > n ? s.slice(0, n - 1) + "…" : s || "");
15
+
16
+ export function promptChoice({ question, options }) {
17
+ const opts = (options || [])
18
+ .map((o) => (typeof o === "string" ? { label: o } : o))
19
+ .filter((o) => o && o.label);
20
+
21
+ return new Promise((resolve) => {
22
+ // Non-interactive (piped / CI): pick the first option so automation never
23
+ // hangs waiting on a keypress that can't come. Print a note so it's visible.
24
+ if (!process.stdin.isTTY || opts.length === 0) {
25
+ const pick = opts[0] ?? null;
26
+ if (pick) process.stdout.write(c.cyan("● ") + c.bold(question) + c.gray(` → ${pick.label} (auto)\n`));
27
+ resolve(pick);
28
+ return;
29
+ }
30
+
31
+ let sel = 0;
32
+ const total = opts.length + 3; // question line + options + blank + hint line
33
+
34
+ const draw = (first) => {
35
+ if (!first) process.stdout.write(`\x1b[${total}A`); // cursor up to menu top
36
+ process.stdout.write("\x1b[J"); // clear from cursor to end of screen
37
+ process.stdout.write(c.cyan("● ") + c.bold(question) + "\n");
38
+ opts.forEach((o, i) => {
39
+ const active = i === sel;
40
+ const pointer = active ? c.cyan("→") : " ";
41
+ const num = active ? c.cyan(c.bold(`${i + 1}.`)) : c.gray(`${i + 1}.`);
42
+ const label = active ? c.bold(o.label) : o.label;
43
+ const desc = o.description ? c.gray(" " + ellip(o.description, 60)) : "";
44
+ process.stdout.write(` ${pointer} ${num} ${label}${desc}\n`);
45
+ });
46
+ process.stdout.write("\n" + c.gray(" ↑/↓ move · 1-9 pick · Enter select · Esc cancel") + "\n");
47
+ };
48
+
49
+ const cleanup = () => {
50
+ process.stdin.removeListener("keypress", onKey);
51
+ if (process.stdin.isTTY) process.stdin.setRawMode(false);
52
+ process.stdin.pause();
53
+ };
54
+
55
+ const finish = (result) => {
56
+ cleanup();
57
+ // Collapse the menu to a compact answer line so the transcript stays clean.
58
+ process.stdout.write(`\x1b[${total}A\x1b[J`);
59
+ process.stdout.write(c.cyan("● ") + c.bold(question) + "\n");
60
+ if (result) process.stdout.write(" " + c.cyan("→") + " " + c.green(result.label) + "\n\n");
61
+ else process.stdout.write(" " + c.gray("(cancelled — proceeding with best judgment)") + "\n\n");
62
+ resolve(result);
63
+ };
64
+
65
+ const onKey = (str, key) => {
66
+ if (!key) return;
67
+ if (key.name === "up" || key.name === "k") { sel = (sel - 1 + opts.length) % opts.length; draw(false); }
68
+ else if (key.name === "down" || key.name === "j" || key.name === "tab") { sel = (sel + 1) % opts.length; draw(false); }
69
+ else if (str && /^[1-9]$/.test(str)) {
70
+ const i = parseInt(str, 10) - 1;
71
+ if (i < opts.length) finish(opts[i]);
72
+ }
73
+ else if (key.name === "return") finish(opts[sel]);
74
+ else if (key.name === "escape" || (key.ctrl && key.name === "c")) finish(null);
75
+ };
76
+
77
+ readline.emitKeypressEvents(process.stdin);
78
+ if (process.stdin.isTTY) process.stdin.setRawMode(true);
79
+ process.stdin.resume();
80
+ process.stdin.on("keypress", onKey);
81
+ draw(true);
82
+ });
83
+ }