fogact 1.2.3 → 1.2.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/config/upstream.example.json +1 -1
- package/lib/index.js +38 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -243,6 +243,41 @@ async function runInteractiveMenu() {
|
|
|
243
243
|
await runToolsMenu();
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
function waitForMenuReturn(message = "按回车返回菜单...") {
|
|
247
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
248
|
+
return Promise.resolve();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return new Promise((resolve) => {
|
|
252
|
+
const stdin = process.stdin;
|
|
253
|
+
const wasRaw = Boolean(stdin.isRaw);
|
|
254
|
+
let closed = false;
|
|
255
|
+
|
|
256
|
+
const cleanup = () => {
|
|
257
|
+
if (closed) return;
|
|
258
|
+
closed = true;
|
|
259
|
+
stdin.off("data", onData);
|
|
260
|
+
if (stdin.isTTY && stdin.isRaw !== wasRaw) stdin.setRawMode(wasRaw);
|
|
261
|
+
stdin.pause();
|
|
262
|
+
process.stdout.write("\n");
|
|
263
|
+
resolve();
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const onData = (data) => {
|
|
267
|
+
const value = String(data);
|
|
268
|
+
if (value.includes("\u0003") || value.includes("\u001b") || value.includes("\r") || value.includes("\n")) {
|
|
269
|
+
cleanup();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
process.stdout.write(` ${message}`);
|
|
274
|
+
stdin.setEncoding("utf8");
|
|
275
|
+
stdin.setRawMode(true);
|
|
276
|
+
stdin.resume();
|
|
277
|
+
stdin.on("data", onData);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
246
281
|
function selectMenuAction() {
|
|
247
282
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
248
283
|
printBanner();
|
|
@@ -335,9 +370,11 @@ async function runToolsMenu() {
|
|
|
335
370
|
break;
|
|
336
371
|
case "test":
|
|
337
372
|
await runTestCommand();
|
|
373
|
+
await waitForMenuReturn();
|
|
338
374
|
break;
|
|
339
375
|
case "restore":
|
|
340
376
|
await runRestoreCommand();
|
|
377
|
+
await waitForMenuReturn();
|
|
341
378
|
break;
|
|
342
379
|
default:
|
|
343
380
|
console.log("");
|
|
@@ -449,4 +486,5 @@ module.exports = {
|
|
|
449
486
|
runInteractiveMenu,
|
|
450
487
|
runToolsMenu,
|
|
451
488
|
runWebServer,
|
|
489
|
+
waitForMenuReturn,
|
|
452
490
|
};
|