@topcli/prompts 1.9.0 → 1.10.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/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,43 @@ 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
  }
131
149
  this.stdin = input;
132
150
  this.stdout = output;
133
151
  this.message = message;
152
+ this.signal = signal;
134
153
  this.history = [];
135
154
  this.agent = PromptAgent.agent();
136
155
  this.mute = false;
@@ -141,7 +160,7 @@ var AbstractPrompt = class _AbstractPrompt {
141
160
  input,
142
161
  output: new import_node_stream.Writable({
143
162
  write: (chunk, encoding, callback) => {
144
- if (!this.mute) {
163
+ if (!this.mute && chunk) {
145
164
  this.stdout.write(chunk, encoding);
146
165
  }
147
166
  callback();
@@ -149,6 +168,16 @@ var AbstractPrompt = class _AbstractPrompt {
149
168
  }),
150
169
  terminal: true
151
170
  });
171
+ if (this.signal) {
172
+ this.#signalHandler = () => {
173
+ this.rl.close();
174
+ for (let i = 0; i < this.history.length; i++) {
175
+ this.clearLastLine();
176
+ }
177
+ this.emit("error", new AbortError("Prompt aborted"));
178
+ };
179
+ this.signal.addEventListener("abort", this.#signalHandler, { once: true });
180
+ }
152
181
  }
153
182
  write(data) {
154
183
  const formattedData = stripAnsi(data).replace(import_node_os.EOL, "");
@@ -168,6 +197,9 @@ var AbstractPrompt = class _AbstractPrompt {
168
197
  }
169
198
  destroy() {
170
199
  this.rl.close();
200
+ if (this.signal) {
201
+ this.signal.removeEventListener("abort", this.#signalHandler);
202
+ }
171
203
  }
172
204
  };
173
205
 
@@ -215,15 +247,14 @@ var QuestionPrompt = class extends AbstractPrompt {
215
247
  answerBuffer;
216
248
  #validators;
217
249
  #secure;
218
- constructor(message, options = {}) {
250
+ constructor(options) {
219
251
  const {
220
- stdin = process.stdin,
221
- stdout = process.stdout,
222
252
  defaultValue,
223
253
  validators = [],
224
- secure = false
254
+ secure = false,
255
+ ...baseOptions
225
256
  } = options;
226
- super(message, stdin, stdout);
257
+ super({ ...baseOptions });
227
258
  if (defaultValue && typeof defaultValue !== "string") {
228
259
  throw new TypeError("defaultValue must be a string");
229
260
  }
@@ -236,6 +267,7 @@ var QuestionPrompt = class extends AbstractPrompt {
236
267
  #question() {
237
268
  return new Promise((resolve) => {
238
269
  const questionQuery = this.#getQuestionQuery();
270
+ this.history.push(questionQuery);
239
271
  this.rl.question(questionQuery, (answer) => {
240
272
  this.history.push(questionQuery + answer);
241
273
  this.mute = false;
@@ -273,24 +305,30 @@ var QuestionPrompt = class extends AbstractPrompt {
273
305
  this.answerBuffer = void 0;
274
306
  this.#writeAnswer();
275
307
  }
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;
308
+ question() {
309
+ return new Promise(async (resolve, reject) => {
310
+ this.answer = this.agent.nextAnswers.shift();
311
+ if (this.answer !== void 0) {
312
+ this.#writeAnswer();
313
+ this.destroy();
314
+ resolve(this.answer);
315
+ return;
316
+ }
317
+ this.once("error", (error) => {
318
+ reject(error);
319
+ });
320
+ this.answer = await this.#question();
321
+ if (this.answer === "" && this.defaultValue) {
322
+ this.answer = this.defaultValue;
323
+ }
290
324
  this.#onQuestionAnswer();
291
- }
292
- this.destroy();
293
- return this.answer;
325
+ while (this.answerBuffer !== void 0) {
326
+ this.answer = await this.answerBuffer;
327
+ this.#onQuestionAnswer();
328
+ }
329
+ this.destroy();
330
+ resolve(this.answer);
331
+ });
294
332
  }
295
333
  };
296
334
 
@@ -317,13 +355,12 @@ var ConfirmPrompt = class extends AbstractPrompt {
317
355
  fastAnswer;
318
356
  #boundKeyPressEvent;
319
357
  #boundExitEvent;
320
- constructor(message, options = {}) {
358
+ constructor(options) {
321
359
  const {
322
- stdin = process.stdin,
323
- stdout = process.stdout,
324
- initial = false
360
+ initial = false,
361
+ ...baseOptions
325
362
  } = options;
326
- super(message, stdin, stdout);
363
+ super({ ...baseOptions });
327
364
  this.initial = initial;
328
365
  this.selectedValue = initial;
329
366
  }
@@ -387,25 +424,31 @@ var ConfirmPrompt = class extends AbstractPrompt {
387
424
  this.stdout.clearScreenDown();
388
425
  this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${import_kleur3.default.bold(this.message)}${import_node_os3.EOL}`);
389
426
  }
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
- }
427
+ confirm() {
428
+ return new Promise(async (resolve, reject) => {
429
+ const answer = this.agent.nextAnswers.shift();
430
+ if (answer !== void 0) {
431
+ this.selectedValue = answer;
432
+ this.#onQuestionAnswer();
433
+ this.destroy();
434
+ resolve(answer);
435
+ return;
436
+ }
437
+ this.once("error", (error) => {
438
+ reject(error);
439
+ });
440
+ this.write(SYMBOLS.HideCursor);
441
+ try {
442
+ await this.#question();
443
+ this.#onQuestionAnswer();
444
+ resolve(this.selectedValue);
445
+ } finally {
446
+ this.write(SYMBOLS.ShowCursor);
447
+ this.#onProcessExit();
448
+ process.off("exit", this.#boundExitEvent);
449
+ this.destroy();
450
+ }
451
+ });
409
452
  }
410
453
  };
411
454
 
@@ -417,6 +460,7 @@ var kRequiredChoiceProperties = ["label", "value"];
417
460
  var SelectPrompt = class extends AbstractPrompt {
418
461
  #boundExitEvent = () => void 0;
419
462
  #boundKeyPressEvent = () => void 0;
463
+ #validators;
420
464
  activeIndex = 0;
421
465
  questionMessage;
422
466
  autocompleteValue = "";
@@ -454,22 +498,19 @@ var SelectPrompt = class extends AbstractPrompt {
454
498
  return choice.label.length;
455
499
  }));
456
500
  }
457
- constructor(message, options) {
501
+ constructor(options) {
458
502
  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
- }
503
+ choices,
504
+ validators = [],
505
+ ...baseOptions
506
+ } = options;
507
+ super({ ...baseOptions });
468
508
  this.options = options;
469
509
  if (!choices?.length) {
470
510
  this.destroy();
471
511
  throw new TypeError("Missing required param: choices");
472
512
  }
513
+ this.#validators = validators;
473
514
  for (const choice of choices) {
474
515
  if (typeof choice === "string") {
475
516
  continue;
@@ -549,6 +590,13 @@ var SelectPrompt = class extends AbstractPrompt {
549
590
  const choice = this.filteredChoices[this.activeIndex] || "";
550
591
  const label = typeof choice === "string" ? choice : choice.label;
551
592
  const value = typeof choice === "string" ? choice : choice.value;
593
+ for (const validator of this.#validators) {
594
+ if (!validator.validate(value)) {
595
+ const error = validator.error(value);
596
+ render({ error });
597
+ return;
598
+ }
599
+ }
552
600
  render({ clearRender: true });
553
601
  if (!this.options.ignoreValues?.includes(value)) {
554
602
  this.#showAnsweredQuestion(label);
@@ -570,56 +618,71 @@ var SelectPrompt = class extends AbstractPrompt {
570
618
  render();
571
619
  }
572
620
  }
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) {
621
+ select() {
622
+ return new Promise((resolve, reject) => {
623
+ const answer = this.agent.nextAnswers.shift();
624
+ if (answer !== void 0) {
625
+ this.#showAnsweredQuestion(answer);
626
+ this.destroy();
627
+ resolve(answer);
628
+ return;
629
+ }
630
+ this.once("error", (error) => {
631
+ reject(error);
632
+ });
633
+ this.write(SYMBOLS.HideCursor);
634
+ this.#showQuestion();
635
+ const render = (options = {}) => {
636
+ const {
637
+ initialRender = false,
638
+ clearRender = false,
639
+ error = null
640
+ } = options;
641
+ if (!initialRender) {
642
+ let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
643
+ while (linesToClear > 0) {
598
644
  this.clearLastLine();
599
- linesToClear2--;
645
+ linesToClear--;
646
+ }
647
+ if (this.options.autocomplete) {
648
+ let linesToClear2 = Math.ceil(
649
+ (0, import_wcwidth3.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
650
+ );
651
+ while (linesToClear2 > 0) {
652
+ this.clearLastLine();
653
+ linesToClear2--;
654
+ }
600
655
  }
601
656
  }
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) => {
657
+ if (clearRender) {
658
+ const questionLineCount = Math.ceil(
659
+ (0, import_wcwidth3.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
660
+ );
661
+ this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
662
+ this.stdout.clearScreenDown();
663
+ return;
664
+ }
665
+ if (error) {
666
+ const linesToClear = Math.ceil((0, import_wcwidth3.default)(this.questionMessage) / this.stdout.columns) + 1;
667
+ this.stdout.moveCursor(0, -linesToClear);
668
+ this.stdout.clearScreenDown();
669
+ this.#showQuestion(error);
670
+ }
671
+ this.#showChoices();
672
+ };
673
+ render({ initialRender: true });
615
674
  this.#boundKeyPressEvent = this.#onKeypress.bind(this, resolve, render);
616
675
  this.stdin.on("keypress", this.#boundKeyPressEvent);
617
676
  this.#boundExitEvent = this.#onProcessExit.bind(this);
618
677
  process.once("exit", this.#boundExitEvent);
619
678
  });
620
679
  }
621
- #showQuestion() {
622
- this.questionMessage = `${SYMBOLS.QuestionMark} ${import_kleur4.default.bold(this.message)}`;
680
+ #showQuestion(error = null) {
681
+ let hint = "";
682
+ if (error) {
683
+ hint = ` ${hint.length > 0 ? " " : ""}${import_kleur4.default.red().bold(`[${error}]`)}`;
684
+ }
685
+ this.questionMessage = `${SYMBOLS.QuestionMark} ${import_kleur4.default.bold(this.message)}${hint}`;
623
686
  this.write(`${this.questionMessage}${import_node_os4.EOL}`);
624
687
  }
625
688
  };
@@ -635,7 +698,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
635
698
  #validators;
636
699
  #showHint;
637
700
  activeIndex = 0;
638
- selectedIndexes = [];
701
+ selectedIndexes = /* @__PURE__ */ new Set();
639
702
  questionMessage;
640
703
  autocompleteValue = "";
641
704
  options;
@@ -672,20 +735,15 @@ var MultiselectPrompt = class extends AbstractPrompt {
672
735
  return choice.label.length;
673
736
  }));
674
737
  }
675
- constructor(message, options) {
738
+ constructor(options) {
676
739
  const {
677
- stdin = process.stdin,
678
- stdout = process.stdout,
679
740
  choices,
680
741
  preSelectedChoices,
681
742
  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
- }
743
+ showHint = true,
744
+ ...baseOptions
745
+ } = options;
746
+ super({ ...baseOptions });
689
747
  this.options = options;
690
748
  if (!choices?.length) {
691
749
  this.destroy();
@@ -718,7 +776,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
718
776
  this.destroy();
719
777
  throw new Error(`Invalid pre-selected choice: ${typeof choice === "string" ? choice : choice.value}`);
720
778
  }
721
- this.selectedIndexes.push(choiceIndex);
779
+ this.selectedIndexes.add(choiceIndex);
722
780
  }
723
781
  }
724
782
  #getFormattedChoice(choiceIndex) {
@@ -746,7 +804,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
746
804
  for (let choiceIndex = startIndex; choiceIndex < endIndex; choiceIndex++) {
747
805
  const choice = this.#getFormattedChoice(choiceIndex);
748
806
  const isChoiceActive = choiceIndex === this.activeIndex;
749
- const isChoiceSelected = this.selectedIndexes.includes(choiceIndex);
807
+ const isChoiceSelected = this.selectedIndexes.has(choiceIndex);
750
808
  const showPreviousChoicesArrow = startIndex > 0 && choiceIndex === startIndex;
751
809
  const showNextChoicesArrow = endIndex < this.filteredChoices.length && choiceIndex === endIndex - 1;
752
810
  let prefixArrow = " ";
@@ -766,7 +824,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
766
824
  }
767
825
  }
768
826
  #showAnsweredQuestion(choices, isAgentAnswer = false) {
769
- const prefixSymbol = this.selectedIndexes.length === 0 && !isAgentAnswer ? SYMBOLS.Cross : SYMBOLS.Tick;
827
+ const prefixSymbol = this.selectedIndexes.size === 0 && !isAgentAnswer ? SYMBOLS.Cross : SYMBOLS.Tick;
770
828
  const prefix = `${prefixSymbol} ${import_kleur5.default.bold(this.message)} ${SYMBOLS.Pointer}`;
771
829
  const formattedChoice = import_kleur5.default.yellow(choices);
772
830
  this.write(`${prefix}${choices ? ` ${formattedChoice}` : ""}${import_node_os5.EOL}`);
@@ -786,20 +844,20 @@ var MultiselectPrompt = class extends AbstractPrompt {
786
844
  this.activeIndex = this.activeIndex === this.filteredChoices.length - 1 ? 0 : this.activeIndex + 1;
787
845
  render();
788
846
  } else if (key.ctrl && key.name === "a") {
789
- this.selectedIndexes = this.selectedIndexes.length === this.filteredChoices.length ? [] : this.filteredChoices.map((_, index) => index);
847
+ this.selectedIndexes = this.selectedIndexes.size === this.filteredChoices.length ? /* @__PURE__ */ new Set() : new Set(this.filteredChoices.map((_, index) => index));
790
848
  render();
791
849
  } else if (key.name === "right") {
792
- this.selectedIndexes.push(this.activeIndex);
850
+ this.selectedIndexes.add(this.activeIndex);
793
851
  render();
794
852
  } else if (key.name === "left") {
795
- this.selectedIndexes = this.selectedIndexes.filter((index) => index !== this.activeIndex);
853
+ this.selectedIndexes = new Set([...this.selectedIndexes].filter((index) => index !== this.activeIndex));
796
854
  render();
797
855
  } else if (key.name === "return") {
798
- const labels = this.selectedIndexes.map((index) => {
856
+ const labels = [...this.selectedIndexes].map((index) => {
799
857
  const choice = this.filteredChoices[index];
800
858
  return typeof choice === "string" ? choice : choice.label;
801
859
  });
802
- const values = this.selectedIndexes.map((index) => {
860
+ const values = [...this.selectedIndexes].map((index) => {
803
861
  const choice = this.filteredChoices[index];
804
862
  return typeof choice === "string" ? choice : choice.value;
805
863
  });
@@ -819,7 +877,7 @@ var MultiselectPrompt = class extends AbstractPrompt {
819
877
  resolve(values);
820
878
  } else {
821
879
  if (!key.ctrl && this.options.autocomplete) {
822
- this.selectedIndexes = [];
880
+ this.selectedIndexes.clear();
823
881
  this.activeIndex = 0;
824
882
  if (key.name === "backspace" && this.autocompleteValue.length > 0) {
825
883
  this.autocompleteValue = this.autocompleteValue.slice(0, -1);
@@ -830,56 +888,60 @@ var MultiselectPrompt = class extends AbstractPrompt {
830
888
  render();
831
889
  }
832
890
  }
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) {
891
+ multiselect() {
892
+ return new Promise((resolve, reject) => {
893
+ const answer = this.agent.nextAnswers.shift();
894
+ if (answer !== void 0) {
895
+ const formatedAnser = Array.isArray(answer) ? answer.join(", ") : answer;
896
+ this.#showAnsweredQuestion(formatedAnser, true);
897
+ this.destroy();
898
+ resolve(Array.isArray(answer) ? answer : [answer]);
899
+ return;
900
+ }
901
+ this.once("error", (error) => {
902
+ reject(error);
903
+ });
904
+ this.write(SYMBOLS.HideCursor);
905
+ this.#showQuestion();
906
+ const render = (options = {}) => {
907
+ const {
908
+ initialRender = false,
909
+ clearRender = false,
910
+ error = null
911
+ } = options;
912
+ if (!initialRender) {
913
+ let linesToClear = this.lastRender.endIndex - this.lastRender.startIndex;
914
+ while (linesToClear > 0) {
860
915
  this.clearLastLine();
861
- linesToClear2--;
916
+ linesToClear--;
917
+ }
918
+ if (this.options.autocomplete) {
919
+ let linesToClear2 = Math.ceil(
920
+ (0, import_wcwidth4.default)(`${SYMBOLS.Pointer} ${this.autocompleteValue}`) / this.stdout.columns
921
+ );
922
+ while (linesToClear2 > 0) {
923
+ this.clearLastLine();
924
+ linesToClear2--;
925
+ }
862
926
  }
863
927
  }
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) => {
928
+ if (clearRender) {
929
+ const questionLineCount = Math.ceil(
930
+ (0, import_wcwidth4.default)(stripAnsi(this.questionMessage)) / this.stdout.columns
931
+ );
932
+ this.stdout.moveCursor(-this.stdout.columns, -(1 + questionLineCount));
933
+ this.stdout.clearScreenDown();
934
+ return;
935
+ }
936
+ if (error) {
937
+ const linesToClear = Math.ceil((0, import_wcwidth4.default)(this.questionMessage) / this.stdout.columns) + 1;
938
+ this.stdout.moveCursor(0, -linesToClear);
939
+ this.stdout.clearScreenDown();
940
+ this.#showQuestion(error);
941
+ }
942
+ this.#showChoices();
943
+ };
944
+ render({ initialRender: true });
883
945
  this.#boundKeyPressEvent = this.#onKeypress.bind(this, resolve, render);
884
946
  this.stdin.on("keypress", this.#boundKeyPressEvent);
885
947
  this.#boundExitEvent = this.#onProcessExit.bind(this);
@@ -909,19 +971,18 @@ function required() {
909
971
 
910
972
  // index.ts
911
973
  async function question(message, options = {}) {
912
- const questionPrompt = new QuestionPrompt(message, options);
913
- return questionPrompt.question();
974
+ return new QuestionPrompt({ ...options, message }).question();
914
975
  }
915
976
  async function select(message, options) {
916
- const selectPrompt = new SelectPrompt(message, options);
977
+ const selectPrompt = new SelectPrompt({ ...options, message });
917
978
  return selectPrompt.select();
918
979
  }
919
980
  async function confirm(message, options) {
920
- const confirmPrompt = new ConfirmPrompt(message, options);
981
+ const confirmPrompt = new ConfirmPrompt({ ...options, message });
921
982
  return confirmPrompt.confirm();
922
983
  }
923
984
  async function multiselect(message, options) {
924
- const multiselectPrompt = new MultiselectPrompt(message, options);
985
+ const multiselectPrompt = new MultiselectPrompt({ ...options, message });
925
986
  return multiselectPrompt.multiselect();
926
987
  }
927
988
  // Annotate the CommonJS export names for ESM import in node: