inquirerer 4.1.2 → 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.
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Spinner Component
3
+ *
4
+ * Animated loading spinner for async operations
5
+ */
6
+ import { Writable } from 'stream';
7
+ import { SpinnerConfig } from './types';
8
+ /**
9
+ * Alternative spinner styles
10
+ */
11
+ export declare const SPINNER_STYLES: {
12
+ dots: string[];
13
+ line: string[];
14
+ arc: string[];
15
+ circle: string[];
16
+ square: string[];
17
+ bounce: string[];
18
+ arrow: string[];
19
+ clock: string[];
20
+ moon: string[];
21
+ dots2: string[];
22
+ };
23
+ /**
24
+ * Create a spinner that can be controlled externally
25
+ */
26
+ export declare class Spinner {
27
+ private engine;
28
+ private frames;
29
+ private interval;
30
+ private state;
31
+ private tickTimer;
32
+ private output;
33
+ private lastLineCount;
34
+ private isRunning;
35
+ constructor(config: SpinnerConfig, output?: Writable);
36
+ /**
37
+ * Start the spinner
38
+ */
39
+ start(): this;
40
+ /**
41
+ * Update the spinner text
42
+ */
43
+ text(text: string): this;
44
+ /**
45
+ * Stop with success
46
+ */
47
+ succeed(text?: string): this;
48
+ /**
49
+ * Stop with error
50
+ */
51
+ fail(text?: string): this;
52
+ /**
53
+ * Stop with warning
54
+ */
55
+ warn(text?: string): this;
56
+ /**
57
+ * Stop with info
58
+ */
59
+ info(text?: string): this;
60
+ /**
61
+ * Stop the spinner
62
+ */
63
+ stop(status?: 'success' | 'error' | 'warning' | 'info', text?: string): this;
64
+ /**
65
+ * Render the current state
66
+ */
67
+ private render;
68
+ }
69
+ /**
70
+ * Create and start a spinner
71
+ */
72
+ export declare function createSpinner(text: string, options?: Partial<SpinnerConfig>): Spinner;
package/ui/spinner.js ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ /**
3
+ * Spinner Component
4
+ *
5
+ * Animated loading spinner for async operations
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Spinner = exports.SPINNER_STYLES = void 0;
9
+ exports.createSpinner = createSpinner;
10
+ const engine_1 = require("./engine");
11
+ const yanse_1 = require("yanse");
12
+ /**
13
+ * Default spinner frames (dots style)
14
+ */
15
+ const DEFAULT_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
16
+ /**
17
+ * Alternative spinner styles
18
+ */
19
+ exports.SPINNER_STYLES = {
20
+ dots: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
21
+ line: ['-', '\\', '|', '/'],
22
+ arc: ['◜', '◠', '◝', '◞', '◡', '◟'],
23
+ circle: ['◐', '◓', '◑', '◒'],
24
+ square: ['◰', '◳', '◲', '◱'],
25
+ bounce: ['⠁', '⠂', '⠄', '⠂'],
26
+ arrow: ['←', '↖', '↑', '↗', '→', '↘', '↓', '↙'],
27
+ clock: ['🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚', '🕛'],
28
+ moon: ['🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'],
29
+ dots2: ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'],
30
+ };
31
+ /**
32
+ * Create a spinner that can be controlled externally
33
+ */
34
+ class Spinner {
35
+ engine;
36
+ frames;
37
+ interval;
38
+ state;
39
+ tickTimer = null;
40
+ output;
41
+ lastLineCount = 0;
42
+ isRunning = false;
43
+ constructor(config, output = process.stdout) {
44
+ this.engine = new engine_1.UIEngine({ output });
45
+ this.frames = config.frames ?? DEFAULT_FRAMES;
46
+ this.interval = config.interval ?? 80;
47
+ this.output = output;
48
+ this.state = {
49
+ frame: 0,
50
+ text: config.text,
51
+ status: 'spinning',
52
+ };
53
+ }
54
+ /**
55
+ * Start the spinner
56
+ */
57
+ start() {
58
+ if (this.isRunning)
59
+ return this;
60
+ this.isRunning = true;
61
+ // Hide cursor
62
+ this.output.write('\x1B[?25l');
63
+ // Initial render
64
+ this.render();
65
+ // Start animation
66
+ this.tickTimer = setInterval(() => {
67
+ this.state.frame = (this.state.frame + 1) % this.frames.length;
68
+ this.render();
69
+ }, this.interval);
70
+ return this;
71
+ }
72
+ /**
73
+ * Update the spinner text
74
+ */
75
+ text(text) {
76
+ this.state.text = text;
77
+ if (this.isRunning) {
78
+ this.render();
79
+ }
80
+ return this;
81
+ }
82
+ /**
83
+ * Stop with success
84
+ */
85
+ succeed(text) {
86
+ return this.stop('success', text);
87
+ }
88
+ /**
89
+ * Stop with error
90
+ */
91
+ fail(text) {
92
+ return this.stop('error', text);
93
+ }
94
+ /**
95
+ * Stop with warning
96
+ */
97
+ warn(text) {
98
+ return this.stop('warning', text);
99
+ }
100
+ /**
101
+ * Stop with info
102
+ */
103
+ info(text) {
104
+ return this.stop('info', text);
105
+ }
106
+ /**
107
+ * Stop the spinner
108
+ */
109
+ stop(status = 'success', text) {
110
+ if (!this.isRunning)
111
+ return this;
112
+ // Clear timer
113
+ if (this.tickTimer) {
114
+ clearInterval(this.tickTimer);
115
+ this.tickTimer = null;
116
+ }
117
+ this.state.status = status;
118
+ if (text) {
119
+ this.state.finalText = text;
120
+ }
121
+ // Final render
122
+ this.render();
123
+ // Show cursor and newline
124
+ this.output.write('\x1B[?25h\n');
125
+ this.isRunning = false;
126
+ return this;
127
+ }
128
+ /**
129
+ * Render the current state
130
+ */
131
+ render() {
132
+ const { frame, text, status, finalText } = this.state;
133
+ let icon;
134
+ let displayText = finalText ?? text;
135
+ switch (status) {
136
+ case 'success':
137
+ icon = (0, yanse_1.green)('✔');
138
+ displayText = (0, yanse_1.green)(displayText);
139
+ break;
140
+ case 'error':
141
+ icon = (0, yanse_1.red)('✖');
142
+ displayText = (0, yanse_1.red)(displayText);
143
+ break;
144
+ case 'warning':
145
+ icon = (0, yanse_1.yellow)('⚠');
146
+ displayText = (0, yanse_1.yellow)(displayText);
147
+ break;
148
+ case 'info':
149
+ icon = (0, yanse_1.cyan)('ℹ');
150
+ displayText = (0, yanse_1.cyan)(displayText);
151
+ break;
152
+ default:
153
+ icon = (0, yanse_1.cyan)(this.frames[frame]);
154
+ }
155
+ // Clear line and write
156
+ this.output.write('\r\x1B[2K' + icon + ' ' + displayText);
157
+ }
158
+ }
159
+ exports.Spinner = Spinner;
160
+ /**
161
+ * Create and start a spinner
162
+ */
163
+ function createSpinner(text, options) {
164
+ return new Spinner({ text, ...options });
165
+ }
package/ui/stream.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Streaming Text Component
3
+ *
4
+ * For displaying streaming output like AI chat responses
5
+ */
6
+ import { Writable } from 'stream';
7
+ import { StreamConfig } from './types';
8
+ /**
9
+ * Streaming text display for AI-style output
10
+ */
11
+ export declare class StreamingText {
12
+ private prefix;
13
+ private showCursor;
14
+ private state;
15
+ private output;
16
+ private isRunning;
17
+ private cursorTimer;
18
+ private cursorVisible;
19
+ constructor(config?: StreamConfig, output?: Writable);
20
+ /**
21
+ * Start the stream display
22
+ */
23
+ start(): this;
24
+ /**
25
+ * Append text to the stream
26
+ */
27
+ append(text: string): this;
28
+ /**
29
+ * Append a complete line
30
+ */
31
+ appendLine(line: string): this;
32
+ /**
33
+ * Clear all content
34
+ */
35
+ clear(): this;
36
+ /**
37
+ * Mark stream as complete
38
+ */
39
+ done(): this;
40
+ /**
41
+ * Get the current content
42
+ */
43
+ getContent(): string;
44
+ /**
45
+ * Render the current state
46
+ */
47
+ private render;
48
+ }
49
+ /**
50
+ * Create a streaming text display
51
+ */
52
+ export declare function createStream(options?: StreamConfig): StreamingText;
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 {};