inquirerer 4.1.1 → 4.2.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/ui/stream.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ /**
3
+ * Streaming Text Component
4
+ *
5
+ * For displaying streaming output like AI chat responses
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.StreamingText = void 0;
9
+ exports.createStream = createStream;
10
+ const yanse_1 = require("yanse");
11
+ /**
12
+ * Streaming text display for AI-style output
13
+ */
14
+ class StreamingText {
15
+ prefix;
16
+ showCursor;
17
+ state;
18
+ output;
19
+ isRunning = false;
20
+ cursorTimer = null;
21
+ cursorVisible = true;
22
+ constructor(config = {}, output = process.stdout) {
23
+ this.prefix = config.prefix ?? '';
24
+ this.showCursor = config.showCursor ?? true;
25
+ this.output = output;
26
+ this.state = {
27
+ lines: [],
28
+ currentLine: '',
29
+ showCursor: this.showCursor,
30
+ isComplete: false,
31
+ };
32
+ }
33
+ /**
34
+ * Start the stream display
35
+ */
36
+ start() {
37
+ if (this.isRunning)
38
+ return this;
39
+ this.isRunning = true;
40
+ // Hide terminal cursor
41
+ this.output.write('\x1B[?25l');
42
+ // Start cursor blink if enabled
43
+ if (this.showCursor) {
44
+ this.cursorTimer = setInterval(() => {
45
+ this.cursorVisible = !this.cursorVisible;
46
+ this.render();
47
+ }, 530);
48
+ }
49
+ // Initial render
50
+ this.render();
51
+ return this;
52
+ }
53
+ /**
54
+ * Append text to the stream
55
+ */
56
+ append(text) {
57
+ for (const char of text) {
58
+ if (char === '\n') {
59
+ this.state.lines.push(this.state.currentLine);
60
+ this.state.currentLine = '';
61
+ }
62
+ else {
63
+ this.state.currentLine += char;
64
+ }
65
+ }
66
+ if (this.isRunning) {
67
+ this.render();
68
+ }
69
+ return this;
70
+ }
71
+ /**
72
+ * Append a complete line
73
+ */
74
+ appendLine(line) {
75
+ if (this.state.currentLine) {
76
+ this.state.lines.push(this.state.currentLine + line);
77
+ this.state.currentLine = '';
78
+ }
79
+ else {
80
+ this.state.lines.push(line);
81
+ }
82
+ if (this.isRunning) {
83
+ this.render();
84
+ }
85
+ return this;
86
+ }
87
+ /**
88
+ * Clear all content
89
+ */
90
+ clear() {
91
+ this.state.lines = [];
92
+ this.state.currentLine = '';
93
+ if (this.isRunning) {
94
+ this.render();
95
+ }
96
+ return this;
97
+ }
98
+ /**
99
+ * Mark stream as complete
100
+ */
101
+ done() {
102
+ this.state.isComplete = true;
103
+ // Stop cursor blink
104
+ if (this.cursorTimer) {
105
+ clearInterval(this.cursorTimer);
106
+ this.cursorTimer = null;
107
+ }
108
+ // Final render without cursor
109
+ this.cursorVisible = false;
110
+ this.render();
111
+ // Show terminal cursor and newline
112
+ this.output.write('\x1B[?25h\n');
113
+ this.isRunning = false;
114
+ return this;
115
+ }
116
+ /**
117
+ * Get the current content
118
+ */
119
+ getContent() {
120
+ const allLines = [...this.state.lines];
121
+ if (this.state.currentLine) {
122
+ allLines.push(this.state.currentLine);
123
+ }
124
+ return allLines.join('\n');
125
+ }
126
+ /**
127
+ * Render the current state
128
+ */
129
+ render() {
130
+ const { lines, currentLine, isComplete } = this.state;
131
+ // Build output
132
+ const allLines = [...lines];
133
+ // Add current line with optional cursor
134
+ let lastLine = currentLine;
135
+ if (this.showCursor && !isComplete && this.cursorVisible) {
136
+ lastLine += (0, yanse_1.cyan)('▋');
137
+ }
138
+ else if (this.showCursor && !isComplete) {
139
+ lastLine += ' ';
140
+ }
141
+ if (lastLine || allLines.length === 0) {
142
+ allLines.push(lastLine);
143
+ }
144
+ // Add prefix to each line
145
+ const prefixedLines = allLines.map((line, i) => {
146
+ if (i === 0 && this.prefix) {
147
+ return this.prefix + line;
148
+ }
149
+ return (this.prefix ? ' '.repeat(this.prefix.length) : '') + line;
150
+ });
151
+ // Clear previous output and write new
152
+ // Move cursor to start of output area
153
+ const totalLines = prefixedLines.length;
154
+ // For simplicity, just clear and rewrite
155
+ // In a more sophisticated implementation, we'd track line count
156
+ this.output.write('\r\x1B[2K');
157
+ // Write all lines
158
+ for (let i = 0; i < prefixedLines.length; i++) {
159
+ if (i > 0) {
160
+ this.output.write('\n\x1B[2K');
161
+ }
162
+ this.output.write(prefixedLines[i]);
163
+ }
164
+ // Move cursor back to end of last line
165
+ if (prefixedLines.length > 1) {
166
+ this.output.write(`\x1B[${prefixedLines.length - 1}A`);
167
+ this.output.write(`\x1B[${prefixedLines[0].length}G`);
168
+ }
169
+ }
170
+ }
171
+ exports.StreamingText = StreamingText;
172
+ /**
173
+ * Create a streaming text display
174
+ */
175
+ function createStream(options) {
176
+ return new StreamingText(options);
177
+ }
package/ui/types.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Event-driven UI Engine Types
3
+ *
4
+ * This module provides types for building custom interactive terminal UIs
5
+ * with support for key events, timers, and async updates.
6
+ */
7
+ /**
8
+ * Normalized key events - abstracts raw escape sequences
9
+ */
10
+ export declare enum Key {
11
+ UP = "UP",
12
+ DOWN = "DOWN",
13
+ LEFT = "LEFT",
14
+ RIGHT = "RIGHT",
15
+ ENTER = "ENTER",
16
+ SPACE = "SPACE",
17
+ BACKSPACE = "BACKSPACE",
18
+ ESCAPE = "ESCAPE",
19
+ TAB = "TAB",
20
+ CTRL_C = "CTRL_C"
21
+ }
22
+ /**
23
+ * Event types that can trigger state updates and re-renders
24
+ */
25
+ export type UIEvent<T = unknown> = {
26
+ type: 'key';
27
+ key: Key | string;
28
+ } | {
29
+ type: 'char';
30
+ char: string;
31
+ } | {
32
+ type: 'tick';
33
+ } | {
34
+ type: 'progress';
35
+ value: number;
36
+ } | {
37
+ type: 'data';
38
+ data: T;
39
+ } | {
40
+ type: 'resize';
41
+ width: number;
42
+ height: number;
43
+ };
44
+ /**
45
+ * Result of handling an event
46
+ */
47
+ export interface EventResult<S, V = unknown> {
48
+ state: S;
49
+ done?: boolean;
50
+ value?: V;
51
+ }
52
+ /**
53
+ * Configuration for a custom UI screen
54
+ */
55
+ export interface UIScreenConfig<S, V = unknown, D = unknown> {
56
+ /** Initial state */
57
+ initialState: S;
58
+ /** Render function - returns lines to display */
59
+ render: (state: S) => string[];
60
+ /** Event handler - reducer pattern */
61
+ onEvent: (event: UIEvent<D>, state: S) => EventResult<S, V>;
62
+ /** Called when the screen starts */
63
+ onStart?: (state: S) => void;
64
+ /** Called when the screen exits (cleanup) */
65
+ onExit?: (state: S, value?: V) => void;
66
+ /** Whether to hide the cursor */
67
+ hideCursor?: boolean;
68
+ /** Interval for tick events (ms) - enables animation */
69
+ tickInterval?: number;
70
+ }
71
+ /**
72
+ * Spinner configuration
73
+ */
74
+ export interface SpinnerConfig {
75
+ /** Text to display next to spinner */
76
+ text: string;
77
+ /** Spinner frames (defaults to dots) */
78
+ frames?: string[];
79
+ /** Frame interval in ms (default: 80) */
80
+ interval?: number;
81
+ }
82
+ /**
83
+ * Progress bar configuration
84
+ */
85
+ export interface ProgressConfig {
86
+ /** Text to display */
87
+ text: string;
88
+ /** Total width of progress bar (default: 40) */
89
+ width?: number;
90
+ /** Show percentage (default: true) */
91
+ showPercentage?: boolean;
92
+ }
93
+ /**
94
+ * Streaming text configuration
95
+ */
96
+ export interface StreamConfig {
97
+ /** Optional prefix for each line */
98
+ prefix?: string;
99
+ /** Whether to show a cursor at the end */
100
+ showCursor?: boolean;
101
+ }
102
+ /**
103
+ * Package info for upgrade UI
104
+ */
105
+ export interface PackageInfo {
106
+ name: string;
107
+ current: string;
108
+ latest: string;
109
+ type: 'dependencies' | 'devDependencies' | 'peerDependencies';
110
+ }
111
+ /**
112
+ * Upgrade selection state
113
+ */
114
+ export interface UpgradeSelection {
115
+ selected: boolean;
116
+ targetVersion: string;
117
+ }
package/ui/types.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Event-driven UI Engine Types
4
+ *
5
+ * This module provides types for building custom interactive terminal UIs
6
+ * with support for key events, timers, and async updates.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Key = void 0;
10
+ /**
11
+ * Normalized key events - abstracts raw escape sequences
12
+ */
13
+ var Key;
14
+ (function (Key) {
15
+ Key["UP"] = "UP";
16
+ Key["DOWN"] = "DOWN";
17
+ Key["LEFT"] = "LEFT";
18
+ Key["RIGHT"] = "RIGHT";
19
+ Key["ENTER"] = "ENTER";
20
+ Key["SPACE"] = "SPACE";
21
+ Key["BACKSPACE"] = "BACKSPACE";
22
+ Key["ESCAPE"] = "ESCAPE";
23
+ Key["TAB"] = "TAB";
24
+ Key["CTRL_C"] = "CTRL_C";
25
+ })(Key || (exports.Key = Key = {}));
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Interactive Upgrade UI Component
3
+ *
4
+ * pnpm-style interactive dependency upgrade interface
5
+ */
6
+ import { UIEngine } from './engine';
7
+ import { PackageInfo } from './types';
8
+ interface UpgradeConfig {
9
+ packages: PackageInfo[];
10
+ maxLines?: number;
11
+ }
12
+ interface UpgradeResult {
13
+ updates: Array<{
14
+ name: string;
15
+ from: string;
16
+ to: string;
17
+ }>;
18
+ }
19
+ /**
20
+ * Create the upgrade UI
21
+ */
22
+ export declare function interactiveUpgrade(engine: UIEngine, config: UpgradeConfig): Promise<UpgradeResult>;
23
+ /**
24
+ * Standalone upgrade prompt
25
+ */
26
+ export declare function upgradePrompt(packages: PackageInfo[], maxLines?: number): Promise<UpgradeResult>;
27
+ export {};
package/ui/upgrade.js ADDED
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ /**
3
+ * Interactive Upgrade UI Component
4
+ *
5
+ * pnpm-style interactive dependency upgrade interface
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.interactiveUpgrade = interactiveUpgrade;
9
+ exports.upgradePrompt = upgradePrompt;
10
+ const engine_1 = require("./engine");
11
+ const types_1 = require("./types");
12
+ const yanse_1 = require("yanse");
13
+ /**
14
+ * Render a single package row
15
+ */
16
+ function renderPackageRow(pkg, selection, isSelected, isVersionMode, versionIndex, versionOptions) {
17
+ const checkbox = selection.selected ? (0, yanse_1.green)('◉') : (0, yanse_1.dim)('○');
18
+ const cursor = isSelected ? (0, yanse_1.cyan)('❯') : ' ';
19
+ const name = pkg.name.padEnd(30);
20
+ const current = (0, yanse_1.dim)(pkg.current.padEnd(12));
21
+ const arrow = (0, yanse_1.dim)('→');
22
+ let target;
23
+ if (isSelected && isVersionMode) {
24
+ // Show version selector
25
+ const versions = versionOptions.map((v, i) => i === versionIndex ? (0, yanse_1.cyan)(`[${v}]`) : (0, yanse_1.dim)(v)).join(' ');
26
+ target = versions;
27
+ }
28
+ else {
29
+ target = selection.selected
30
+ ? (0, yanse_1.green)(selection.targetVersion.padEnd(12))
31
+ : (0, yanse_1.dim)(selection.targetVersion.padEnd(12));
32
+ }
33
+ const type = (0, yanse_1.dim)(`(${pkg.type.replace('Dependencies', '')})`);
34
+ return `${cursor} ${checkbox} ${name} ${current} ${arrow} ${target} ${type}`;
35
+ }
36
+ /**
37
+ * Create the upgrade UI
38
+ */
39
+ async function interactiveUpgrade(engine, config) {
40
+ const { packages, maxLines = 10 } = config;
41
+ // Initialize selections
42
+ const selections = new Map();
43
+ packages.forEach(pkg => {
44
+ selections.set(pkg.name, {
45
+ selected: false,
46
+ targetVersion: pkg.latest,
47
+ });
48
+ });
49
+ const initialState = {
50
+ packages,
51
+ selections,
52
+ selectedIndex: 0,
53
+ startIndex: 0,
54
+ maxLines,
55
+ filter: '',
56
+ mode: 'select',
57
+ versionOptions: [],
58
+ versionIndex: 0,
59
+ };
60
+ const result = await engine.run({
61
+ initialState,
62
+ hideCursor: true,
63
+ render: (state) => {
64
+ const lines = [];
65
+ // Header
66
+ lines.push((0, yanse_1.white)('Interactive Dependency Upgrade'));
67
+ lines.push((0, yanse_1.dim)('Use ↑↓ to navigate, SPACE to select, → to change version, ENTER to confirm'));
68
+ lines.push('');
69
+ // Column headers
70
+ const header = ` ${(0, yanse_1.dim)(' Package'.padEnd(32))} ${(0, yanse_1.dim)('Current'.padEnd(12))} ${(0, yanse_1.dim)('Target'.padEnd(12))} ${(0, yanse_1.dim)('Type')}`;
71
+ lines.push(header);
72
+ lines.push((0, yanse_1.dim)('─'.repeat(80)));
73
+ // Filter packages if filter is set
74
+ let filteredPackages = state.packages;
75
+ if (state.filter) {
76
+ filteredPackages = state.packages.filter(p => p.name.toLowerCase().includes(state.filter.toLowerCase()));
77
+ }
78
+ // Calculate visible range
79
+ const endIndex = Math.min(state.startIndex + state.maxLines, filteredPackages.length);
80
+ // Render visible packages
81
+ for (let i = state.startIndex; i < endIndex; i++) {
82
+ const pkg = filteredPackages[i];
83
+ const selection = state.selections.get(pkg.name);
84
+ const isSelected = i === state.selectedIndex;
85
+ const isVersionMode = state.mode === 'version' && isSelected;
86
+ lines.push(renderPackageRow(pkg, selection, isSelected, isVersionMode, state.versionIndex, state.versionOptions));
87
+ }
88
+ // Padding if fewer packages than maxLines
89
+ for (let i = filteredPackages.length; i < state.maxLines; i++) {
90
+ lines.push('');
91
+ }
92
+ lines.push((0, yanse_1.dim)('─'.repeat(80)));
93
+ // Summary
94
+ const selectedCount = Array.from(state.selections.values()).filter(s => s.selected).length;
95
+ lines.push(`${(0, yanse_1.cyan)(selectedCount.toString())} packages selected for upgrade`);
96
+ // Filter indicator
97
+ if (state.filter) {
98
+ lines.push((0, yanse_1.dim)(`Filter: ${state.filter}`));
99
+ }
100
+ return lines;
101
+ },
102
+ onEvent: (event, state) => {
103
+ // Get filtered packages for navigation
104
+ let filteredPackages = state.packages;
105
+ if (state.filter) {
106
+ filteredPackages = state.packages.filter(p => p.name.toLowerCase().includes(state.filter.toLowerCase()));
107
+ }
108
+ if (event.type === 'key') {
109
+ switch (event.key) {
110
+ case types_1.Key.UP: {
111
+ if (filteredPackages.length === 0)
112
+ return { state };
113
+ let newIndex = state.selectedIndex - 1;
114
+ let newStartIndex = state.startIndex;
115
+ if (newIndex < 0) {
116
+ newIndex = filteredPackages.length - 1;
117
+ newStartIndex = Math.max(0, filteredPackages.length - state.maxLines);
118
+ }
119
+ else if (newIndex < state.startIndex) {
120
+ newStartIndex = newIndex;
121
+ }
122
+ return {
123
+ state: {
124
+ ...state,
125
+ selectedIndex: newIndex,
126
+ startIndex: newStartIndex,
127
+ mode: 'select',
128
+ }
129
+ };
130
+ }
131
+ case types_1.Key.DOWN: {
132
+ if (filteredPackages.length === 0)
133
+ return { state };
134
+ let newIndex = (state.selectedIndex + 1) % filteredPackages.length;
135
+ let newStartIndex = state.startIndex;
136
+ if (newIndex === 0) {
137
+ newStartIndex = 0;
138
+ }
139
+ else if (newIndex >= state.startIndex + state.maxLines) {
140
+ newStartIndex = newIndex - state.maxLines + 1;
141
+ }
142
+ return {
143
+ state: {
144
+ ...state,
145
+ selectedIndex: newIndex,
146
+ startIndex: newStartIndex,
147
+ mode: 'select',
148
+ }
149
+ };
150
+ }
151
+ case types_1.Key.SPACE: {
152
+ if (filteredPackages.length === 0)
153
+ return { state };
154
+ const pkg = filteredPackages[state.selectedIndex];
155
+ const newSelections = new Map(state.selections);
156
+ const current = newSelections.get(pkg.name);
157
+ newSelections.set(pkg.name, {
158
+ ...current,
159
+ selected: !current.selected,
160
+ });
161
+ return {
162
+ state: {
163
+ ...state,
164
+ selections: newSelections,
165
+ }
166
+ };
167
+ }
168
+ case types_1.Key.RIGHT: {
169
+ if (filteredPackages.length === 0)
170
+ return { state };
171
+ const pkg = filteredPackages[state.selectedIndex];
172
+ // Generate version options (simplified - in real use, these would come from npm)
173
+ const versionOptions = [
174
+ pkg.latest,
175
+ `^${pkg.latest}`,
176
+ `~${pkg.latest}`,
177
+ pkg.current,
178
+ ];
179
+ return {
180
+ state: {
181
+ ...state,
182
+ mode: 'version',
183
+ versionOptions,
184
+ versionIndex: 0,
185
+ }
186
+ };
187
+ }
188
+ case types_1.Key.LEFT: {
189
+ if (state.mode === 'version') {
190
+ const newIndex = (state.versionIndex - 1 + state.versionOptions.length) % state.versionOptions.length;
191
+ return {
192
+ state: {
193
+ ...state,
194
+ versionIndex: newIndex,
195
+ }
196
+ };
197
+ }
198
+ return { state };
199
+ }
200
+ case types_1.Key.ENTER: {
201
+ if (state.mode === 'version') {
202
+ // Apply selected version
203
+ const pkg = filteredPackages[state.selectedIndex];
204
+ const newSelections = new Map(state.selections);
205
+ const current = newSelections.get(pkg.name);
206
+ newSelections.set(pkg.name, {
207
+ ...current,
208
+ selected: true,
209
+ targetVersion: state.versionOptions[state.versionIndex],
210
+ });
211
+ return {
212
+ state: {
213
+ ...state,
214
+ selections: newSelections,
215
+ mode: 'select',
216
+ }
217
+ };
218
+ }
219
+ // Confirm and return results
220
+ const updates = [];
221
+ state.selections.forEach((selection, name) => {
222
+ if (selection.selected) {
223
+ const pkg = state.packages.find(p => p.name === name);
224
+ updates.push({
225
+ name,
226
+ from: pkg.current,
227
+ to: selection.targetVersion,
228
+ });
229
+ }
230
+ });
231
+ return {
232
+ state,
233
+ done: true,
234
+ value: { updates },
235
+ };
236
+ }
237
+ case types_1.Key.ESCAPE: {
238
+ if (state.mode === 'version') {
239
+ return {
240
+ state: {
241
+ ...state,
242
+ mode: 'select',
243
+ }
244
+ };
245
+ }
246
+ // Cancel
247
+ return {
248
+ state,
249
+ done: true,
250
+ value: { updates: [] },
251
+ };
252
+ }
253
+ case types_1.Key.BACKSPACE: {
254
+ if (state.filter.length > 0) {
255
+ return {
256
+ state: {
257
+ ...state,
258
+ filter: state.filter.slice(0, -1),
259
+ selectedIndex: 0,
260
+ startIndex: 0,
261
+ }
262
+ };
263
+ }
264
+ return { state };
265
+ }
266
+ }
267
+ }
268
+ // Handle character input for filtering
269
+ if (event.type === 'char') {
270
+ return {
271
+ state: {
272
+ ...state,
273
+ filter: state.filter + event.char,
274
+ selectedIndex: 0,
275
+ startIndex: 0,
276
+ }
277
+ };
278
+ }
279
+ return { state };
280
+ },
281
+ });
282
+ return result ?? { updates: [] };
283
+ }
284
+ /**
285
+ * Standalone upgrade prompt
286
+ */
287
+ async function upgradePrompt(packages, maxLines) {
288
+ const engine = new engine_1.UIEngine();
289
+ try {
290
+ return await interactiveUpgrade(engine, { packages, maxLines });
291
+ }
292
+ finally {
293
+ engine.destroy();
294
+ }
295
+ }