mono-jsx-dom 0.1.3 → 0.1.4
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/bin/init.mjs +66 -3
- package/package.json +1 -1
package/bin/init.mjs
CHANGED
|
@@ -9,11 +9,73 @@ import { argv, exit, stdin, stdout } from "node:process";
|
|
|
9
9
|
import { access, mkdir } from "node:fs/promises";
|
|
10
10
|
import { createInterface } from "node:readline/promises";
|
|
11
11
|
async function input(prompt, placeholder = "") {
|
|
12
|
+
const hint = `\x1B[34m?\x1B[0m ${prompt}:`;
|
|
13
|
+
if (stdin.isTTY && stdout.isTTY) {
|
|
14
|
+
let text = "";
|
|
15
|
+
const render = () => {
|
|
16
|
+
stdout.write(`\r\x1B[2K${hint} `);
|
|
17
|
+
if (text) {
|
|
18
|
+
stdout.write(text);
|
|
19
|
+
} else if (placeholder) {
|
|
20
|
+
stdout.write(`\x1B[90m${placeholder}\x1B[0m`);
|
|
21
|
+
stdout.write(`\x1B[${placeholder.length}D`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
render();
|
|
25
|
+
const wasRaw = stdin.isRaw;
|
|
26
|
+
stdin.setRawMode(true);
|
|
27
|
+
stdin.resume();
|
|
28
|
+
try {
|
|
29
|
+
text = await new Promise((resolve) => {
|
|
30
|
+
const decoder = new TextDecoder("utf8");
|
|
31
|
+
const onData = (buf) => {
|
|
32
|
+
const chars = typeof buf === "string" ? buf : decoder.decode(buf);
|
|
33
|
+
switch (chars) {
|
|
34
|
+
case "":
|
|
35
|
+
stdout.write("\x1B[999C\n\x1B[90mcancelled\x1B[0m\n");
|
|
36
|
+
exit(130);
|
|
37
|
+
return;
|
|
38
|
+
case "\r":
|
|
39
|
+
case "\n":
|
|
40
|
+
stdin.off("data", onData);
|
|
41
|
+
resolve(text.trim() || placeholder);
|
|
42
|
+
return;
|
|
43
|
+
case "\x7F":
|
|
44
|
+
case "\b":
|
|
45
|
+
text = text.slice(0, -1);
|
|
46
|
+
render();
|
|
47
|
+
return;
|
|
48
|
+
case "":
|
|
49
|
+
text = "";
|
|
50
|
+
render();
|
|
51
|
+
return;
|
|
52
|
+
case " ":
|
|
53
|
+
if (!text && placeholder) {
|
|
54
|
+
text = placeholder;
|
|
55
|
+
render();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (chars.startsWith("\x1B")) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
text += chars;
|
|
63
|
+
render();
|
|
64
|
+
};
|
|
65
|
+
stdin.on("data", onData);
|
|
66
|
+
});
|
|
67
|
+
stdout.write(`\r\x1B[2K${hint} \x1B[32m${text}\x1B[0m
|
|
68
|
+
`);
|
|
69
|
+
return text;
|
|
70
|
+
} finally {
|
|
71
|
+
stdin.setRawMode(wasRaw ?? false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
12
74
|
const rl = createInterface({ input: stdin, output: stdout });
|
|
13
75
|
try {
|
|
14
|
-
const line = await rl.question(
|
|
76
|
+
const line = await rl.question(hint + (placeholder ? " \x1B[90m" + placeholder + "\x1B[0m" : ""));
|
|
15
77
|
if (stdout.isTTY) {
|
|
16
|
-
stdout.write(`\x1B[1A\r\x1B[34m?\x1B[0m ${prompt}
|
|
78
|
+
stdout.write(`\x1B[1A\r\x1B[34m?\x1B[0m ${prompt} \x1B[32m${line.trim()}\x1B[0m\x1B[K
|
|
17
79
|
`);
|
|
18
80
|
}
|
|
19
81
|
return line.trim() || placeholder;
|
|
@@ -33,6 +95,7 @@ async function confirm(prompt) {
|
|
|
33
95
|
const c = typeof buf === "string" ? buf.charCodeAt(0) : buf[0];
|
|
34
96
|
switch (c) {
|
|
35
97
|
case 3:
|
|
98
|
+
stdout.write("\x1B[999C\n\x1B[90mcancelled\x1B[0m\n");
|
|
36
99
|
exit(130);
|
|
37
100
|
break;
|
|
38
101
|
case 89:
|
|
@@ -158,7 +221,7 @@ export default {
|
|
|
158
221
|
`
|
|
159
222
|
};
|
|
160
223
|
async function run() {
|
|
161
|
-
const appName = argv2[3] ?? await input("Enter the name of the app
|
|
224
|
+
const appName = argv2[3] ?? await input("Enter the name of the app", "mono-app");
|
|
162
225
|
return init(appName);
|
|
163
226
|
}
|
|
164
227
|
async function init(appName) {
|