inquirerer 2.2.1 → 2.3.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.
Files changed (3) hide show
  1. package/esm/prompt.js +15 -64
  2. package/package.json +2 -2
  3. package/prompt.js +14 -63
package/esm/prompt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { red, whiteBright, yellow, gray, dim, green, cyan, white, blue } from 'yanse';
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 generatePromptMessageSuccinct(question, ctx) {
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
- lines.push(whiteBright.bold(message || `${name}?`));
89
- // 2. Validation message if applicable
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
- inline = '(y/n)';
92
+ promptLine += ' (y/n)';
99
93
  if (def !== undefined) {
100
- inline += ` ${yellow(`[${def ? 'y' : 'n'}]`)}`;
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
- inline += `${yellow(`[${def}]`)}`;
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
- inline += `${yellow(`[${rendered}]`)}`;
109
+ promptLine += ` ${yellow(`[${rendered}]`)}`;
116
110
  }
117
111
  break;
118
112
  }
119
- if (inline) {
120
- lines[lines.length - 1] += ' ' + inline; // append to prompt line
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
- // 3. Validation warning (if failed before)
118
+ // 4. Validation message if applicable
136
119
  const validation = validationMessage(question, ctx);
137
120
  if (validation) {
138
- lines.push(validation); // already red-colored
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.bold('$')} ${input}`;
168
+ return `${white('>')} ${input}`;
218
169
  }
219
170
  getPrompt(question, ctx, input) {
220
171
  const promptMessage = generatePromptMessage(question, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inquirerer",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
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": "ad34404aab89a1f92d11de28f908ce80adcb7d72"
44
+ "gitHead": "264e5515ffaa2089b420f7c96afc287eec93196b"
45
45
  }
package/prompt.js CHANGED
@@ -88,29 +88,23 @@ class PromptContext {
88
88
  return this.validation;
89
89
  }
90
90
  }
91
- function generatePromptMessageSuccinct(question, ctx) {
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
- lines.push(yanse_1.whiteBright.bold(message || `${name}?`));
96
- // 2. Validation message if applicable
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
- inline = '(y/n)';
99
+ promptLine += ' (y/n)';
106
100
  if (def !== undefined) {
107
- inline += ` ${(0, yanse_1.yellow)(`[${def ? 'y' : 'n'}]`)}`;
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
- inline += `${(0, yanse_1.yellow)(`[${def}]`)}`;
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
- inline += `${(0, yanse_1.yellow)(`[${rendered}]`)}`;
116
+ promptLine += ` ${(0, yanse_1.yellow)(`[${rendered}]`)}`;
123
117
  }
124
118
  break;
125
119
  }
126
- if (inline) {
127
- lines[lines.length - 1] += ' ' + inline; // append to prompt line
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
- // 3. Validation warning (if failed before)
125
+ // 4. Validation message if applicable
143
126
  const validation = validationMessage(question, ctx);
144
127
  if (validation) {
145
- lines.push(validation); // already red-colored
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.bold('$')} ${input}`;
175
+ return `${(0, yanse_1.white)('>')} ${input}`;
225
176
  }
226
177
  getPrompt(question, ctx, input) {
227
178
  const promptMessage = generatePromptMessage(question, ctx);