@autotask/atools-tool 0.1.10 → 0.1.11
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/lib/config-codex.mjs +19 -14
- package/package.json +1 -1
package/lib/config-codex.mjs
CHANGED
|
@@ -240,22 +240,31 @@ function canUseArrowMenu() {
|
|
|
240
240
|
function askChoiceArrow(question, options, defaultIndex = 0) {
|
|
241
241
|
return new Promise((resolve, reject) => {
|
|
242
242
|
let index = defaultIndex;
|
|
243
|
-
|
|
243
|
+
process.stdout.write("\n" + question + "\n");
|
|
244
|
+
let firstDraw = true;
|
|
244
245
|
const draw = () => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
if (!firstDraw) {
|
|
247
|
+
readline.moveCursor(process.stdout, 0, -options.length);
|
|
248
|
+
} else {
|
|
249
|
+
firstDraw = false;
|
|
250
|
+
}
|
|
251
|
+
for (let i = 0; i < options.length; i += 1) {
|
|
252
|
+
readline.clearLine(process.stdout, 0);
|
|
253
|
+
const prefix = i === index ? '> ' : ' ';
|
|
254
|
+
const label = String(i + 1) + ". " + String(options[i]);
|
|
255
|
+
let line = prefix + label;
|
|
256
|
+
if (i === index) {
|
|
257
|
+
line = withColor(line, ANSI.cyan, ANSI.bold) + ' (↑/↓, Enter; 数字直接跳转)';
|
|
258
|
+
}
|
|
259
|
+
process.stdout.write(line + "\n");
|
|
260
|
+
}
|
|
250
261
|
};
|
|
251
|
-
|
|
252
262
|
const cleanup = () => {
|
|
253
263
|
process.stdin.off('keypress', onKeyPress);
|
|
254
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode ===
|
|
264
|
+
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
255
265
|
process.stdin.setRawMode(false);
|
|
256
266
|
}
|
|
257
267
|
};
|
|
258
|
-
|
|
259
268
|
const onKeyPress = (str, key = {}) => {
|
|
260
269
|
if (key.ctrl && key.name === 'c') {
|
|
261
270
|
cleanup();
|
|
@@ -274,9 +283,7 @@ function askChoiceArrow(question, options, defaultIndex = 0) {
|
|
|
274
283
|
}
|
|
275
284
|
if (key.name === 'return' || key.name === 'enter') {
|
|
276
285
|
cleanup();
|
|
277
|
-
|
|
278
|
-
readline.cursorTo(process.stdout, 0);
|
|
279
|
-
process.stdout.write(`已选择: ${options[index]}\n`);
|
|
286
|
+
process.stdout.write("已选择: " + String(options[index]) + "\n");
|
|
280
287
|
resolve(options[index]);
|
|
281
288
|
return;
|
|
282
289
|
}
|
|
@@ -286,9 +293,7 @@ function askChoiceArrow(question, options, defaultIndex = 0) {
|
|
|
286
293
|
draw();
|
|
287
294
|
}
|
|
288
295
|
};
|
|
289
|
-
|
|
290
296
|
try {
|
|
291
|
-
process.stdout.write(`\n${question}\n`);
|
|
292
297
|
readline.emitKeypressEvents(process.stdin);
|
|
293
298
|
process.stdin.setRawMode(true);
|
|
294
299
|
process.stdin.resume();
|