@topcli/prompts 1.8.0 → 1.8.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/README.md CHANGED
@@ -201,6 +201,7 @@ export interface ConfirmOptions extends SharedOptions {
201
201
  <td align="center" valign="top" width="14.28%"><a href="http://tonygo.dev"><img src="https://avatars0.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt="Tony Gorez"/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/TopCli/prompts/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a></td>
202
202
  <td align="center" valign="top" width="14.28%"><a href="http://sofiand.github.io/portfolio-client/"><img src="https://avatars.githubusercontent.com/u/39944043?v=4?s=100" width="100px;" alt="Yefis"/><br /><sub><b>Yefis</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Documentation">📖</a></td>
203
203
  <td align="center" valign="top" width="14.28%"><a href="http://justie.dev"><img src="https://avatars.githubusercontent.com/u/7118300?v=4?s=100" width="100px;" alt="Ben"/><br /><sub><b>Ben</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=JUSTIVE" title="Documentation">📖</a> <a href="#maintenance-JUSTIVE" title="Maintenance">🚧</a></td>
204
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ncukondo"><img src="https://avatars.githubusercontent.com/u/17022138?v=4?s=100" width="100px;" alt="Takeshi Kondo"/><br /><sub><b>Takeshi Kondo</b></sub></a><br /><a href="#maintenance-ncukondo" title="Maintenance">🚧</a></td>
204
205
  </tr>
205
206
  </tbody>
206
207
  </table>
package/dist/index.cjs CHANGED
@@ -314,6 +314,7 @@ var kToggleKeys = /* @__PURE__ */ new Set([
314
314
  var ConfirmPrompt = class extends AbstractPrompt {
315
315
  initial;
316
316
  selectedValue;
317
+ fastAnswer;
317
318
  #boundKeyPressEvent;
318
319
  #boundExitEvent;
319
320
  constructor(message, options = {}) {
@@ -357,7 +358,18 @@ var ConfirmPrompt = class extends AbstractPrompt {
357
358
  if (kToggleKeys.has(key.name ?? "")) {
358
359
  this.selectedValue = !this.selectedValue;
359
360
  }
360
- this.#render();
361
+ if (key.name === "y") {
362
+ this.selectedValue = true;
363
+ resolve(true);
364
+ this.fastAnswer = true;
365
+ } else if (key.name === "n") {
366
+ this.selectedValue = false;
367
+ resolve(false);
368
+ this.fastAnswer = true;
369
+ }
370
+ if (!this.fastAnswer) {
371
+ this.#render();
372
+ }
361
373
  }
362
374
  #onProcessExit() {
363
375
  this.stdin.off("keypress", this.#boundKeyPressEvent);
@@ -367,9 +379,10 @@ var ConfirmPrompt = class extends AbstractPrompt {
367
379
  return `${query} ${this.#getHint()}`;
368
380
  }
369
381
  #onQuestionAnswer() {
382
+ const defaultLines = this.fastAnswer ? 0 : 1;
370
383
  this.stdout.moveCursor(
371
384
  -this.stdout.columns,
372
- -(Math.floor((0, import_wcwidth2.default)(stripAnsi(this.#getQuestionQuery())) / this.stdout.columns) || 1)
385
+ -(Math.floor((0, import_wcwidth2.default)(stripAnsi(this.#getQuestionQuery())) / this.stdout.columns) || defaultLines)
373
386
  );
374
387
  this.stdout.clearScreenDown();
375
388
  this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${import_kleur3.default.bold(this.message)}${import_node_os3.EOL}`);
@@ -520,10 +533,9 @@ var SelectPrompt = class extends AbstractPrompt {
520
533
  async select() {
521
534
  const answer = this.agent.nextAnswers.shift();
522
535
  if (answer !== void 0) {
523
- const formatedAnser = Array.isArray(answer) ? answer.join(", ") : answer;
524
- this.#showAnsweredQuestion(formatedAnser);
536
+ this.#showAnsweredQuestion(answer);
525
537
  this.destroy();
526
- return Array.isArray(answer) ? answer : [answer];
538
+ return answer;
527
539
  }
528
540
  this.write(SYMBOLS.HideCursor);
529
541
  this.#showQuestion();
package/dist/index.d.cts CHANGED
@@ -69,8 +69,8 @@ interface SelectOptions extends SharedOptions {
69
69
  ignoreValues?: (string | number | boolean)[];
70
70
  }
71
71
 
72
- declare function question(message: any, options?: {}): Promise<string>;
73
- declare function select(message: string, options: SelectOptions): Promise<string[]>;
72
+ declare function question(message: string, options?: QuestionOptions): Promise<string>;
73
+ declare function select(message: string, options: SelectOptions): Promise<string>;
74
74
  declare function confirm(message: string, options: ConfirmOptions): Promise<boolean>;
75
75
  declare function multiselect(message: string, options: MultiselectOptions): Promise<string[]>;
76
76
 
package/dist/index.d.ts CHANGED
@@ -69,8 +69,8 @@ interface SelectOptions extends SharedOptions {
69
69
  ignoreValues?: (string | number | boolean)[];
70
70
  }
71
71
 
72
- declare function question(message: any, options?: {}): Promise<string>;
73
- declare function select(message: string, options: SelectOptions): Promise<string[]>;
72
+ declare function question(message: string, options?: QuestionOptions): Promise<string>;
73
+ declare function select(message: string, options: SelectOptions): Promise<string>;
74
74
  declare function confirm(message: string, options: ConfirmOptions): Promise<boolean>;
75
75
  declare function multiselect(message: string, options: MultiselectOptions): Promise<string[]>;
76
76
 
package/dist/index.js CHANGED
@@ -274,6 +274,7 @@ var kToggleKeys = /* @__PURE__ */ new Set([
274
274
  var ConfirmPrompt = class extends AbstractPrompt {
275
275
  initial;
276
276
  selectedValue;
277
+ fastAnswer;
277
278
  #boundKeyPressEvent;
278
279
  #boundExitEvent;
279
280
  constructor(message, options = {}) {
@@ -317,7 +318,18 @@ var ConfirmPrompt = class extends AbstractPrompt {
317
318
  if (kToggleKeys.has(key.name ?? "")) {
318
319
  this.selectedValue = !this.selectedValue;
319
320
  }
320
- this.#render();
321
+ if (key.name === "y") {
322
+ this.selectedValue = true;
323
+ resolve(true);
324
+ this.fastAnswer = true;
325
+ } else if (key.name === "n") {
326
+ this.selectedValue = false;
327
+ resolve(false);
328
+ this.fastAnswer = true;
329
+ }
330
+ if (!this.fastAnswer) {
331
+ this.#render();
332
+ }
321
333
  }
322
334
  #onProcessExit() {
323
335
  this.stdin.off("keypress", this.#boundKeyPressEvent);
@@ -327,9 +339,10 @@ var ConfirmPrompt = class extends AbstractPrompt {
327
339
  return `${query} ${this.#getHint()}`;
328
340
  }
329
341
  #onQuestionAnswer() {
342
+ const defaultLines = this.fastAnswer ? 0 : 1;
330
343
  this.stdout.moveCursor(
331
344
  -this.stdout.columns,
332
- -(Math.floor(wcwidth2(stripAnsi(this.#getQuestionQuery())) / this.stdout.columns) || 1)
345
+ -(Math.floor(wcwidth2(stripAnsi(this.#getQuestionQuery())) / this.stdout.columns) || defaultLines)
333
346
  );
334
347
  this.stdout.clearScreenDown();
335
348
  this.write(`${this.selectedValue ? SYMBOLS.Tick : SYMBOLS.Cross} ${kleur3.bold(this.message)}${EOL3}`);
@@ -480,10 +493,9 @@ var SelectPrompt = class extends AbstractPrompt {
480
493
  async select() {
481
494
  const answer = this.agent.nextAnswers.shift();
482
495
  if (answer !== void 0) {
483
- const formatedAnser = Array.isArray(answer) ? answer.join(", ") : answer;
484
- this.#showAnsweredQuestion(formatedAnser);
496
+ this.#showAnsweredQuestion(answer);
485
497
  this.destroy();
486
- return Array.isArray(answer) ? answer : [answer];
498
+ return answer;
487
499
  }
488
500
  this.write(SYMBOLS.HideCursor);
489
501
  this.#showQuestion();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topcli/prompts",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Node.js user input library for command-line interfaces.",
5
5
  "scripts": {
6
6
  "build": "tsup index.ts --format cjs,esm --dts --clean",
@@ -32,10 +32,10 @@
32
32
  "type": "module",
33
33
  "devDependencies": {
34
34
  "@nodesecure/eslint-config": "^1.9.0",
35
- "@types/node": "^20.10.6",
36
- "c8": "^8.0.1",
35
+ "@types/node": "^20.11.6",
36
+ "c8": "^9.1.0",
37
37
  "eslint": "^8.56.0",
38
- "esmock": "^2.6.0",
38
+ "esmock": "^2.6.3",
39
39
  "glob": "^10.3.10",
40
40
  "tsup": "^8.0.1",
41
41
  "tsx": "^4.7.0",