@topcli/prompts 1.9.0 → 1.10.1

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/index.cjs CHANGED
@@ -47,6 +47,7 @@ var import_wcwidth = __toESM(require("@topcli/wcwidth"), 1);
47
47
  var import_node_os = require("os");
48
48
  var import_node_readline = require("readline");
49
49
  var import_node_stream = require("stream");
50
+ var import_node_events = __toESM(require("events"), 1);
50
51
 
51
52
  // src/utils.ts
52
53
  var import_node_process = __toESM(require("process"), 1);
@@ -112,25 +113,49 @@ var PromptAgent = class _PromptAgent {
112
113
  }
113
114
  };
114
115
 
116
+ // src/errors/abort.ts
117
+ var AbortError = class extends Error {
118
+ constructor(message) {
119
+ super(message);
120
+ this.name = "AbortError";
121
+ }
122
+ };
123
+
115
124
  // src/prompts/abstract.ts
116
- var AbstractPrompt = class _AbstractPrompt {
125
+ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
117
126
  stdin;
118
127
  stdout;
119
128
  message;
129
+ signal;
120
130
  history;
121
131
  agent;
122
132
  mute;
123
133
  rl;
124
- constructor(message, input = process.stdin, output = process.stdout) {
134
+ #signalHandler;
135
+ constructor(options) {
136
+ super();
125
137
  if (this.constructor === _AbstractPrompt) {
126
138
  throw new Error("AbstractPrompt can't be instantiated.");
127
139
  }
140
+ const {
141
+ stdin: input = process.stdin,
142
+ stdout: output = process.stdout,
143
+ message,
144
+ signal
145
+ } = options;
128
146
  if (typeof message !== "string") {
129
147
  throw new TypeError(`message must be string, ${typeof message} given.`);
130
148
  }
149
+ if (!output.isTTY) {
150
+ Object.assign(output, {
151
+ moveCursor: () => void 0,
152
+ clearScreenDown: () => void 0
153
+ });
154
+ }
131
155
  this.stdin = input;
132
156
  this.stdout = output;
133
157
  this.message = message;
158
+ this.signal = signal;
134
159
  this.history = [];
135
160
  this.agent = PromptAgent.agent();
136
161
  this.mute = false;
@@ -141,7 +166,7 @@ var AbstractPrompt = class _AbstractPrompt {
141
166
  input,
142
167
  output: new import_node_stream.Writable({
143
168
  write: (chunk, encoding, callback) => {
144
- if (!this.mute) {
169
+ if (!this.mute && chunk) {
145
170
  this.stdout.write(chunk, encoding);
146
171
  }
147
172
  callback();
@@ -149,6 +174,16 @@ var AbstractPrompt = class _AbstractPrompt {
149
174
  }),
150
175
  terminal: true
151
176
  });
177
+ if (this.signal) {
178
+ this.#signalHandler = () => {
179
+ this.rl.close();
180
+ for (let i = 0; i < this.history.length; i++) {
181
+ this.clearLastLine();
182
+ }
183
+ this.emit("error", new AbortError("Prompt aborted"));
184
+ };
185
+ this.signal.addEventListener("abort", this.#signalHandler, { once: true });
186
+ }
152
187
  }
153
188
  write(data) {
154
189
  const formattedData = stripAnsi(data).replace(import_node_os.EOL, "");
@@ -168,6 +203,9 @@ var AbstractPrompt = class _AbstractPrompt {
168
203
  }
169
204
  destroy() {
170
205
  this.rl.close();
206
+ if (this.signal) {
207
+ this.signal.removeEventListener("abort", this.#signalHandler);
208
+ }
171
209
  }
172
210
  };
173
211
 
@@ -215,15 +253,14 @@ var QuestionPrompt = class extends AbstractPrompt {
215
253
  answerBuffer;
216
254
  #validators;
217
255
  #secure;
218
- constructor(message, options = {}) {
256
+ constructor(options) {
219
257
  const {
220
- stdin = process.stdin,
221
- stdout = process.stdout,
222
258
  defaultValue,
223
259
  validators = [],
224
- secure = false
260
+ secure = false,
261
+ ...baseOptions
225
262
  } = options;
226
- super(message, stdin, stdout);
263
+ super({ ...baseOptions });
227
264
  if (defaultValue && typeof defaultValue !== "string") {
228
265
  throw new TypeError("defaultValue must be a string");
229
266
  }
@@ -236,6 +273,7 @@ var QuestionPrompt = class extends AbstractPrompt {
236
273
  #question() {
237
274
  return new Promise((resolve) => {
238
275
  const questionQuery = this.#getQuestionQuery();
276
+ this.history.push(questionQuery);
239
277
  this.rl.question(questionQuery, (answer) => {
240
278
  this.history.push(questionQuery + answer);
241
279
  this.mute = false;
@@ -273,24 +311,30 @@ var QuestionPrompt = class extends AbstractPrompt {
273
311
  this.answerBuffer = void 0;
274
312
  this.#writeAnswer();
275
313
  }
276
- async question() {
277
- this.answer = this.agent.nextAnswers.shift();
278
- if (this.answer !== void 0) {
279
- this.#writeAnswer();
280
- this.destroy();
281
- return this.answer;
282
- }
283
- this.answer = await this.#question();
284
- if (this.answer === "" && this.defaultValue) {
285
- this.answer = this.defaultValue;
286
- }
287
- this.#onQuestionAnswer();
288
- while (this.answerBuffer !== void 0) {
289
- this.answer = await this.answerBuffer;
314
+ question() {
315
+ return new Promise(async (resolve, reject) => {
316
+ this.answer = this.agent.nextAnswers.shift();
317
+ if (this.answer !== void 0) {
318
+ this.#writeAnswer();
319
+ this.destroy();
320
+ resolve(this.answer);
321
+ return;
322
+ }
323
+ this.once("error", (error) => {
324
+ reject(error);
325
+ });
326
+ this.answer = await this.#question();
327
+ if (this.answer === "" && this.defaultValue) {
328
+ this.answer = this.defaultValue;
329
+ }
290
330
  this.#onQuestionAnswer();
291
- }
292
- this.destroy();
293
- return this.answer;
331
+ while (this.answerBuffer !== void 0) {
332
+ this.answer = await this.answerBuffer;
333
+ this.#onQuestionAnswer();
334
+ }
335
+ this.destroy();
336
+ resolve(this.answer);
337
+ });
294
338
  }
295
339
  };
296
340
 
@@ -317,13 +361,12 @@ var ConfirmPrompt = class extends AbstractPrompt {
317
361
  fastAnswer;
318
362
  #boundKeyPressEvent;
319
363
  #boundExitEvent;
320
- constructor(message, options = {}) {
364
+ constructor(options) {
321
365
  const {
322
- stdin = process.stdin,
323
- stdout = process.stdout,
324
- initial = false
366
+ initial = false,
367
+ ...baseOptions
325
368
  } = options;
326
- super(message, stdin, stdout);
369
+ super({ ...baseOptions });
327
370
  this.initial = initial;
328
371
  this.selectedValue = initial;
329
372
  }
@@ -387,25 +430,31 @@ var ConfirmPrompt = class extends AbstractPrompt {
387
430
  this.stdout.clearScreenDown();
388
431
  this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${import_kleur3.default.bold(this.message)}${import_node_os3.EOL}`);
389
432
  }
390
- async confirm() {
391
- const answer = this.agent.nextAnswers.shift();
392
- if (answer !== void 0) {
393
- this.selectedValue = answer;
394
- this.#onQuestionAnswer();
395
- this.destroy();
396
- return answer;
397
- }
398
- this.write(SYMBOLS.HideCursor);
399
- try {
400
- await this.#question();
401
- this.#onQuestionAnswer();
402
- return this.selectedValue;
403
- } finally {
404
- this.write(SYMBOLS.ShowCursor);
405
- this.#onProcessExit();
406
- process.off("exit", this.#boundExitEvent);
407
- this.destroy();
408
- }
433
+ confirm() {
434
+ return new Promise(async (resolve, reject) => {
435
+ const answer = this.agent.nextAnswers.shift();
436
+ if (answer !== void 0) {
437
+ this.selectedValue = answer;
438
+ this.#onQuestionAnswer();
439
+ this.destroy();
440
+ resolve(answer);
441
+ return;
442
+ }
443
+ this.once("error", (error) => {
444
+ reject(error);
445
+ });
446
+ this.write(SYMBOLS.HideCursor);
447
+ try {
448
+ await this.#question();
449
+ this.#onQuestionAnswer();
450
+ resolve(this.selectedValue);
451
+ } finally {
452
+ this.write(SYMBOLS.ShowCursor);
453
+ this.#onProcessExit();
454
+ process.off("exit", this.#boundExitEvent);
455
+ this.destroy();
456
+ }
457
+ });
409
458
  }
410
459
  };
411
460
 
@@ -417,6 +466,7 @@ var kRequiredChoiceProperties = ["label", "value"];
417
466
  var SelectPrompt = class extends AbstractPrompt {
418
467
  #boundExitEvent = () => void 0;
419
468
  #boundKeyPressEvent = () => void 0;
469
+ #validators;
420
470
  activeIndex = 0;
421
471
  questionMessage;
422
472
  autocompleteValue = "";
@@ -454,22 +504,19 @@ var SelectPrompt = class extends AbstractPrompt {
454
504
  return choice.label.length;
455
505
  }));
456
506
  }
457
- constructor(message, options) {
507
+ constructor(options) {
458
508
  const {
459
- stdin = process.stdin,
460
- stdout = process.stdout,
461
- choices
462
- } = options ?? {};
463
- super(message, stdin, stdout);
464
- if (!options) {
465
- this.destroy();
466
- throw new TypeError("Missing required options");
467
- }
509
+ choices,
510
+ validators = [],
511
+ ...baseOptions
512
+ } = options;
513
+ super({ ...baseOptions });
468
514
  this.options = options;
469
515
  if (!choices?.length) {
470
516
  this.destroy();
471
517
  throw new TypeError("Missing required param: choices");
472
518
  }
519
+ this.#validators = validators;
473
520
  for (const choice of choices) {
474
521
  if (typeof choice === "string") {
475
522
  continue;
@@ -549,6 +596,13 @@ var SelectPrompt = class extends AbstractPrompt {
549
596
  const choice = this.filteredChoices[this.activeIndex] || "";
550
597
  const label = typeof choice === "string" ? choice : choice.label;
551
598
  const value = typeof choice === "string" ? choice : choice.value;
599
+ for (const validator of this.#validators) {
600
+ if (!validator.validate(value)) {
601
+ const error = validator.error(value);
602
+ render({ error });
603
+ return;
604
+ }
605
+ }
552
606
  render({ clearRender: true });
553
607
  if (!this.options.ignoreValues?.includes(value)) {
554
608
  this.#showAnsweredQuestion(label);
@@ -570,56 +624,71 @@ var SelectPrompt = class extends AbstractPrompt {
570
624
  render();
571
625
  }
572
626
  }
573
- async select() {
574
- const answer = this.agent.nextAnswers.shift();
575
- if (answer !== void 0) {
576
- this.#showAnsweredQuestion(answer);
577
- this.destroy();
578
- return answer;
579
- }
580
- this.write(SYMBOLS.HideCursor);
581
- this.#showQuestion();
582
- const render = (options = {}) => {
583
- const {
584
- initialRender = false,
585
- clearRender = false
586
- } = options;
587
- if (!initialRender) {
588
- let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
589
- while (linesToClear > 0) {
590
- this.clearLastLine();
591
- linesToClear--;
592
- }
593
- if (this.options.autocomplete) {
594
- let linesToClear2 = Math.ceil(
595
- (0, import_wcwidth3.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
596
- );
597
- while (linesToClear2 > 0) {
627
+ select() {
628
+ return new Promise((resolve, reject) => {
629
+ const answer = this.agent.nextAnswers.shift();
630
+ if (answer !== void 0) {
631
+ this.#showAnsweredQuestion(answer);
632
+ this.destroy();
633
+ resolve(answer);
634
+ return;
635
+ }
636
+ this.once("error", (error) => {
637
+ reject(error);
638
+ });
639
+ this.write(SYMBOLS.HideCursor);
640
+ this.#showQuestion();
641
+ const render = (options = {}) => {
642
+ const {
643
+ initialRender = false,
644
+ clearRender = false,
645
+ error = null
646
+ } = options;
647
+ if (!initialRender) {
648
+ let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
649
+ while (linesToClear > 0) {
598
650
  this.clearLastLine();
599
- linesToClear2--;
651
+ linesToClear--;
652
+ }
653
+ if (this.options.autocomplete) {
654
+ let linesToClear2 = Math.ceil(
655
+ (0, import_wcwidth3.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
656
+ );
657
+ while (linesToClear2 > 0) {
658
+ this.clearLastLine();
659
+ linesToClear2--;
660
+ }
600
661
  }
601
662
  }
602
- }
603
- if (clearRender) {
604
- const questionLineCount = Math.ceil(
605
- (0, import_wcwidth3.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
606
- );
607
- this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
608
- this.stdout.clearScreenDown();
609
- return;
610
- }
611
- this.#showChoices();
612
- };
613
- render({ initialRender: true });
614
- return new Promise((resolve) => {
663
+ if (clearRender) {
664
+ const questionLineCount = Math.ceil(
665
+ (0, import_wcwidth3.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
666
+ );
667
+ this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
668
+ this.stdout.clearScreenDown();
669
+ return;
670
+ }
671
+ if (error) {
672
+ const linesToClear = Math.ceil((0, import_wcwidth3.default)(this.questionMessage) / this.stdout.columns) + 1;
673
+ this.stdout.moveCursor(0, -linesToClear);
674
+ this.stdout.clearScreenDown();
675
+ this.#showQuestion(error);
676
+ }
677
+ this.#showChoices();
678
+ };
679
+ render({ initialRender: true });
615
680
  this.#boundKeyPressEvent = this.#onKeypress.bind(this, resolve, render);
616
681
  this.stdin.on("keypress", this.#boundKeyPressEvent);
617
682
  this.#boundExitEvent = this.#onProcessExit.bind(this);
618
683
  process.once("exit", this.#boundExitEvent);
619
684
  });
620
685
  }
621
- #showQuestion() {
622
- this.questionMessage = `${SYMBOLS.QuestionMark} ${import_kleur4.default.bold(this.message)}`;
686
+ #showQuestion(error = null) {
687
+ let hint = "";
688
+ if (error) {
689
+ hint = ` ${hint.length > 0 ? " " : ""}${import_kleur4.default.red().bold(`[${error}]`)}`;
690
+ }
691
+ this.questionMessage = `${SYMBOLS.QuestionMark} ${import_kleur4.default.bold(this.message)}${hint}`;
623
692
  this.write(`${this.questionMessage}${import_node_os4.EOL}`);
624
693
  }
625
694
  };
@@ -635,7 +704,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
635
704
  #validators;
636
705
  #showHint;
637
706
  activeIndex = 0;
638
- selectedIndexes = [];
707
+ selectedIndexes = /* @__PURE__ */ new Set();
639
708
  questionMessage;
640
709
  autocompleteValue = "";
641
710
  options;
@@ -672,20 +741,15 @@ var MultiselectPrompt = class extends AbstractPrompt {
672
741
  return choice.label.length;
673
742
  }));
674
743
  }
675
- constructor(message, options) {
744
+ constructor(options) {
676
745
  const {
677
- stdin = process.stdin,
678
- stdout = process.stdout,
679
746
  choices,
680
747
  preSelectedChoices,
681
748
  validators = [],
682
- showHint = true
683
- } = options ?? {};
684
- super(message, stdin, stdout);
685
- if (!options) {
686
- this.destroy();
687
- throw new TypeError("Missing required options");
688
- }
749
+ showHint = true,
750
+ ...baseOptions
751
+ } = options;
752
+ super({ ...baseOptions });
689
753
  this.options = options;
690
754
  if (!choices?.length) {
691
755
  this.destroy();
@@ -718,7 +782,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
718
782
  this.destroy();
719
783
  throw new Error(`Invalid pre-selected choice: ${typeof choice === "string" ? choice : choice.value}`);
720
784
  }
721
- this.selectedIndexes.push(choiceIndex);
785
+ this.selectedIndexes.add(choiceIndex);
722
786
  }
723
787
  }
724
788
  #getFormattedChoice(choiceIndex) {
@@ -746,7 +810,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
746
810
  for (let choiceIndex = startIndex; choiceIndex < endIndex; choiceIndex++) {
747
811
  const choice = this.#getFormattedChoice(choiceIndex);
748
812
  const isChoiceActive = choiceIndex === this.activeIndex;
749
- const isChoiceSelected = this.selectedIndexes.includes(choiceIndex);
813
+ const isChoiceSelected = this.selectedIndexes.has(choiceIndex);
750
814
  const showPreviousChoicesArrow = startIndex > 0 && choiceIndex === startIndex;
751
815
  const showNextChoicesArrow = endIndex < this.filteredChoices.length && choiceIndex === endIndex - 1;
752
816
  let prefixArrow = " ";
@@ -766,7 +830,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
766
830
  }
767
831
  }
768
832
  #showAnsweredQuestion(choices, isAgentAnswer = false) {
769
- const prefixSymbol = this.selectedIndexes.length === 0 && !isAgentAnswer ? SYMBOLS.Cross : SYMBOLS.Tick;
833
+ const prefixSymbol = this.selectedIndexes.size === 0 && !isAgentAnswer ? SYMBOLS.Cross : SYMBOLS.Tick;
770
834
  const prefix = `${prefixSymbol} ${import_kleur5.default.bold(this.message)} ${SYMBOLS.Pointer}`;
771
835
  const formattedChoice = import_kleur5.default.yellow(choices);
772
836
  this.write(`${prefix}${choices ? ` ${formattedChoice}` : ""}${import_node_os5.EOL}`);
@@ -786,20 +850,20 @@ var MultiselectPrompt = class extends AbstractPrompt {
786
850
  this.activeIndex = this.activeIndex === this.filteredChoices.length - 1 ? 0 : this.activeIndex + 1;
787
851
  render();
788
852
  } else if (key.ctrl && key.name === "a") {
789
- this.selectedIndexes = this.selectedIndexes.length === this.filteredChoices.length ? [] : this.filteredChoices.map((_, index) => index);
853
+ this.selectedIndexes = this.selectedIndexes.size === this.filteredChoices.length ? /* @__PURE__ */ new Set() : new Set(this.filteredChoices.map((_, index) => index));
790
854
  render();
791
855
  } else if (key.name === "right") {
792
- this.selectedIndexes.push(this.activeIndex);
856
+ this.selectedIndexes.add(this.activeIndex);
793
857
  render();
794
858
  } else if (key.name === "left") {
795
- this.selectedIndexes = this.selectedIndexes.filter((index) => index !== this.activeIndex);
859
+ this.selectedIndexes = new Set([...this.selectedIndexes].filter((index) => index !== this.activeIndex));
796
860
  render();
797
861
  } else if (key.name === "return") {
798
- const labels = this.selectedIndexes.map((index) => {
862
+ const labels = [...this.selectedIndexes].map((index) => {
799
863
  const choice = this.filteredChoices[index];
800
864
  return typeof choice === "string" ? choice : choice.label;
801
865
  });
802
- const values = this.selectedIndexes.map((index) => {
866
+ const values = [...this.selectedIndexes].map((index) => {
803
867
  const choice = this.filteredChoices[index];
804
868
  return typeof choice === "string" ? choice : choice.value;
805
869
  });
@@ -819,7 +883,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
819
883
  resolve(values);
820
884
  } else {
821
885
  if (!key.ctrl && this.options.autocomplete) {
822
- this.selectedIndexes = [];
886
+ this.selectedIndexes.clear();
823
887
  this.activeIndex = 0;
824
888
  if (key.name === "backspace" && this.autocompleteValue.length > 0) {
825
889
  this.autocompleteValue = this.autocompleteValue.slice(0, -1);
@@ -830,56 +894,60 @@ var MultiselectPrompt = class extends AbstractPrompt {
830
894
  render();
831
895
  }
832
896
  }
833
- async multiselect() {
834
- const answer = this.agent.nextAnswers.shift();
835
- if (answer !== void 0) {
836
- const formatedAnser = Array.isArray(answer) ? answer.join(", ") : answer;
837
- this.#showAnsweredQuestion(formatedAnser, true);
838
- this.destroy();
839
- return Array.isArray(answer) ? answer : [answer];
840
- }
841
- this.write(SYMBOLS.HideCursor);
842
- this.#showQuestion();
843
- const render = (options = {}) => {
844
- const {
845
- initialRender = false,
846
- clearRender = false,
847
- error = null
848
- } = options;
849
- if (!initialRender) {
850
- let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
851
- while (linesToClear > 0) {
852
- this.clearLastLine();
853
- linesToClear--;
854
- }
855
- if (this.options.autocomplete) {
856
- let linesToClear2 = Math.ceil(
857
- (0, import_wcwidth4.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
858
- );
859
- while (linesToClear2 > 0) {
897
+ multiselect() {
898
+ return new Promise((resolve, reject) => {
899
+ const answer = this.agent.nextAnswers.shift();
900
+ if (answer !== void 0) {
901
+ const formatedAnser = Array.isArray(answer) ? answer.join(", ") : answer;
902
+ this.#showAnsweredQuestion(formatedAnser, true);
903
+ this.destroy();
904
+ resolve(Array.isArray(answer) ? answer : [answer]);
905
+ return;
906
+ }
907
+ this.once("error", (error) => {
908
+ reject(error);
909
+ });
910
+ this.write(SYMBOLS.HideCursor);
911
+ this.#showQuestion();
912
+ const render = (options = {}) => {
913
+ const {
914
+ initialRender = false,
915
+ clearRender = false,
916
+ error = null
917
+ } = options;
918
+ if (!initialRender) {
919
+ let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
920
+ while (linesToClear > 0) {
860
921
  this.clearLastLine();
861
- linesToClear2--;
922
+ linesToClear--;
923
+ }
924
+ if (this.options.autocomplete) {
925
+ let linesToClear2 = Math.ceil(
926
+ (0, import_wcwidth4.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
927
+ );
928
+ while (linesToClear2 > 0) {
929
+ this.clearLastLine();
930
+ linesToClear2--;
931
+ }
862
932
  }
863
933
  }
864
- }
865
- if (clearRender) {
866
- const questionLineCount = Math.ceil(
867
- (0, import_wcwidth4.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
868
- );
869
- this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
870
- this.stdout.clearScreenDown();
871
- return;
872
- }
873
- if (error) {
874
- const linesToClear = Math.ceil((0, import_wcwidth4.default)(this.questionMessage) / this.stdout.columns) + 1;
875
- this.stdout.moveCursor(0, -linesToClear);
876
- this.stdout.clearScreenDown();
877
- this.#showQuestion(error);
878
- }
879
- this.#showChoices();
880
- };
881
- render({ initialRender: true });
882
- return new Promise((resolve) => {
934
+ if (clearRender) {
935
+ const questionLineCount = Math.ceil(
936
+ (0, import_wcwidth4.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
937
+ );
938
+ this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
939
+ this.stdout.clearScreenDown();
940
+ return;
941
+ }
942
+ if (error) {
943
+ const linesToClear = Math.ceil((0, import_wcwidth4.default)(this.questionMessage) / this.stdout.columns) + 1;
944
+ this.stdout.moveCursor(0, -linesToClear);
945
+ this.stdout.clearScreenDown();
946
+ this.#showQuestion(error);
947
+ }
948
+ this.#showChoices();
949
+ };
950
+ render({ initialRender: true });
883
951
  this.#boundKeyPressEvent = this.#onKeypress.bind(this, resolve, render);
884
952
  this.stdin.on("keypress", this.#boundKeyPressEvent);
885
953
  this.#boundExitEvent = this.#onProcessExit.bind(this);
@@ -909,19 +977,18 @@ function required() {
909
977
 
910
978
  // index.ts
911
979
  async function question(message, options = {}) {
912
- const questionPrompt = new QuestionPrompt(message, options);
913
- return questionPrompt.question();
980
+ return new QuestionPrompt({ ...options, message }).question();
914
981
  }
915
982
  async function select(message, options) {
916
- const selectPrompt = new SelectPrompt(message, options);
983
+ const selectPrompt = new SelectPrompt({ ...options, message });
917
984
  return selectPrompt.select();
918
985
  }
919
986
  async function confirm(message, options) {
920
- const confirmPrompt = new ConfirmPrompt(message, options);
987
+ const confirmPrompt = new ConfirmPrompt({ ...options, message });
921
988
  return confirmPrompt.confirm();
922
989
  }
923
990
  async function multiselect(message, options) {
924
- const multiselectPrompt = new MultiselectPrompt(message, options);
991
+ const multiselectPrompt = new MultiselectPrompt({ ...options, message });
925
992
  return multiselectPrompt.multiselect();
926
993
  }
927
994
  // Annotate the CommonJS export names for ESM import in node: