@topcli/prompts 2.1.0 → 2.3.0
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/LICENSE +13 -13
- package/README.md +274 -274
- package/dist/index.cjs +74 -75
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +44 -45
- package/package.json +50 -54
package/dist/index.cjs
CHANGED
|
@@ -41,35 +41,14 @@ module.exports = __toCommonJS(index_exports);
|
|
|
41
41
|
|
|
42
42
|
// src/prompts/question.ts
|
|
43
43
|
var import_node_os2 = require("os");
|
|
44
|
-
var
|
|
45
|
-
var import_wcwidth = __toESM(require("@topcli/wcwidth"), 1);
|
|
44
|
+
var import_node_util4 = require("util");
|
|
46
45
|
|
|
47
46
|
// src/prompts/abstract.ts
|
|
48
47
|
var import_node_os = require("os");
|
|
49
|
-
var import_node_readline = require("readline");
|
|
48
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
50
49
|
var import_node_stream = require("stream");
|
|
51
50
|
var import_node_events = __toESM(require("events"), 1);
|
|
52
|
-
|
|
53
|
-
// src/utils.ts
|
|
54
|
-
var import_node_process = __toESM(require("process"), 1);
|
|
55
|
-
var kAnsiRegex = ansiRegex();
|
|
56
|
-
function ansiRegex({ onlyFirst = false } = {}) {
|
|
57
|
-
const pattern = [
|
|
58
|
-
// eslint-disable-next-line @stylistic/max-len
|
|
59
|
-
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
60
|
-
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
|
|
61
|
-
].join("|");
|
|
62
|
-
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
63
|
-
}
|
|
64
|
-
function stripAnsi(string) {
|
|
65
|
-
return string.replace(kAnsiRegex, "");
|
|
66
|
-
}
|
|
67
|
-
function isUnicodeSupported() {
|
|
68
|
-
if (import_node_process.default.platform !== "win32") {
|
|
69
|
-
return import_node_process.default.env.TERM !== "linux";
|
|
70
|
-
}
|
|
71
|
-
return Boolean(import_node_process.default.env.WT_SESSION) || Boolean(import_node_process.default.env.TERMINUS_SUBLIME) || import_node_process.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process.default.env.TERM_PROGRAM === "vscode" || import_node_process.default.env.TERM === "xterm-256color" || import_node_process.default.env.TERM === "alacritty" || import_node_process.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
72
|
-
}
|
|
51
|
+
var import_node_util = require("util");
|
|
73
52
|
|
|
74
53
|
// src/prompt-agent.ts
|
|
75
54
|
var kPrivateInstancier = Symbol("instancier");
|
|
@@ -166,7 +145,7 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
|
|
|
166
145
|
if (this.stdout.isTTY) {
|
|
167
146
|
this.stdin.setRawMode(true);
|
|
168
147
|
}
|
|
169
|
-
this.rl =
|
|
148
|
+
this.rl = import_node_readline.default.createInterface({
|
|
170
149
|
input,
|
|
171
150
|
output: new import_node_stream.Writable({
|
|
172
151
|
write: (chunk, encoding, callback) => {
|
|
@@ -193,7 +172,7 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
|
|
|
193
172
|
}
|
|
194
173
|
}
|
|
195
174
|
write(data) {
|
|
196
|
-
const formattedData =
|
|
175
|
+
const formattedData = (0, import_node_util.stripVTControlCharacters)(data).replace(import_node_os.EOL, "");
|
|
197
176
|
if (formattedData) {
|
|
198
177
|
this.history.push(formattedData);
|
|
199
178
|
}
|
|
@@ -204,7 +183,7 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
|
|
|
204
183
|
if (!lastLine) {
|
|
205
184
|
return;
|
|
206
185
|
}
|
|
207
|
-
const lastLineRows = Math.ceil(
|
|
186
|
+
const lastLineRows = Math.ceil((0, import_node_util.stripVTControlCharacters)(lastLine).length / this.stdout.columns);
|
|
208
187
|
this.stdout.moveCursor(-this.stdout.columns, -lastLineRows);
|
|
209
188
|
this.stdout.clearScreenDown();
|
|
210
189
|
}
|
|
@@ -216,8 +195,31 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
|
|
|
216
195
|
}
|
|
217
196
|
};
|
|
218
197
|
|
|
198
|
+
// src/utils.ts
|
|
199
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
200
|
+
var import_node_util2 = require("util");
|
|
201
|
+
var kLenSegmenter = new Intl.Segmenter();
|
|
202
|
+
function isUnicodeSupported() {
|
|
203
|
+
if (import_node_process.default.platform !== "win32") {
|
|
204
|
+
return import_node_process.default.env.TERM !== "linux";
|
|
205
|
+
}
|
|
206
|
+
return Boolean(import_node_process.default.env.WT_SESSION) || Boolean(import_node_process.default.env.TERMINUS_SUBLIME) || import_node_process.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process.default.env.TERM_PROGRAM === "vscode" || import_node_process.default.env.TERM === "xterm-256color" || import_node_process.default.env.TERM === "alacritty" || import_node_process.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
207
|
+
}
|
|
208
|
+
function stringLength(string) {
|
|
209
|
+
if (string === "") {
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
let length = 0;
|
|
213
|
+
for (const _ of kLenSegmenter.segment(
|
|
214
|
+
(0, import_node_util2.stripVTControlCharacters)(string)
|
|
215
|
+
)) {
|
|
216
|
+
length++;
|
|
217
|
+
}
|
|
218
|
+
return length;
|
|
219
|
+
}
|
|
220
|
+
|
|
219
221
|
// src/constants.ts
|
|
220
|
-
var
|
|
222
|
+
var import_node_util3 = require("util");
|
|
221
223
|
var kMainSymbols = {
|
|
222
224
|
tick: "\u2714",
|
|
223
225
|
cross: "\u2716",
|
|
@@ -237,18 +239,18 @@ var kFallbackSymbols = {
|
|
|
237
239
|
inactive: "(-)"
|
|
238
240
|
};
|
|
239
241
|
var kSymbols = isUnicodeSupported() || process.env.CI ? kMainSymbols : kFallbackSymbols;
|
|
240
|
-
var kPointer = (0,
|
|
242
|
+
var kPointer = (0, import_node_util3.styleText)("gray", kSymbols.pointer);
|
|
241
243
|
var SYMBOLS = {
|
|
242
|
-
QuestionMark: (0,
|
|
243
|
-
Tick: (0,
|
|
244
|
-
Cross: (0,
|
|
244
|
+
QuestionMark: (0, import_node_util3.styleText)(["blue", "bold"], "?"),
|
|
245
|
+
Tick: (0, import_node_util3.styleText)(["green", "bold"], kSymbols.tick),
|
|
246
|
+
Cross: (0, import_node_util3.styleText)(["red", "bold"], kSymbols.cross),
|
|
245
247
|
Pointer: kPointer,
|
|
246
248
|
Previous: kSymbols.previous,
|
|
247
249
|
Next: kSymbols.next,
|
|
248
250
|
ShowCursor: "\x1B[?25h",
|
|
249
251
|
HideCursor: "\x1B[?25l",
|
|
250
|
-
Active: (0,
|
|
251
|
-
Inactive: (0,
|
|
252
|
+
Active: (0, import_node_util3.styleText)("cyan", kSymbols.active),
|
|
253
|
+
Inactive: (0, import_node_util3.styleText)("gray", kSymbols.inactive)
|
|
252
254
|
};
|
|
253
255
|
|
|
254
256
|
// src/validators.ts
|
|
@@ -315,20 +317,20 @@ var QuestionPrompt = class extends AbstractPrompt {
|
|
|
315
317
|
});
|
|
316
318
|
}
|
|
317
319
|
#getQuestionQuery() {
|
|
318
|
-
return `${(0,
|
|
320
|
+
return `${(0, import_node_util4.styleText)("bold", `${SYMBOLS.QuestionMark} ${this.message}${this.tip}`)} ${this.questionSuffixError}`;
|
|
319
321
|
}
|
|
320
322
|
#setQuestionSuffixError(error) {
|
|
321
|
-
const suffix = (0,
|
|
323
|
+
const suffix = (0, import_node_util4.styleText)("red", `[${error}] `);
|
|
322
324
|
this.questionSuffixError = suffix;
|
|
323
325
|
}
|
|
324
326
|
#writeAnswer() {
|
|
325
327
|
const prefix = this.answer ? SYMBOLS.Tick : SYMBOLS.Cross;
|
|
326
|
-
const answer = (0,
|
|
327
|
-
this.write(`${prefix} ${(0,
|
|
328
|
+
const answer = (0, import_node_util4.styleText)("yellow", this.#secure ? "CONFIDENTIAL" : this.answer ?? "");
|
|
329
|
+
this.write(`${prefix} ${(0, import_node_util4.styleText)("bold", this.message)} ${SYMBOLS.Pointer} ${answer}${import_node_os2.EOL}`);
|
|
328
330
|
}
|
|
329
331
|
#onQuestionAnswer() {
|
|
330
332
|
const questionLineCount = Math.ceil(
|
|
331
|
-
(
|
|
333
|
+
stringLength(this.#getQuestionQuery() + this.answer) / this.stdout.columns
|
|
332
334
|
);
|
|
333
335
|
this.stdout.moveCursor(-this.stdout.columns, -questionLineCount);
|
|
334
336
|
this.stdout.clearScreenDown();
|
|
@@ -376,8 +378,7 @@ var QuestionPrompt = class extends AbstractPrompt {
|
|
|
376
378
|
|
|
377
379
|
// src/prompts/confirm.ts
|
|
378
380
|
var import_node_os3 = require("os");
|
|
379
|
-
var
|
|
380
|
-
var import_wcwidth2 = __toESM(require("@topcli/wcwidth"), 1);
|
|
381
|
+
var import_node_util5 = require("util");
|
|
381
382
|
var kToggleKeys = /* @__PURE__ */ new Set([
|
|
382
383
|
"left",
|
|
383
384
|
"right",
|
|
@@ -407,8 +408,8 @@ var ConfirmPrompt = class extends AbstractPrompt {
|
|
|
407
408
|
this.selectedValue = initial;
|
|
408
409
|
}
|
|
409
410
|
#getHint() {
|
|
410
|
-
const Yes = (0,
|
|
411
|
-
const No = (0,
|
|
411
|
+
const Yes = (0, import_node_util5.styleText)(["cyan", "bold", "underline"], "Yes");
|
|
412
|
+
const No = (0, import_node_util5.styleText)(["cyan", "bold", "underline"], "No");
|
|
412
413
|
return this.selectedValue ? `${Yes}/No` : `Yes/${No}`;
|
|
413
414
|
}
|
|
414
415
|
#render() {
|
|
@@ -427,7 +428,7 @@ var ConfirmPrompt = class extends AbstractPrompt {
|
|
|
427
428
|
#onKeypress(resolve, _value, key) {
|
|
428
429
|
this.stdout.moveCursor(
|
|
429
430
|
-this.stdout.columns,
|
|
430
|
-
-Math.floor((
|
|
431
|
+
-Math.floor(stringLength(this.#getQuestionQuery()) / this.stdout.columns)
|
|
431
432
|
);
|
|
432
433
|
this.stdout.clearScreenDown();
|
|
433
434
|
if (key.name === "return") {
|
|
@@ -454,17 +455,17 @@ var ConfirmPrompt = class extends AbstractPrompt {
|
|
|
454
455
|
this.stdin.off("keypress", this.#boundKeyPressEvent);
|
|
455
456
|
}
|
|
456
457
|
#getQuestionQuery() {
|
|
457
|
-
const query = (0,
|
|
458
|
+
const query = (0, import_node_util5.styleText)("bold", `${SYMBOLS.QuestionMark} ${this.message}`);
|
|
458
459
|
return `${query} ${this.#getHint()}`;
|
|
459
460
|
}
|
|
460
461
|
#onQuestionAnswer() {
|
|
461
462
|
this.clearLastLine();
|
|
462
463
|
this.stdout.moveCursor(
|
|
463
464
|
-this.stdout.columns,
|
|
464
|
-
-Math.floor((
|
|
465
|
+
-Math.floor(stringLength(this.#getQuestionQuery()) / this.stdout.columns)
|
|
465
466
|
);
|
|
466
467
|
this.stdout.clearScreenDown();
|
|
467
|
-
this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${(0,
|
|
468
|
+
this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${(0, import_node_util5.styleText)("bold", this.message)}${import_node_os3.EOL}`);
|
|
468
469
|
}
|
|
469
470
|
async confirm() {
|
|
470
471
|
if (this.skip) {
|
|
@@ -500,8 +501,7 @@ var ConfirmPrompt = class extends AbstractPrompt {
|
|
|
500
501
|
|
|
501
502
|
// src/prompts/select.ts
|
|
502
503
|
var import_node_os4 = require("os");
|
|
503
|
-
var
|
|
504
|
-
var import_wcwidth3 = __toESM(require("@topcli/wcwidth"), 1);
|
|
504
|
+
var import_node_util6 = require("util");
|
|
505
505
|
var kRequiredChoiceProperties = ["label", "value"];
|
|
506
506
|
var SelectPrompt = class extends AbstractPrompt {
|
|
507
507
|
#boundExitEvent = () => void 0;
|
|
@@ -608,14 +608,14 @@ var SelectPrompt = class extends AbstractPrompt {
|
|
|
608
608
|
);
|
|
609
609
|
const formattedDescription = choice.description ? ` - ${choice.description}` : "";
|
|
610
610
|
const styles = isChoiceSelected ? ["white", "bold"] : ["gray"];
|
|
611
|
-
const str = `${prefix}${(0,
|
|
611
|
+
const str = `${prefix}${(0, import_node_util6.styleText)(styles, `${formattedLabel}${formattedDescription}`)}${import_node_os4.EOL}`;
|
|
612
612
|
this.write(str);
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
|
-
#showAnsweredQuestion(
|
|
616
|
-
const symbolPrefix =
|
|
617
|
-
const prefix = `${symbolPrefix} ${(0,
|
|
618
|
-
const formattedChoice = (0,
|
|
615
|
+
#showAnsweredQuestion(label) {
|
|
616
|
+
const symbolPrefix = label === "" ? SYMBOLS.Cross : SYMBOLS.Tick;
|
|
617
|
+
const prefix = `${symbolPrefix} ${(0, import_node_util6.styleText)("bold", this.message)} ${SYMBOLS.Pointer}`;
|
|
618
|
+
const formattedChoice = (0, import_node_util6.styleText)("yellow", label);
|
|
619
619
|
this.write(`${prefix} ${formattedChoice}${import_node_os4.EOL}`);
|
|
620
620
|
}
|
|
621
621
|
#onProcessExit() {
|
|
@@ -697,7 +697,7 @@ var SelectPrompt = class extends AbstractPrompt {
|
|
|
697
697
|
}
|
|
698
698
|
if (this.options.autocomplete) {
|
|
699
699
|
let linesToClear2 = Math.ceil(
|
|
700
|
-
(
|
|
700
|
+
stringLength(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
|
|
701
701
|
);
|
|
702
702
|
while (linesToClear2 > 0) {
|
|
703
703
|
this.clearLastLine();
|
|
@@ -707,14 +707,14 @@ var SelectPrompt = class extends AbstractPrompt {
|
|
|
707
707
|
}
|
|
708
708
|
if (clearRender) {
|
|
709
709
|
const questionLineCount = Math.ceil(
|
|
710
|
-
(
|
|
710
|
+
stringLength(this.questionMessage) / this.stdout.columns
|
|
711
711
|
);
|
|
712
712
|
this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
|
|
713
713
|
this.stdout.clearScreenDown();
|
|
714
714
|
return;
|
|
715
715
|
}
|
|
716
716
|
if (error) {
|
|
717
|
-
const linesToClear = Math.ceil((
|
|
717
|
+
const linesToClear = Math.ceil(stringLength(this.questionMessage) / this.stdout.columns) + 1;
|
|
718
718
|
this.stdout.moveCursor(0, -linesToClear);
|
|
719
719
|
this.stdout.clearScreenDown();
|
|
720
720
|
this.#showQuestion(error);
|
|
@@ -731,17 +731,16 @@ var SelectPrompt = class extends AbstractPrompt {
|
|
|
731
731
|
#showQuestion(error = null) {
|
|
732
732
|
let hint = "";
|
|
733
733
|
if (error) {
|
|
734
|
-
hint = ` ${hint.length > 0 ? " " : ""}${(0,
|
|
734
|
+
hint = ` ${hint.length > 0 ? " " : ""}${(0, import_node_util6.styleText)(["red", "bold"], `[${error}]`)}`;
|
|
735
735
|
}
|
|
736
|
-
this.questionMessage = `${SYMBOLS.QuestionMark} ${(0,
|
|
736
|
+
this.questionMessage = `${SYMBOLS.QuestionMark} ${(0, import_node_util6.styleText)("bold", this.message)}${hint}`;
|
|
737
737
|
this.write(`${this.questionMessage}${import_node_os4.EOL}`);
|
|
738
738
|
}
|
|
739
739
|
};
|
|
740
740
|
|
|
741
741
|
// src/prompts/multiselect.ts
|
|
742
742
|
var import_node_os5 = require("os");
|
|
743
|
-
var
|
|
744
|
-
var import_wcwidth4 = __toESM(require("@topcli/wcwidth"), 1);
|
|
743
|
+
var import_node_util7 = require("util");
|
|
745
744
|
var kRequiredChoiceProperties2 = ["label", "value"];
|
|
746
745
|
var MultiselectPrompt = class extends AbstractPrompt {
|
|
747
746
|
#boundExitEvent = () => void 0;
|
|
@@ -867,14 +866,14 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
867
866
|
);
|
|
868
867
|
const formattedDescription = choice.description ? ` - ${choice.description}` : "";
|
|
869
868
|
const styles = isChoiceActive ? ["white", "bold"] : ["gray"];
|
|
870
|
-
const str = `${prefix} ${(0,
|
|
869
|
+
const str = `${prefix} ${(0, import_node_util7.styleText)(styles, `${formattedLabel}${formattedDescription}`)}${import_node_os5.EOL}`;
|
|
871
870
|
this.write(str);
|
|
872
871
|
}
|
|
873
872
|
}
|
|
874
873
|
#showAnsweredQuestion(choices, isAgentAnswer = false) {
|
|
875
874
|
const prefixSymbol = this.selectedIndexes.size === 0 && !isAgentAnswer ? SYMBOLS.Cross : SYMBOLS.Tick;
|
|
876
|
-
const prefix = `${prefixSymbol} ${(0,
|
|
877
|
-
const formattedChoice = (0,
|
|
875
|
+
const prefix = `${prefixSymbol} ${(0, import_node_util7.styleText)("bold", this.message)} ${SYMBOLS.Pointer}`;
|
|
876
|
+
const formattedChoice = (0, import_node_util7.styleText)("yellow", choices);
|
|
878
877
|
this.write(`${prefix}${choices ? ` ${formattedChoice}` : ""}${import_node_os5.EOL}`);
|
|
879
878
|
}
|
|
880
879
|
#selectedChoices() {
|
|
@@ -982,7 +981,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
982
981
|
}
|
|
983
982
|
if (this.options.autocomplete) {
|
|
984
983
|
let linesToClear2 = Math.ceil(
|
|
985
|
-
(
|
|
984
|
+
stringLength(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
|
|
986
985
|
);
|
|
987
986
|
while (linesToClear2 > 0) {
|
|
988
987
|
this.clearLastLine();
|
|
@@ -992,14 +991,14 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
992
991
|
}
|
|
993
992
|
if (clearRender) {
|
|
994
993
|
const questionLineCount = Math.ceil(
|
|
995
|
-
(
|
|
994
|
+
stringLength(this.questionMessage) / this.stdout.columns
|
|
996
995
|
);
|
|
997
996
|
this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
|
|
998
997
|
this.stdout.clearScreenDown();
|
|
999
998
|
return;
|
|
1000
999
|
}
|
|
1001
1000
|
if (error) {
|
|
1002
|
-
const linesToClear = Math.ceil((
|
|
1001
|
+
const linesToClear = Math.ceil(stringLength(this.questionMessage) / this.stdout.columns) + 1;
|
|
1003
1002
|
this.stdout.moveCursor(0, -linesToClear);
|
|
1004
1003
|
this.stdout.clearScreenDown();
|
|
1005
1004
|
this.#showQuestion(error);
|
|
@@ -1014,32 +1013,32 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
1014
1013
|
});
|
|
1015
1014
|
}
|
|
1016
1015
|
#showQuestion(error = null) {
|
|
1017
|
-
let hint = this.#showHint ? (0,
|
|
1016
|
+
let hint = this.#showHint ? (0, import_node_util7.styleText)(
|
|
1018
1017
|
"gray",
|
|
1019
1018
|
// eslint-disable-next-line @stylistic/max-len
|
|
1020
|
-
`(Press ${(0,
|
|
1019
|
+
`(Press ${(0, import_node_util7.styleText)("bold", "<Ctrl+A>")} to toggle all, ${(0, import_node_util7.styleText)("bold", "<Left/Right>")} to toggle, ${(0, import_node_util7.styleText)("bold", "<Return>")} to submit)`
|
|
1021
1020
|
) : "";
|
|
1022
1021
|
if (error) {
|
|
1023
|
-
hint += `${hint.length > 0 ? " " : ""}${(0,
|
|
1022
|
+
hint += `${hint.length > 0 ? " " : ""}${(0, import_node_util7.styleText)(["red", "bold"], `[${error}]`)}`;
|
|
1024
1023
|
}
|
|
1025
|
-
this.questionMessage = `${SYMBOLS.QuestionMark} ${(0,
|
|
1024
|
+
this.questionMessage = `${SYMBOLS.QuestionMark} ${(0, import_node_util7.styleText)("bold", this.message)}${hint.length > 0 ? ` ${hint}` : ""}`;
|
|
1026
1025
|
this.write(`${this.questionMessage}${import_node_os5.EOL}`);
|
|
1027
1026
|
}
|
|
1028
1027
|
};
|
|
1029
1028
|
|
|
1030
1029
|
// index.ts
|
|
1031
|
-
|
|
1030
|
+
function question(message, options = {}) {
|
|
1032
1031
|
return new QuestionPrompt({ ...options, message }).question();
|
|
1033
1032
|
}
|
|
1034
|
-
|
|
1033
|
+
function select(message, options) {
|
|
1035
1034
|
const selectPrompt = new SelectPrompt({ ...options, message });
|
|
1036
1035
|
return selectPrompt.select();
|
|
1037
1036
|
}
|
|
1038
|
-
|
|
1037
|
+
function confirm(message, options = {}) {
|
|
1039
1038
|
const confirmPrompt = new ConfirmPrompt({ ...options, message });
|
|
1040
1039
|
return confirmPrompt.confirm();
|
|
1041
1040
|
}
|
|
1042
|
-
|
|
1041
|
+
function multiselect(message, options) {
|
|
1043
1042
|
const multiselectPrompt = new MultiselectPrompt({ ...options, message });
|
|
1044
1043
|
return multiselectPrompt.multiselect();
|
|
1045
1044
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -69,28 +69,28 @@ interface ConfirmOptions extends AbstractPromptOptions {
|
|
|
69
69
|
initial?: boolean;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
interface MultiselectOptions extends AbstractPromptOptions {
|
|
73
|
-
choices: (Choice |
|
|
72
|
+
interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
|
|
73
|
+
choices: (Choice<T> | T)[];
|
|
74
74
|
maxVisible?: number;
|
|
75
|
-
preSelectedChoices?: (Choice |
|
|
76
|
-
validators?: PromptValidator[];
|
|
75
|
+
preSelectedChoices?: (Choice | T)[];
|
|
76
|
+
validators?: PromptValidator<T[]>[];
|
|
77
77
|
autocomplete?: boolean;
|
|
78
78
|
caseSensitive?: boolean;
|
|
79
79
|
showHint?: boolean;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
interface SelectOptions extends AbstractPromptOptions {
|
|
83
|
-
choices: (Choice |
|
|
82
|
+
interface SelectOptions<T extends string> extends AbstractPromptOptions {
|
|
83
|
+
choices: (Choice<T> | T)[];
|
|
84
84
|
maxVisible?: number;
|
|
85
|
-
ignoreValues?: (
|
|
86
|
-
validators?: PromptValidator[];
|
|
85
|
+
ignoreValues?: (T | number | boolean)[];
|
|
86
|
+
validators?: PromptValidator<T>[];
|
|
87
87
|
autocomplete?: boolean;
|
|
88
88
|
caseSensitive?: boolean;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
|
|
92
|
-
declare function select(message: string, options: Omit<SelectOptions
|
|
92
|
+
declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
|
|
93
93
|
declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
|
|
94
|
-
declare function multiselect(message: string, options: Omit<MultiselectOptions
|
|
94
|
+
declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
|
|
95
95
|
|
|
96
96
|
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
|
package/dist/index.d.ts
CHANGED
|
@@ -69,28 +69,28 @@ interface ConfirmOptions extends AbstractPromptOptions {
|
|
|
69
69
|
initial?: boolean;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
interface MultiselectOptions extends AbstractPromptOptions {
|
|
73
|
-
choices: (Choice |
|
|
72
|
+
interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
|
|
73
|
+
choices: (Choice<T> | T)[];
|
|
74
74
|
maxVisible?: number;
|
|
75
|
-
preSelectedChoices?: (Choice |
|
|
76
|
-
validators?: PromptValidator[];
|
|
75
|
+
preSelectedChoices?: (Choice | T)[];
|
|
76
|
+
validators?: PromptValidator<T[]>[];
|
|
77
77
|
autocomplete?: boolean;
|
|
78
78
|
caseSensitive?: boolean;
|
|
79
79
|
showHint?: boolean;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
interface SelectOptions extends AbstractPromptOptions {
|
|
83
|
-
choices: (Choice |
|
|
82
|
+
interface SelectOptions<T extends string> extends AbstractPromptOptions {
|
|
83
|
+
choices: (Choice<T> | T)[];
|
|
84
84
|
maxVisible?: number;
|
|
85
|
-
ignoreValues?: (
|
|
86
|
-
validators?: PromptValidator[];
|
|
85
|
+
ignoreValues?: (T | number | boolean)[];
|
|
86
|
+
validators?: PromptValidator<T>[];
|
|
87
87
|
autocomplete?: boolean;
|
|
88
88
|
caseSensitive?: boolean;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
|
|
92
|
-
declare function select(message: string, options: Omit<SelectOptions
|
|
92
|
+
declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
|
|
93
93
|
declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
|
|
94
|
-
declare function multiselect(message: string, options: Omit<MultiselectOptions
|
|
94
|
+
declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
|
|
95
95
|
|
|
96
96
|
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
|