inquirerer 1.8.0 → 1.9.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/esm/keypress.js +6 -2
- package/esm/prompt.js +29 -0
- package/keypress.js +6 -2
- package/package.json +2 -2
- package/prompt.d.ts +2 -1
- package/prompt.js +29 -0
- package/question/types.d.ts +5 -1
package/esm/keypress.js
CHANGED
|
@@ -23,7 +23,9 @@ export class TerminalKeypress {
|
|
|
23
23
|
this.input = input;
|
|
24
24
|
this.proc = proc;
|
|
25
25
|
if (this.isTTY()) {
|
|
26
|
-
this.input.setRawMode
|
|
26
|
+
if (typeof this.input.setRawMode === 'function') {
|
|
27
|
+
this.input.setRawMode(true);
|
|
28
|
+
}
|
|
27
29
|
this.input.resume();
|
|
28
30
|
this.input.setEncoding('utf8');
|
|
29
31
|
}
|
|
@@ -64,7 +66,9 @@ export class TerminalKeypress {
|
|
|
64
66
|
this.active = true;
|
|
65
67
|
}
|
|
66
68
|
destroy() {
|
|
67
|
-
this.input.setRawMode
|
|
69
|
+
if (typeof this.input.setRawMode === 'function') {
|
|
70
|
+
this.input.setRawMode(false);
|
|
71
|
+
}
|
|
68
72
|
this.input.pause();
|
|
69
73
|
this.input.removeAllListeners('data');
|
|
70
74
|
}
|
package/esm/prompt.js
CHANGED
|
@@ -357,6 +357,8 @@ export class Inquirerer {
|
|
|
357
357
|
return this.checkbox(question, ctx);
|
|
358
358
|
case 'autocomplete':
|
|
359
359
|
return this.autocomplete(question, ctx);
|
|
360
|
+
case 'number':
|
|
361
|
+
return this.number(question, ctx);
|
|
360
362
|
case 'text':
|
|
361
363
|
default:
|
|
362
364
|
return this.text(question, ctx);
|
|
@@ -402,6 +404,33 @@ export class Inquirerer {
|
|
|
402
404
|
});
|
|
403
405
|
});
|
|
404
406
|
}
|
|
407
|
+
async number(question, ctx) {
|
|
408
|
+
if (this.noTty || !this.rl) {
|
|
409
|
+
if ('default' in question) {
|
|
410
|
+
return question.default;
|
|
411
|
+
}
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
let input = '';
|
|
415
|
+
return new Promise((resolve) => {
|
|
416
|
+
this.clearScreen();
|
|
417
|
+
this.rl.question(this.getPrompt(question, ctx, input), (answer) => {
|
|
418
|
+
input = answer.trim();
|
|
419
|
+
if (input !== '') {
|
|
420
|
+
const num = Number(input);
|
|
421
|
+
if (!isNaN(num)) {
|
|
422
|
+
resolve(num);
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
resolve(null);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
resolve(null);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
}
|
|
405
434
|
async checkbox(question, ctx) {
|
|
406
435
|
if (this.noTty || !this.rl)
|
|
407
436
|
return question.default ?? []; // Return default if non-interactive
|
package/keypress.js
CHANGED
|
@@ -26,7 +26,9 @@ class TerminalKeypress {
|
|
|
26
26
|
this.input = input;
|
|
27
27
|
this.proc = proc;
|
|
28
28
|
if (this.isTTY()) {
|
|
29
|
-
this.input.setRawMode
|
|
29
|
+
if (typeof this.input.setRawMode === 'function') {
|
|
30
|
+
this.input.setRawMode(true);
|
|
31
|
+
}
|
|
30
32
|
this.input.resume();
|
|
31
33
|
this.input.setEncoding('utf8');
|
|
32
34
|
}
|
|
@@ -67,7 +69,9 @@ class TerminalKeypress {
|
|
|
67
69
|
this.active = true;
|
|
68
70
|
}
|
|
69
71
|
destroy() {
|
|
70
|
-
this.input.setRawMode
|
|
72
|
+
if (typeof this.input.setRawMode === 'function') {
|
|
73
|
+
this.input.setRawMode(false);
|
|
74
|
+
}
|
|
71
75
|
this.input.pause();
|
|
72
76
|
this.input.removeAllListeners('data');
|
|
73
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "inquirerer",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"minimist": "^1.2.8"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "8cd37ae36d4a3ae76cc31f47bcbc15fd8a6c8c84"
|
|
39
39
|
}
|
package/prompt.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable, Writable } from 'stream';
|
|
3
|
-
import { AutocompleteQuestion, CheckboxQuestion, ConfirmQuestion, OptionValue, Question, TextQuestion, Validation } from './question';
|
|
3
|
+
import { AutocompleteQuestion, CheckboxQuestion, ConfirmQuestion, NumberQuestion, OptionValue, Question, TextQuestion, Validation } from './question';
|
|
4
4
|
export interface ManPageInfo {
|
|
5
5
|
commandName: string;
|
|
6
6
|
questions: Question[];
|
|
@@ -63,6 +63,7 @@ export declare class Inquirerer {
|
|
|
63
63
|
private handleQuestionType;
|
|
64
64
|
confirm(question: ConfirmQuestion, ctx: PromptContext): Promise<boolean>;
|
|
65
65
|
text(question: TextQuestion, ctx: PromptContext): Promise<string | null>;
|
|
66
|
+
number(question: NumberQuestion, ctx: PromptContext): Promise<number | null>;
|
|
66
67
|
checkbox(question: CheckboxQuestion, ctx: PromptContext): Promise<OptionValue[]>;
|
|
67
68
|
autocomplete(question: AutocompleteQuestion, ctx: PromptContext): Promise<any>;
|
|
68
69
|
private getOptionValue;
|
package/prompt.js
CHANGED
|
@@ -363,6 +363,8 @@ class Inquirerer {
|
|
|
363
363
|
return this.checkbox(question, ctx);
|
|
364
364
|
case 'autocomplete':
|
|
365
365
|
return this.autocomplete(question, ctx);
|
|
366
|
+
case 'number':
|
|
367
|
+
return this.number(question, ctx);
|
|
366
368
|
case 'text':
|
|
367
369
|
default:
|
|
368
370
|
return this.text(question, ctx);
|
|
@@ -408,6 +410,33 @@ class Inquirerer {
|
|
|
408
410
|
});
|
|
409
411
|
});
|
|
410
412
|
}
|
|
413
|
+
async number(question, ctx) {
|
|
414
|
+
if (this.noTty || !this.rl) {
|
|
415
|
+
if ('default' in question) {
|
|
416
|
+
return question.default;
|
|
417
|
+
}
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
let input = '';
|
|
421
|
+
return new Promise((resolve) => {
|
|
422
|
+
this.clearScreen();
|
|
423
|
+
this.rl.question(this.getPrompt(question, ctx, input), (answer) => {
|
|
424
|
+
input = answer.trim();
|
|
425
|
+
if (input !== '') {
|
|
426
|
+
const num = Number(input);
|
|
427
|
+
if (!isNaN(num)) {
|
|
428
|
+
resolve(num);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
resolve(null);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
resolve(null);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
}
|
|
411
440
|
async checkbox(question, ctx) {
|
|
412
441
|
if (this.noTty || !this.rl)
|
|
413
442
|
return question.default ?? []; // Return default if non-interactive
|
package/question/types.d.ts
CHANGED
|
@@ -45,4 +45,8 @@ export interface TextQuestion extends BaseQuestion {
|
|
|
45
45
|
type: 'text';
|
|
46
46
|
default?: string;
|
|
47
47
|
}
|
|
48
|
-
export
|
|
48
|
+
export interface NumberQuestion extends BaseQuestion {
|
|
49
|
+
type: 'number';
|
|
50
|
+
default?: number;
|
|
51
|
+
}
|
|
52
|
+
export type Question = ConfirmQuestion | AutocompleteQuestion | CheckboxQuestion | TextQuestion | NumberQuestion;
|