@kiyeonjeon21/ncli 0.1.6 → 0.1.8
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/dist/commands/init.js +24 -21
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -13,7 +13,7 @@ function prompt(question, mask = false) {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
// Masked input
|
|
16
|
+
// Masked input — handles both typing and paste
|
|
17
17
|
return new Promise((resolve) => {
|
|
18
18
|
process.stderr.write(question);
|
|
19
19
|
const stdin = process.stdin;
|
|
@@ -23,27 +23,30 @@ function prompt(question, mask = false) {
|
|
|
23
23
|
stdin.resume();
|
|
24
24
|
stdin.setEncoding("utf-8");
|
|
25
25
|
let input = "";
|
|
26
|
-
const onData = (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
stdin.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
const onData = (data) => {
|
|
27
|
+
for (const ch of data) {
|
|
28
|
+
if (ch === "\r" || ch === "\n") {
|
|
29
|
+
stdin.removeListener("data", onData);
|
|
30
|
+
if (stdin.isTTY)
|
|
31
|
+
stdin.setRawMode(wasRaw ?? false);
|
|
32
|
+
stdin.pause();
|
|
33
|
+
process.stderr.write("\n");
|
|
34
|
+
resolve(input.trim());
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
else if (ch === "\x7f" || ch === "\b") {
|
|
38
|
+
if (input.length > 0) {
|
|
39
|
+
input = input.slice(0, -1);
|
|
40
|
+
process.stderr.write("\b \b");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (ch === "\x03") {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
input += ch;
|
|
48
|
+
process.stderr.write("*");
|
|
39
49
|
}
|
|
40
|
-
}
|
|
41
|
-
else if (ch === "\x03") {
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
input += ch;
|
|
46
|
-
process.stderr.write("*");
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
stdin.on("data", onData);
|