inquirerer 2.2.1 → 2.3.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 +61 -22
- package/esm/prompt.js +15 -64
- package/keypress.d.ts +1 -1
- package/keypress.js +61 -22
- package/package.json +2 -2
- package/prompt.js +14 -63
package/esm/keypress.js
CHANGED
|
@@ -13,25 +13,27 @@ export const KEY_CODES = {
|
|
|
13
13
|
BACKSPACE_LEGACY: '\x08' // For compatibility with some systems
|
|
14
14
|
};
|
|
15
15
|
const sharedInputStates = new WeakMap();
|
|
16
|
-
function getOrCreateSharedState(input
|
|
16
|
+
function getOrCreateSharedState(input) {
|
|
17
17
|
let state = sharedInputStates.get(input);
|
|
18
18
|
if (!state) {
|
|
19
19
|
const dataHandler = (key) => {
|
|
20
20
|
const currentState = sharedInputStates.get(input);
|
|
21
21
|
if (!currentState)
|
|
22
22
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// Only dispatch to the top of the active stack (current owner)
|
|
24
|
+
const owner = currentState.activeStack[currentState.activeStack.length - 1];
|
|
25
|
+
if (owner) {
|
|
26
|
+
owner.handleKey(key);
|
|
27
|
+
// Handle Ctrl+C via the current owner's process wrapper
|
|
28
|
+
if (key === KEY_CODES.CTRL_C) {
|
|
29
|
+
owner.exitProcess(0);
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
if (key === KEY_CODES.CTRL_C) {
|
|
29
|
-
proc.exit(0);
|
|
30
|
-
}
|
|
31
32
|
};
|
|
32
33
|
state = {
|
|
33
34
|
dataHandler,
|
|
34
35
|
instances: new Set(),
|
|
36
|
+
activeStack: [],
|
|
35
37
|
rawModeSet: false
|
|
36
38
|
};
|
|
37
39
|
sharedInputStates.set(input, state);
|
|
@@ -44,17 +46,25 @@ function removeFromSharedState(input, instance) {
|
|
|
44
46
|
if (!state)
|
|
45
47
|
return;
|
|
46
48
|
state.instances.delete(instance);
|
|
49
|
+
// Remove from active stack as well
|
|
50
|
+
const stackIndex = state.activeStack.indexOf(instance);
|
|
51
|
+
if (stackIndex !== -1) {
|
|
52
|
+
state.activeStack.splice(stackIndex, 1);
|
|
53
|
+
}
|
|
54
|
+
// If stack is now empty, disable raw mode
|
|
55
|
+
if (state.activeStack.length === 0 && state.rawModeSet) {
|
|
56
|
+
if (typeof input.setRawMode === 'function') {
|
|
57
|
+
input.setRawMode(false);
|
|
58
|
+
}
|
|
59
|
+
state.rawModeSet = false;
|
|
60
|
+
}
|
|
47
61
|
if (state.instances.size === 0) {
|
|
48
62
|
input.removeListener('data', state.dataHandler);
|
|
49
63
|
sharedInputStates.delete(input);
|
|
50
|
-
if (state.rawModeSet && typeof input.setRawMode === 'function') {
|
|
51
|
-
input.setRawMode(false);
|
|
52
|
-
}
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
export class TerminalKeypress {
|
|
56
67
|
listeners = {};
|
|
57
|
-
active = true;
|
|
58
68
|
noTty;
|
|
59
69
|
input;
|
|
60
70
|
proc;
|
|
@@ -70,17 +80,26 @@ export class TerminalKeypress {
|
|
|
70
80
|
this.registerWithSharedState();
|
|
71
81
|
}
|
|
72
82
|
registerWithSharedState() {
|
|
73
|
-
const state = getOrCreateSharedState(this.input
|
|
83
|
+
const state = getOrCreateSharedState(this.input);
|
|
74
84
|
state.instances.add(this);
|
|
75
85
|
}
|
|
76
86
|
isTTY() {
|
|
77
87
|
return !this.noTty;
|
|
78
88
|
}
|
|
79
89
|
isActive() {
|
|
80
|
-
|
|
90
|
+
if (this.destroyed)
|
|
91
|
+
return false;
|
|
92
|
+
const state = sharedInputStates.get(this.input);
|
|
93
|
+
if (!state)
|
|
94
|
+
return false;
|
|
95
|
+
// Active only if this instance is the current owner (top of stack)
|
|
96
|
+
return state.activeStack[state.activeStack.length - 1] === this;
|
|
97
|
+
}
|
|
98
|
+
exitProcess(code) {
|
|
99
|
+
this.proc.exit(code);
|
|
81
100
|
}
|
|
82
101
|
handleKey(key) {
|
|
83
|
-
if (
|
|
102
|
+
if (this.destroyed)
|
|
84
103
|
return;
|
|
85
104
|
const handlers = this.listeners[key];
|
|
86
105
|
handlers?.forEach(handler => handler());
|
|
@@ -103,24 +122,44 @@ export class TerminalKeypress {
|
|
|
103
122
|
this.listeners = {};
|
|
104
123
|
}
|
|
105
124
|
pause() {
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
const state = sharedInputStates.get(this.input);
|
|
126
|
+
if (!state)
|
|
127
|
+
return;
|
|
128
|
+
// Remove from active stack (from anywhere, not just top)
|
|
129
|
+
const stackIndex = state.activeStack.indexOf(this);
|
|
130
|
+
if (stackIndex !== -1) {
|
|
131
|
+
state.activeStack.splice(stackIndex, 1);
|
|
132
|
+
}
|
|
133
|
+
// If stack is now empty, disable raw mode
|
|
134
|
+
if (state.activeStack.length === 0 && state.rawModeSet) {
|
|
135
|
+
if (this.isTTY() && typeof this.input.setRawMode === 'function') {
|
|
136
|
+
this.input.setRawMode(false);
|
|
137
|
+
}
|
|
138
|
+
state.rawModeSet = false;
|
|
139
|
+
}
|
|
108
140
|
}
|
|
109
141
|
resume() {
|
|
110
|
-
this.
|
|
142
|
+
if (this.destroyed)
|
|
143
|
+
return;
|
|
144
|
+
const state = sharedInputStates.get(this.input);
|
|
145
|
+
if (!state)
|
|
146
|
+
return;
|
|
147
|
+
// Move-to-top semantics: remove from anywhere in stack, then push to top
|
|
148
|
+
const existingIndex = state.activeStack.indexOf(this);
|
|
149
|
+
if (existingIndex !== -1) {
|
|
150
|
+
state.activeStack.splice(existingIndex, 1);
|
|
151
|
+
}
|
|
152
|
+
state.activeStack.push(this);
|
|
153
|
+
// Enable raw mode if TTY
|
|
111
154
|
if (this.isTTY() && typeof this.input.setRawMode === 'function') {
|
|
112
155
|
this.input.setRawMode(true);
|
|
113
|
-
|
|
114
|
-
if (state) {
|
|
115
|
-
state.rawModeSet = true;
|
|
116
|
-
}
|
|
156
|
+
state.rawModeSet = true;
|
|
117
157
|
}
|
|
118
158
|
}
|
|
119
159
|
destroy() {
|
|
120
160
|
if (this.destroyed)
|
|
121
161
|
return;
|
|
122
162
|
this.destroyed = true;
|
|
123
|
-
this.active = false;
|
|
124
163
|
this.clearHandlers();
|
|
125
164
|
removeFromSharedState(this.input, this);
|
|
126
165
|
const state = sharedInputStates.get(this.input);
|
package/esm/prompt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { red, whiteBright, yellow, gray, dim,
|
|
1
|
+
import { red, whiteBright, yellow, gray, dim, white, blue } from 'yanse';
|
|
2
2
|
import readline from 'readline';
|
|
3
3
|
import { KEY_CODES, TerminalKeypress } from './keypress';
|
|
4
4
|
import { globalResolverRegistry } from './resolvers';
|
|
@@ -81,29 +81,23 @@ class PromptContext {
|
|
|
81
81
|
return this.validation;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
const { message, name, type, default: def, options = [] } = question;
|
|
84
|
+
function generatePromptMessage(question, ctx) {
|
|
85
|
+
const { message, name, type, default: def, options = [], description } = question;
|
|
86
86
|
const lines = [];
|
|
87
|
-
// 1. Main prompt label
|
|
88
|
-
|
|
89
|
-
// 2.
|
|
90
|
-
const validation = validationMessage(question, ctx);
|
|
91
|
-
if (validation) {
|
|
92
|
-
lines.push(validation); // already styled red
|
|
93
|
-
}
|
|
94
|
-
// 3. Append default inline (only if present)
|
|
95
|
-
let inline = '';
|
|
87
|
+
// 1. Main prompt label with --name inline
|
|
88
|
+
let promptLine = whiteBright.bold(message || `${name}?`) + ' ' + dim(`(--${name})`);
|
|
89
|
+
// 2. Append default inline (only if present)
|
|
96
90
|
switch (type) {
|
|
97
91
|
case 'confirm':
|
|
98
|
-
|
|
92
|
+
promptLine += ' (y/n)';
|
|
99
93
|
if (def !== undefined) {
|
|
100
|
-
|
|
94
|
+
promptLine += ` ${yellow(`[${def ? 'y' : 'n'}]`)}`;
|
|
101
95
|
}
|
|
102
96
|
break;
|
|
103
97
|
case 'text':
|
|
104
98
|
case 'number':
|
|
105
99
|
if (def !== undefined) {
|
|
106
|
-
|
|
100
|
+
promptLine += ` ${yellow(`[${def}]`)}`;
|
|
107
101
|
}
|
|
108
102
|
break;
|
|
109
103
|
case 'autocomplete':
|
|
@@ -112,63 +106,20 @@ function generatePromptMessageSuccinct(question, ctx) {
|
|
|
112
106
|
if (def !== undefined) {
|
|
113
107
|
const defaults = Array.isArray(def) ? def : [def];
|
|
114
108
|
const rendered = defaults.map(d => yellow(d)).join(gray(', '));
|
|
115
|
-
|
|
109
|
+
promptLine += ` ${yellow(`[${rendered}]`)}`;
|
|
116
110
|
}
|
|
117
111
|
break;
|
|
118
112
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
// 4. Final input line
|
|
123
|
-
lines.push('> ');
|
|
124
|
-
return lines.join('\n');
|
|
125
|
-
}
|
|
126
|
-
function generatePromptMessage(question, ctx) {
|
|
127
|
-
const { message, name, type = 'text', default: def, options = [], description } = question;
|
|
128
|
-
const lines = [];
|
|
129
|
-
// 1. Title Message
|
|
130
|
-
lines.push(whiteBright.bold(message || `${name}?`));
|
|
131
|
-
// 2. Optional description below title
|
|
113
|
+
lines.push(promptLine);
|
|
114
|
+
// 3. Optional description below title
|
|
132
115
|
if (description) {
|
|
133
116
|
lines.push(dim(description));
|
|
134
117
|
}
|
|
135
|
-
//
|
|
118
|
+
// 4. Validation message if applicable
|
|
136
119
|
const validation = validationMessage(question, ctx);
|
|
137
120
|
if (validation) {
|
|
138
|
-
lines.push(validation); // already red
|
|
139
|
-
}
|
|
140
|
-
// 4. Metadata (name/type)
|
|
141
|
-
lines.push(`${dim('Argument')} ${green(`--${name}`)} ${dim('type')} ${cyan(`[${type}]`)}`);
|
|
142
|
-
// 5. Default value or guidance
|
|
143
|
-
let guidance = '';
|
|
144
|
-
switch (type) {
|
|
145
|
-
case 'confirm':
|
|
146
|
-
guidance = '(y/n)';
|
|
147
|
-
if (def !== undefined) {
|
|
148
|
-
guidance += ` ${yellow(`[default: ${def ? 'y' : 'n'}]`)}`;
|
|
149
|
-
}
|
|
150
|
-
break;
|
|
151
|
-
case 'text':
|
|
152
|
-
case 'number':
|
|
153
|
-
if (def !== undefined) {
|
|
154
|
-
guidance = yellow(`[default: ${def}]`);
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
case 'autocomplete':
|
|
158
|
-
case 'list':
|
|
159
|
-
case 'checkbox':
|
|
160
|
-
if (def !== undefined) {
|
|
161
|
-
const defaults = Array.isArray(def) ? def : [def];
|
|
162
|
-
const rendered = defaults.map(d => yellow(d)).join(gray(', '));
|
|
163
|
-
guidance += `${yellow(`[default: ${rendered}]`)}`;
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
if (guidance) {
|
|
168
|
-
lines.push(guidance);
|
|
121
|
+
lines.push(validation); // already styled red
|
|
169
122
|
}
|
|
170
|
-
// 6. Final input prompt
|
|
171
|
-
lines.push(white('> ') + dim('Your input:'));
|
|
172
123
|
return lines.join('\n') + '\n';
|
|
173
124
|
}
|
|
174
125
|
export class Inquirerer {
|
|
@@ -214,7 +165,7 @@ export class Inquirerer {
|
|
|
214
165
|
this.output.write(message + '\n');
|
|
215
166
|
}
|
|
216
167
|
getInput(input) {
|
|
217
|
-
return `${white
|
|
168
|
+
return `${white('>')} ${input}`;
|
|
218
169
|
}
|
|
219
170
|
getPrompt(question, ctx, input) {
|
|
220
171
|
const promptMessage = generatePromptMessage(question, ctx);
|
package/keypress.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare const KEY_CODES: {
|
|
|
16
16
|
};
|
|
17
17
|
export declare class TerminalKeypress {
|
|
18
18
|
private listeners;
|
|
19
|
-
private active;
|
|
20
19
|
private noTty;
|
|
21
20
|
private input;
|
|
22
21
|
private proc;
|
|
@@ -25,6 +24,7 @@ export declare class TerminalKeypress {
|
|
|
25
24
|
private registerWithSharedState;
|
|
26
25
|
isTTY(): boolean;
|
|
27
26
|
isActive(): boolean;
|
|
27
|
+
exitProcess(code?: number): void;
|
|
28
28
|
handleKey(key: string): void;
|
|
29
29
|
on(key: string, callback: KeyHandler): void;
|
|
30
30
|
off(key: string, callback: KeyHandler): void;
|
package/keypress.js
CHANGED
|
@@ -16,25 +16,27 @@ exports.KEY_CODES = {
|
|
|
16
16
|
BACKSPACE_LEGACY: '\x08' // For compatibility with some systems
|
|
17
17
|
};
|
|
18
18
|
const sharedInputStates = new WeakMap();
|
|
19
|
-
function getOrCreateSharedState(input
|
|
19
|
+
function getOrCreateSharedState(input) {
|
|
20
20
|
let state = sharedInputStates.get(input);
|
|
21
21
|
if (!state) {
|
|
22
22
|
const dataHandler = (key) => {
|
|
23
23
|
const currentState = sharedInputStates.get(input);
|
|
24
24
|
if (!currentState)
|
|
25
25
|
return;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// Only dispatch to the top of the active stack (current owner)
|
|
27
|
+
const owner = currentState.activeStack[currentState.activeStack.length - 1];
|
|
28
|
+
if (owner) {
|
|
29
|
+
owner.handleKey(key);
|
|
30
|
+
// Handle Ctrl+C via the current owner's process wrapper
|
|
31
|
+
if (key === exports.KEY_CODES.CTRL_C) {
|
|
32
|
+
owner.exitProcess(0);
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
|
-
if (key === exports.KEY_CODES.CTRL_C) {
|
|
32
|
-
proc.exit(0);
|
|
33
|
-
}
|
|
34
35
|
};
|
|
35
36
|
state = {
|
|
36
37
|
dataHandler,
|
|
37
38
|
instances: new Set(),
|
|
39
|
+
activeStack: [],
|
|
38
40
|
rawModeSet: false
|
|
39
41
|
};
|
|
40
42
|
sharedInputStates.set(input, state);
|
|
@@ -47,17 +49,25 @@ function removeFromSharedState(input, instance) {
|
|
|
47
49
|
if (!state)
|
|
48
50
|
return;
|
|
49
51
|
state.instances.delete(instance);
|
|
52
|
+
// Remove from active stack as well
|
|
53
|
+
const stackIndex = state.activeStack.indexOf(instance);
|
|
54
|
+
if (stackIndex !== -1) {
|
|
55
|
+
state.activeStack.splice(stackIndex, 1);
|
|
56
|
+
}
|
|
57
|
+
// If stack is now empty, disable raw mode
|
|
58
|
+
if (state.activeStack.length === 0 && state.rawModeSet) {
|
|
59
|
+
if (typeof input.setRawMode === 'function') {
|
|
60
|
+
input.setRawMode(false);
|
|
61
|
+
}
|
|
62
|
+
state.rawModeSet = false;
|
|
63
|
+
}
|
|
50
64
|
if (state.instances.size === 0) {
|
|
51
65
|
input.removeListener('data', state.dataHandler);
|
|
52
66
|
sharedInputStates.delete(input);
|
|
53
|
-
if (state.rawModeSet && typeof input.setRawMode === 'function') {
|
|
54
|
-
input.setRawMode(false);
|
|
55
|
-
}
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
69
|
class TerminalKeypress {
|
|
59
70
|
listeners = {};
|
|
60
|
-
active = true;
|
|
61
71
|
noTty;
|
|
62
72
|
input;
|
|
63
73
|
proc;
|
|
@@ -73,17 +83,26 @@ class TerminalKeypress {
|
|
|
73
83
|
this.registerWithSharedState();
|
|
74
84
|
}
|
|
75
85
|
registerWithSharedState() {
|
|
76
|
-
const state = getOrCreateSharedState(this.input
|
|
86
|
+
const state = getOrCreateSharedState(this.input);
|
|
77
87
|
state.instances.add(this);
|
|
78
88
|
}
|
|
79
89
|
isTTY() {
|
|
80
90
|
return !this.noTty;
|
|
81
91
|
}
|
|
82
92
|
isActive() {
|
|
83
|
-
|
|
93
|
+
if (this.destroyed)
|
|
94
|
+
return false;
|
|
95
|
+
const state = sharedInputStates.get(this.input);
|
|
96
|
+
if (!state)
|
|
97
|
+
return false;
|
|
98
|
+
// Active only if this instance is the current owner (top of stack)
|
|
99
|
+
return state.activeStack[state.activeStack.length - 1] === this;
|
|
100
|
+
}
|
|
101
|
+
exitProcess(code) {
|
|
102
|
+
this.proc.exit(code);
|
|
84
103
|
}
|
|
85
104
|
handleKey(key) {
|
|
86
|
-
if (
|
|
105
|
+
if (this.destroyed)
|
|
87
106
|
return;
|
|
88
107
|
const handlers = this.listeners[key];
|
|
89
108
|
handlers?.forEach(handler => handler());
|
|
@@ -106,24 +125,44 @@ class TerminalKeypress {
|
|
|
106
125
|
this.listeners = {};
|
|
107
126
|
}
|
|
108
127
|
pause() {
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
const state = sharedInputStates.get(this.input);
|
|
129
|
+
if (!state)
|
|
130
|
+
return;
|
|
131
|
+
// Remove from active stack (from anywhere, not just top)
|
|
132
|
+
const stackIndex = state.activeStack.indexOf(this);
|
|
133
|
+
if (stackIndex !== -1) {
|
|
134
|
+
state.activeStack.splice(stackIndex, 1);
|
|
135
|
+
}
|
|
136
|
+
// If stack is now empty, disable raw mode
|
|
137
|
+
if (state.activeStack.length === 0 && state.rawModeSet) {
|
|
138
|
+
if (this.isTTY() && typeof this.input.setRawMode === 'function') {
|
|
139
|
+
this.input.setRawMode(false);
|
|
140
|
+
}
|
|
141
|
+
state.rawModeSet = false;
|
|
142
|
+
}
|
|
111
143
|
}
|
|
112
144
|
resume() {
|
|
113
|
-
this.
|
|
145
|
+
if (this.destroyed)
|
|
146
|
+
return;
|
|
147
|
+
const state = sharedInputStates.get(this.input);
|
|
148
|
+
if (!state)
|
|
149
|
+
return;
|
|
150
|
+
// Move-to-top semantics: remove from anywhere in stack, then push to top
|
|
151
|
+
const existingIndex = state.activeStack.indexOf(this);
|
|
152
|
+
if (existingIndex !== -1) {
|
|
153
|
+
state.activeStack.splice(existingIndex, 1);
|
|
154
|
+
}
|
|
155
|
+
state.activeStack.push(this);
|
|
156
|
+
// Enable raw mode if TTY
|
|
114
157
|
if (this.isTTY() && typeof this.input.setRawMode === 'function') {
|
|
115
158
|
this.input.setRawMode(true);
|
|
116
|
-
|
|
117
|
-
if (state) {
|
|
118
|
-
state.rawModeSet = true;
|
|
119
|
-
}
|
|
159
|
+
state.rawModeSet = true;
|
|
120
160
|
}
|
|
121
161
|
}
|
|
122
162
|
destroy() {
|
|
123
163
|
if (this.destroyed)
|
|
124
164
|
return;
|
|
125
165
|
this.destroyed = true;
|
|
126
|
-
this.active = false;
|
|
127
166
|
this.clearHandlers();
|
|
128
167
|
removeFromSharedState(this.input, this);
|
|
129
168
|
const state = sharedInputStates.get(this.input);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"clean-ansi": "0.1.5",
|
|
42
42
|
"makage": "0.1.8"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b8ebff70a30df8ee4fb60794f7ba7842730ba199"
|
|
45
45
|
}
|
package/prompt.js
CHANGED
|
@@ -88,29 +88,23 @@ class PromptContext {
|
|
|
88
88
|
return this.validation;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
const { message, name, type, default: def, options = [] } = question;
|
|
91
|
+
function generatePromptMessage(question, ctx) {
|
|
92
|
+
const { message, name, type, default: def, options = [], description } = question;
|
|
93
93
|
const lines = [];
|
|
94
|
-
// 1. Main prompt label
|
|
95
|
-
|
|
96
|
-
// 2.
|
|
97
|
-
const validation = validationMessage(question, ctx);
|
|
98
|
-
if (validation) {
|
|
99
|
-
lines.push(validation); // already styled red
|
|
100
|
-
}
|
|
101
|
-
// 3. Append default inline (only if present)
|
|
102
|
-
let inline = '';
|
|
94
|
+
// 1. Main prompt label with --name inline
|
|
95
|
+
let promptLine = yanse_1.whiteBright.bold(message || `${name}?`) + ' ' + (0, yanse_1.dim)(`(--${name})`);
|
|
96
|
+
// 2. Append default inline (only if present)
|
|
103
97
|
switch (type) {
|
|
104
98
|
case 'confirm':
|
|
105
|
-
|
|
99
|
+
promptLine += ' (y/n)';
|
|
106
100
|
if (def !== undefined) {
|
|
107
|
-
|
|
101
|
+
promptLine += ` ${(0, yanse_1.yellow)(`[${def ? 'y' : 'n'}]`)}`;
|
|
108
102
|
}
|
|
109
103
|
break;
|
|
110
104
|
case 'text':
|
|
111
105
|
case 'number':
|
|
112
106
|
if (def !== undefined) {
|
|
113
|
-
|
|
107
|
+
promptLine += ` ${(0, yanse_1.yellow)(`[${def}]`)}`;
|
|
114
108
|
}
|
|
115
109
|
break;
|
|
116
110
|
case 'autocomplete':
|
|
@@ -119,63 +113,20 @@ function generatePromptMessageSuccinct(question, ctx) {
|
|
|
119
113
|
if (def !== undefined) {
|
|
120
114
|
const defaults = Array.isArray(def) ? def : [def];
|
|
121
115
|
const rendered = defaults.map(d => (0, yanse_1.yellow)(d)).join((0, yanse_1.gray)(', '));
|
|
122
|
-
|
|
116
|
+
promptLine += ` ${(0, yanse_1.yellow)(`[${rendered}]`)}`;
|
|
123
117
|
}
|
|
124
118
|
break;
|
|
125
119
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
// 4. Final input line
|
|
130
|
-
lines.push('> ');
|
|
131
|
-
return lines.join('\n');
|
|
132
|
-
}
|
|
133
|
-
function generatePromptMessage(question, ctx) {
|
|
134
|
-
const { message, name, type = 'text', default: def, options = [], description } = question;
|
|
135
|
-
const lines = [];
|
|
136
|
-
// 1. Title Message
|
|
137
|
-
lines.push(yanse_1.whiteBright.bold(message || `${name}?`));
|
|
138
|
-
// 2. Optional description below title
|
|
120
|
+
lines.push(promptLine);
|
|
121
|
+
// 3. Optional description below title
|
|
139
122
|
if (description) {
|
|
140
123
|
lines.push((0, yanse_1.dim)(description));
|
|
141
124
|
}
|
|
142
|
-
//
|
|
125
|
+
// 4. Validation message if applicable
|
|
143
126
|
const validation = validationMessage(question, ctx);
|
|
144
127
|
if (validation) {
|
|
145
|
-
lines.push(validation); // already red
|
|
146
|
-
}
|
|
147
|
-
// 4. Metadata (name/type)
|
|
148
|
-
lines.push(`${(0, yanse_1.dim)('Argument')} ${(0, yanse_1.green)(`--${name}`)} ${(0, yanse_1.dim)('type')} ${(0, yanse_1.cyan)(`[${type}]`)}`);
|
|
149
|
-
// 5. Default value or guidance
|
|
150
|
-
let guidance = '';
|
|
151
|
-
switch (type) {
|
|
152
|
-
case 'confirm':
|
|
153
|
-
guidance = '(y/n)';
|
|
154
|
-
if (def !== undefined) {
|
|
155
|
-
guidance += ` ${(0, yanse_1.yellow)(`[default: ${def ? 'y' : 'n'}]`)}`;
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
case 'text':
|
|
159
|
-
case 'number':
|
|
160
|
-
if (def !== undefined) {
|
|
161
|
-
guidance = (0, yanse_1.yellow)(`[default: ${def}]`);
|
|
162
|
-
}
|
|
163
|
-
break;
|
|
164
|
-
case 'autocomplete':
|
|
165
|
-
case 'list':
|
|
166
|
-
case 'checkbox':
|
|
167
|
-
if (def !== undefined) {
|
|
168
|
-
const defaults = Array.isArray(def) ? def : [def];
|
|
169
|
-
const rendered = defaults.map(d => (0, yanse_1.yellow)(d)).join((0, yanse_1.gray)(', '));
|
|
170
|
-
guidance += `${(0, yanse_1.yellow)(`[default: ${rendered}]`)}`;
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (guidance) {
|
|
175
|
-
lines.push(guidance);
|
|
128
|
+
lines.push(validation); // already styled red
|
|
176
129
|
}
|
|
177
|
-
// 6. Final input prompt
|
|
178
|
-
lines.push((0, yanse_1.white)('> ') + (0, yanse_1.dim)('Your input:'));
|
|
179
130
|
return lines.join('\n') + '\n';
|
|
180
131
|
}
|
|
181
132
|
class Inquirerer {
|
|
@@ -221,7 +172,7 @@ class Inquirerer {
|
|
|
221
172
|
this.output.write(message + '\n');
|
|
222
173
|
}
|
|
223
174
|
getInput(input) {
|
|
224
|
-
return `${yanse_1.white
|
|
175
|
+
return `${(0, yanse_1.white)('>')} ${input}`;
|
|
225
176
|
}
|
|
226
177
|
getPrompt(question, ctx, input) {
|
|
227
178
|
const promptMessage = generatePromptMessage(question, ctx);
|