@reliverse/rempts 1.7.28 → 1.7.29
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/README.md +84 -8
- package/bin/components/aliases/aliases-mod.d.ts +11 -0
- package/bin/components/aliases/aliases-mod.js +16 -0
- package/bin/components/{visual/animate → animate}/animate.d.ts +1 -1
- package/bin/components/{visual/animate → animate}/animate.js +2 -2
- package/bin/components/anykey/anykey-mod.d.ts +2 -2
- package/bin/components/anykey/anykey-mod.js +2 -2
- package/bin/components/cancel/cancel.d.ts +45 -0
- package/bin/components/cancel/cancel.js +72 -0
- package/bin/components/editor/editor-mod.d.ts +4 -4
- package/bin/components/{st-end/start.d.ts → intro/intro-start.d.ts} +4 -1
- package/bin/components/{st-end/start.js → intro/intro-start.js} +33 -19
- package/bin/components/launcher/launcher-types.d.ts +15 -18
- package/bin/components/log/log.d.ts +2 -0
- package/bin/components/log/log.js +2 -0
- package/bin/components/next-steps/next-steps.d.ts +2 -2
- package/bin/components/number/number-mod.d.ts +2 -2
- package/bin/components/outro/outro-end.d.ts +8 -0
- package/bin/components/outro/outro-end.js +55 -0
- package/bin/components/results/results.d.ts +2 -2
- package/bin/components/select/select-prompt.d.ts +6 -5
- package/bin/components/select/select-prompt.js +4 -2
- package/bin/components/spinner/spinner-mod.d.ts +106 -0
- package/bin/components/spinner/spinner-mod.js +263 -0
- package/bin/components/task/progress.d.ts +1 -1
- package/bin/components/task/progress.js +1 -1
- package/bin/components/task/{spinner.d.ts → task-spin.d.ts} +3 -3
- package/bin/components/task/{spinner.js → task-spin.js} +1 -1
- package/bin/mod.d.ts +11 -8
- package/bin/mod.js +31 -8
- package/bin/types.d.ts +36 -36
- package/bin/utils/validate.d.ts +2 -2
- package/package.json +2 -2
- package/bin/components/st-end/end.d.ts +0 -2
- package/bin/components/st-end/end.js +0 -42
- package/bin/hooks/spinner/spinner-mod.d.ts +0 -64
- package/bin/hooks/spinner/spinner-mod.js +0 -74
- /package/bin/components/{visual/ascii-art → ascii-art}/ascii-art.d.ts +0 -0
- /package/bin/components/{visual/ascii-art → ascii-art}/ascii-art.js +0 -0
- /package/bin/components/{input → confirm}/confirm-prompt.d.ts +0 -0
- /package/bin/components/{input → confirm}/confirm-prompt.js +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { BorderColorName, ColorName, SelectOption, TypographyName, VariantName } from "../../types.js";
|
|
2
2
|
import { symbols } from "../msg-fmt/messages.js";
|
|
3
|
-
|
|
3
|
+
interface SeparatorOption {
|
|
4
4
|
separator: true;
|
|
5
5
|
width?: number;
|
|
6
6
|
symbol?: keyof typeof symbols;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
title
|
|
7
|
+
}
|
|
8
|
+
interface SelectPromptParams<T extends string> {
|
|
9
|
+
title?: string;
|
|
10
|
+
message?: string;
|
|
10
11
|
content?: string;
|
|
11
12
|
options: (SelectOption<T> | SeparatorOption)[];
|
|
12
13
|
defaultValue?: T;
|
|
@@ -25,7 +26,7 @@ type SelectPromptParams<T extends string> = {
|
|
|
25
26
|
displayInstructions?: boolean;
|
|
26
27
|
shouldStream?: boolean;
|
|
27
28
|
streamDelay?: number;
|
|
28
|
-
}
|
|
29
|
+
}
|
|
29
30
|
/**
|
|
30
31
|
* Displays a selectable prompt in the terminal and returns the chosen value.
|
|
31
32
|
*/
|
|
@@ -111,6 +111,7 @@ async function renderPromptUI(params) {
|
|
|
111
111
|
export async function selectPrompt(params) {
|
|
112
112
|
const {
|
|
113
113
|
title = "",
|
|
114
|
+
message = "",
|
|
114
115
|
content = "",
|
|
115
116
|
options,
|
|
116
117
|
defaultValue,
|
|
@@ -130,6 +131,7 @@ export async function selectPrompt(params) {
|
|
|
130
131
|
shouldStream = false,
|
|
131
132
|
streamDelay = 20
|
|
132
133
|
} = params;
|
|
134
|
+
const finalTitle = message || title;
|
|
133
135
|
let selectedIndex = defaultValue ? options.findIndex(
|
|
134
136
|
(option) => isSelectOption(option) && option.value === defaultValue && !option.disabled
|
|
135
137
|
) : -1;
|
|
@@ -159,7 +161,7 @@ export async function selectPrompt(params) {
|
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
void renderPromptUI({
|
|
162
|
-
title,
|
|
164
|
+
title: finalTitle,
|
|
163
165
|
content,
|
|
164
166
|
options,
|
|
165
167
|
selectedIndex,
|
|
@@ -183,7 +185,7 @@ export async function selectPrompt(params) {
|
|
|
183
185
|
});
|
|
184
186
|
}
|
|
185
187
|
lastUILineCount = await renderPromptUI({
|
|
186
|
-
title,
|
|
188
|
+
title: finalTitle,
|
|
187
189
|
content,
|
|
188
190
|
options,
|
|
189
191
|
selectedIndex,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
interface SpinnerOptions {
|
|
2
|
+
cancelMessage?: string;
|
|
3
|
+
color?: string;
|
|
4
|
+
delay?: number;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
failText?: string;
|
|
7
|
+
frames?: string[];
|
|
8
|
+
hideCursor?: boolean;
|
|
9
|
+
indicator?: "dots" | "timer";
|
|
10
|
+
onCancel?: () => void;
|
|
11
|
+
prefixText?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
silent?: boolean;
|
|
14
|
+
spinner?: string;
|
|
15
|
+
successText?: string;
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
interface ProgressOptions {
|
|
19
|
+
current: number;
|
|
20
|
+
total: number;
|
|
21
|
+
format?: "percentage" | "count" | "both";
|
|
22
|
+
}
|
|
23
|
+
interface SpinnerControls {
|
|
24
|
+
start: (text?: string) => SpinnerControls;
|
|
25
|
+
stop: (text?: string, code?: number) => void;
|
|
26
|
+
setText: (text: string) => void;
|
|
27
|
+
setProgress: (progress: ProgressOptions) => void;
|
|
28
|
+
succeed: (text?: string) => void;
|
|
29
|
+
fail: (text?: string) => void;
|
|
30
|
+
warn: (text?: string) => void;
|
|
31
|
+
info: (text?: string) => void;
|
|
32
|
+
isSpinning: () => boolean;
|
|
33
|
+
clear: () => void;
|
|
34
|
+
getElapsedTime: () => number;
|
|
35
|
+
pause: () => void;
|
|
36
|
+
resume: () => void;
|
|
37
|
+
dispose: () => void;
|
|
38
|
+
isCancelled: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a terminal spinner with enhanced controls and styling options.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Basic usage
|
|
46
|
+
* const spinner = useSpinner({ text: "Loading..." }).start();
|
|
47
|
+
* spinner.stop();
|
|
48
|
+
*
|
|
49
|
+
* // With progress tracking
|
|
50
|
+
* const spinner = useSpinner({ text: "Processing files..." }).start();
|
|
51
|
+
* for (let i = 0; i < files.length; i++) {
|
|
52
|
+
* spinner.setProgress({ current: i + 1, total: files.length });
|
|
53
|
+
* await processFile(files[i]);
|
|
54
|
+
* }
|
|
55
|
+
* spinner.succeed();
|
|
56
|
+
*
|
|
57
|
+
* // With custom color and spinner
|
|
58
|
+
* const spinner = useSpinner({
|
|
59
|
+
* text: "Processing...",
|
|
60
|
+
* color: "cyan",
|
|
61
|
+
* spinner: "dots"
|
|
62
|
+
* }).start();
|
|
63
|
+
*
|
|
64
|
+
* // With success/failure states
|
|
65
|
+
* const spinner = useSpinner({
|
|
66
|
+
* text: "Uploading...",
|
|
67
|
+
* successText: "Upload complete!",
|
|
68
|
+
* failText: "Upload failed!"
|
|
69
|
+
* }).start();
|
|
70
|
+
* try {
|
|
71
|
+
* await uploadFile();
|
|
72
|
+
* spinner.succeed();
|
|
73
|
+
* } catch (error) {
|
|
74
|
+
* spinner.fail();
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* // Using the wrapper for async operations
|
|
78
|
+
* await useSpinner.promise(
|
|
79
|
+
* async (spinner) => {
|
|
80
|
+
* await longOperation();
|
|
81
|
+
* spinner.setProgress({ current: 50, total: 100 });
|
|
82
|
+
* },
|
|
83
|
+
* {
|
|
84
|
+
* text: "Working...",
|
|
85
|
+
* successText: "Done!",
|
|
86
|
+
* failText: "Failed!"
|
|
87
|
+
* }
|
|
88
|
+
* );
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function useSpinner(options: SpinnerOptions): SpinnerControls;
|
|
92
|
+
export declare namespace useSpinner {
|
|
93
|
+
var promise: <T>(operation: (spinner: SpinnerControls) => Promise<T>, options: SpinnerOptions) => Promise<T>;
|
|
94
|
+
var nested: (parentOptions: SpinnerOptions) => {
|
|
95
|
+
start: () => {
|
|
96
|
+
child: (childOptions: SpinnerOptions) => SpinnerControls;
|
|
97
|
+
finish: (success: boolean, text?: string) => void;
|
|
98
|
+
dispose: () => void;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
var withTiming: <T>(operation: (spinner: SpinnerControls) => Promise<T>, options: SpinnerOptions) => Promise<{
|
|
102
|
+
result: T;
|
|
103
|
+
duration: number;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { re } from "@reliverse/relico";
|
|
2
|
+
import { block } from "../cancel/cancel.js";
|
|
3
|
+
const unicode = process.platform !== "win32" || process.env.TERM_PROGRAM === "vscode";
|
|
4
|
+
const defaultFrames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
|
|
5
|
+
const defaultDelay = unicode ? 80 : 120;
|
|
6
|
+
function isInteractive() {
|
|
7
|
+
return process.stdout.isTTY && !process.env.CI && !process.env.GITHUB_ACTIONS && !process.env.GITLAB_CI && !process.env.BUILDKITE && process.env.TERM !== "dumb";
|
|
8
|
+
}
|
|
9
|
+
function formatProgress(options) {
|
|
10
|
+
const { current, total, format = "both" } = options;
|
|
11
|
+
const percentage = Math.round(current / total * 100);
|
|
12
|
+
switch (format) {
|
|
13
|
+
case "percentage":
|
|
14
|
+
return `${percentage}%`;
|
|
15
|
+
case "count":
|
|
16
|
+
return `${current}/${total}`;
|
|
17
|
+
case "both":
|
|
18
|
+
return `${current}/${total} (${percentage}%)`;
|
|
19
|
+
default:
|
|
20
|
+
return `${current}/${total}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function formatTimer(origin) {
|
|
24
|
+
const duration = (performance.now() - origin) / 1e3;
|
|
25
|
+
const min = Math.floor(duration / 60);
|
|
26
|
+
const secs = Math.floor(duration % 60);
|
|
27
|
+
return min > 0 ? `[${min}m ${secs}s]` : `[${secs}s]`;
|
|
28
|
+
}
|
|
29
|
+
function removeTrailingDots(msg) {
|
|
30
|
+
return msg.replace(/\.+$/, "");
|
|
31
|
+
}
|
|
32
|
+
export function useSpinner(options) {
|
|
33
|
+
let loop;
|
|
34
|
+
const interactive = isInteractive();
|
|
35
|
+
let unblock = null;
|
|
36
|
+
const state = {
|
|
37
|
+
isActive: false,
|
|
38
|
+
isPaused: false,
|
|
39
|
+
startTime: null,
|
|
40
|
+
pausedTime: 0,
|
|
41
|
+
text: options.text,
|
|
42
|
+
isCancelled: false,
|
|
43
|
+
origin: performance.now(),
|
|
44
|
+
indicatorTimer: 0
|
|
45
|
+
};
|
|
46
|
+
const handleExit = (code) => {
|
|
47
|
+
const msg = code > 1 ? options.errorMessage ?? "Operation failed" : options.cancelMessage ?? "Operation cancelled";
|
|
48
|
+
state.isCancelled = code === 1;
|
|
49
|
+
if (state.isActive) {
|
|
50
|
+
controls.stop(msg, code);
|
|
51
|
+
if (state.isCancelled && typeof options.onCancel === "function") {
|
|
52
|
+
options.onCancel();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const errorEventHandler = () => handleExit(2);
|
|
57
|
+
const signalEventHandler = () => handleExit(1);
|
|
58
|
+
const registerHooks = () => {
|
|
59
|
+
process.on("uncaughtExceptionMonitor", errorEventHandler);
|
|
60
|
+
process.on("unhandledRejection", errorEventHandler);
|
|
61
|
+
process.on("SIGINT", signalEventHandler);
|
|
62
|
+
process.on("SIGTERM", signalEventHandler);
|
|
63
|
+
process.on("exit", handleExit);
|
|
64
|
+
if (options.signal) {
|
|
65
|
+
options.signal.addEventListener("abort", signalEventHandler);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const clearHooks = () => {
|
|
69
|
+
process.removeListener("uncaughtExceptionMonitor", errorEventHandler);
|
|
70
|
+
process.removeListener("unhandledRejection", errorEventHandler);
|
|
71
|
+
process.removeListener("SIGINT", signalEventHandler);
|
|
72
|
+
process.removeListener("SIGTERM", signalEventHandler);
|
|
73
|
+
process.removeListener("exit", handleExit);
|
|
74
|
+
if (options.signal) {
|
|
75
|
+
options.signal.removeEventListener("abort", signalEventHandler);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const clearPrevMessage = () => {
|
|
79
|
+
if (state.prevMessage === void 0) return;
|
|
80
|
+
if (process.env.CI) process.stdout.write("\n");
|
|
81
|
+
const prevLines = state.prevMessage.split("\n");
|
|
82
|
+
process.stdout.write(`\x1B[${prevLines.length}A`);
|
|
83
|
+
process.stdout.write("\x1B[0J");
|
|
84
|
+
};
|
|
85
|
+
const controls = {
|
|
86
|
+
start: (text) => {
|
|
87
|
+
if (text) {
|
|
88
|
+
options.text = text;
|
|
89
|
+
state.text = text;
|
|
90
|
+
}
|
|
91
|
+
if (options.silent || !interactive) {
|
|
92
|
+
console.log(
|
|
93
|
+
options.prefixText ? `${options.prefixText} ${options.text}` : options.text
|
|
94
|
+
);
|
|
95
|
+
state.isActive = true;
|
|
96
|
+
state.startTime = Date.now();
|
|
97
|
+
return controls;
|
|
98
|
+
}
|
|
99
|
+
state.isActive = true;
|
|
100
|
+
state.origin = performance.now();
|
|
101
|
+
unblock = block({ output: process.stdout });
|
|
102
|
+
process.stdout.write(`${re.dim("\u2502")}
|
|
103
|
+
`);
|
|
104
|
+
let frameIndex = 0;
|
|
105
|
+
registerHooks();
|
|
106
|
+
loop = setInterval(() => {
|
|
107
|
+
if (process.env.CI && state.text === state.prevMessage) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
clearPrevMessage();
|
|
111
|
+
state.prevMessage = state.text;
|
|
112
|
+
const frame = re.magenta((options.frames ?? defaultFrames)[frameIndex]);
|
|
113
|
+
if (process.env.CI) {
|
|
114
|
+
process.stdout.write(`${frame} ${state.text}...`);
|
|
115
|
+
} else if (options.indicator === "timer") {
|
|
116
|
+
process.stdout.write(
|
|
117
|
+
`${frame} ${state.text} ${formatTimer(state.origin)}`
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
const loadingDots = ".".repeat(Math.floor(state.indicatorTimer)).slice(0, 3);
|
|
121
|
+
process.stdout.write(`${frame} ${state.text}${loadingDots}`);
|
|
122
|
+
}
|
|
123
|
+
frameIndex = (frameIndex + 1) % (options.frames ?? defaultFrames).length;
|
|
124
|
+
state.indicatorTimer = state.indicatorTimer < 4 ? state.indicatorTimer + 0.125 : 0;
|
|
125
|
+
}, options.delay ?? defaultDelay);
|
|
126
|
+
return controls;
|
|
127
|
+
},
|
|
128
|
+
stop: (text, code = 0) => {
|
|
129
|
+
if (!state.isActive) return;
|
|
130
|
+
state.isActive = false;
|
|
131
|
+
clearInterval(loop);
|
|
132
|
+
clearPrevMessage();
|
|
133
|
+
const step = code === 0 ? re.green("\u2713") : code === 1 ? re.red("\u2717") : re.red("\u2717");
|
|
134
|
+
const finalText = text ?? state.text;
|
|
135
|
+
if (options.indicator === "timer") {
|
|
136
|
+
process.stdout.write(
|
|
137
|
+
`${step} ${finalText} ${formatTimer(state.origin)}
|
|
138
|
+
`
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
process.stdout.write(`${step} ${finalText}
|
|
142
|
+
`);
|
|
143
|
+
}
|
|
144
|
+
clearHooks();
|
|
145
|
+
if (unblock) unblock();
|
|
146
|
+
},
|
|
147
|
+
setText: (text) => {
|
|
148
|
+
state.text = removeTrailingDots(text);
|
|
149
|
+
options.text = text;
|
|
150
|
+
},
|
|
151
|
+
setProgress: (progress) => {
|
|
152
|
+
const progressText = formatProgress(progress);
|
|
153
|
+
const newText = `${state.text} [${progressText}]`;
|
|
154
|
+
state.text = newText;
|
|
155
|
+
options.text = newText;
|
|
156
|
+
},
|
|
157
|
+
succeed: (text) => {
|
|
158
|
+
const successText = text ?? options.successText ?? state.text;
|
|
159
|
+
controls.stop(successText, 0);
|
|
160
|
+
},
|
|
161
|
+
fail: (text) => {
|
|
162
|
+
const failText = text ?? options.failText ?? state.text;
|
|
163
|
+
controls.stop(failText, 2);
|
|
164
|
+
},
|
|
165
|
+
warn: (text) => {
|
|
166
|
+
const warnText = text ?? state.text;
|
|
167
|
+
controls.stop(warnText, 0);
|
|
168
|
+
},
|
|
169
|
+
info: (text) => {
|
|
170
|
+
const infoText = text ?? state.text;
|
|
171
|
+
controls.stop(infoText, 0);
|
|
172
|
+
},
|
|
173
|
+
isSpinning: () => {
|
|
174
|
+
return state.isActive && !state.isPaused;
|
|
175
|
+
},
|
|
176
|
+
clear: () => {
|
|
177
|
+
clearPrevMessage();
|
|
178
|
+
},
|
|
179
|
+
getElapsedTime: () => {
|
|
180
|
+
if (!state.startTime) return 0;
|
|
181
|
+
const currentTime = Date.now();
|
|
182
|
+
return currentTime - state.startTime - state.pausedTime;
|
|
183
|
+
},
|
|
184
|
+
pause: () => {
|
|
185
|
+
if (state.isActive && !state.isPaused) {
|
|
186
|
+
clearInterval(loop);
|
|
187
|
+
state.isPaused = true;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
resume: () => {
|
|
191
|
+
if (state.isActive && state.isPaused) {
|
|
192
|
+
loop = setInterval(() => {
|
|
193
|
+
}, options.delay ?? defaultDelay);
|
|
194
|
+
state.isPaused = false;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
dispose: () => {
|
|
198
|
+
if (state.isActive) {
|
|
199
|
+
controls.stop();
|
|
200
|
+
}
|
|
201
|
+
state.isActive = false;
|
|
202
|
+
state.isPaused = false;
|
|
203
|
+
},
|
|
204
|
+
get isCancelled() {
|
|
205
|
+
return state.isCancelled;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
return controls;
|
|
209
|
+
}
|
|
210
|
+
useSpinner.promise = async (operation, options) => {
|
|
211
|
+
const spinner = useSpinner(options).start();
|
|
212
|
+
try {
|
|
213
|
+
const result = await operation(spinner);
|
|
214
|
+
spinner.succeed();
|
|
215
|
+
return result;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
spinner.fail();
|
|
218
|
+
throw error;
|
|
219
|
+
} finally {
|
|
220
|
+
spinner.dispose();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
useSpinner.nested = (parentOptions) => {
|
|
224
|
+
const parentSpinner = useSpinner({
|
|
225
|
+
...parentOptions,
|
|
226
|
+
silent: true
|
|
227
|
+
// Parent is silent, children will show progress
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
start: () => {
|
|
231
|
+
parentSpinner.start();
|
|
232
|
+
return {
|
|
233
|
+
child: (childOptions) => useSpinner(childOptions),
|
|
234
|
+
finish: (success, text) => {
|
|
235
|
+
if (success) {
|
|
236
|
+
parentSpinner.succeed(text);
|
|
237
|
+
} else {
|
|
238
|
+
parentSpinner.fail(text);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
dispose: () => parentSpinner.dispose()
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
useSpinner.withTiming = async (operation, options) => {
|
|
247
|
+
const spinner = useSpinner(options).start();
|
|
248
|
+
const startTime = Date.now();
|
|
249
|
+
try {
|
|
250
|
+
const result = await operation(spinner);
|
|
251
|
+
const duration = Date.now() - startTime;
|
|
252
|
+
spinner.succeed(`${options.successText || options.text} (${duration}ms)`);
|
|
253
|
+
return { result, duration };
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const duration = Date.now() - startTime;
|
|
256
|
+
spinner.fail(
|
|
257
|
+
`${options.failText || options.text} (failed after ${duration}ms)`
|
|
258
|
+
);
|
|
259
|
+
throw error;
|
|
260
|
+
} finally {
|
|
261
|
+
spinner.dispose();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ProgressBar, ProgressBarOptions } from "../../types.js";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function taskProgressPrompt(options: ProgressBarOptions): Promise<ProgressBar>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { re } from "@reliverse/relico";
|
|
2
2
|
import { cursor, erase } from "sisteransi";
|
|
3
|
-
export async function
|
|
3
|
+
export async function taskProgressPrompt(options) {
|
|
4
4
|
if (options.total <= 0) {
|
|
5
5
|
throw new Error("Total must be a positive number");
|
|
6
6
|
}
|
|
@@ -2,7 +2,7 @@ import type { SpinnerName } from "cli-spinners";
|
|
|
2
2
|
type SimpleSpinnerType = "default" | "dottedCircle" | "boxSpinner";
|
|
3
3
|
type OraSpinnerType = Extract<SpinnerName, OraAllowedSpinners>;
|
|
4
4
|
type OraAllowedSpinners = "dots" | "bouncingBar" | "arc";
|
|
5
|
-
|
|
5
|
+
interface TaskOptions<T extends "simple" | "ora"> {
|
|
6
6
|
initialMessage: string;
|
|
7
7
|
successMessage?: string;
|
|
8
8
|
errorMessage?: string;
|
|
@@ -10,6 +10,6 @@ type TaskOptions<T extends "simple" | "ora"> = {
|
|
|
10
10
|
spinnerSolution: T;
|
|
11
11
|
spinnerType?: T extends "simple" ? SimpleSpinnerType : OraSpinnerType;
|
|
12
12
|
action: (updateMessage: (message: string) => void) => Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare function
|
|
13
|
+
}
|
|
14
|
+
export declare function taskSpinPrompt<T extends "simple" | "ora">(options: TaskOptions<T>): Promise<void>;
|
|
15
15
|
export {};
|
|
@@ -3,7 +3,7 @@ import process from "node:process";
|
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import { cursor, erase } from "sisteransi";
|
|
5
5
|
import { msg } from "../msg-fmt/messages.js";
|
|
6
|
-
export async function
|
|
6
|
+
export async function taskSpinPrompt(options) {
|
|
7
7
|
const {
|
|
8
8
|
initialMessage,
|
|
9
9
|
successMessage = "Task completed successfully.",
|
package/bin/mod.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { anykeyPrompt } from "./components/anykey/anykey-mod.js";
|
|
|
2
2
|
export { datePrompt } from "./components/date/date.js";
|
|
3
3
|
export { startEditor } from "./components/editor/editor-mod.js";
|
|
4
4
|
export { mainSymbols, fallbackSymbols, } from "./components/figures/figures-mod.js";
|
|
5
|
-
export { confirmPrompt } from "./components/
|
|
5
|
+
export { confirmPrompt } from "./components/confirm/confirm-prompt.js";
|
|
6
6
|
export { inputPrompt } from "./components/input/input-prompt.js";
|
|
7
7
|
export * from "./components/launcher/launcher-types.js";
|
|
8
8
|
export { defineCommand, defineArgs, showUsage, runMain, runCmd, } from "./components/launcher/launcher-mod.js";
|
|
@@ -22,10 +22,10 @@ export { numMultiSelectPrompt } from "./components/select/nummultiselect-prompt.
|
|
|
22
22
|
export { numSelectPrompt } from "./components/select/numselect-prompt.js";
|
|
23
23
|
export { selectPrompt } from "./components/select/select-prompt.js";
|
|
24
24
|
export { togglePrompt } from "./components/select/toggle-prompt.js";
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
25
|
+
export { introPrompt } from "./components/intro/intro-start.js";
|
|
26
|
+
export { outroPrompt } from "./components/outro/outro-end.js";
|
|
27
|
+
export { taskProgressPrompt } from "./components/task/progress.js";
|
|
28
|
+
export { taskSpinPrompt } from "./components/task/task-spin.js";
|
|
29
29
|
export { colorize } from "./utils/colorize.js";
|
|
30
30
|
export { errorHandler } from "./utils/errors.js";
|
|
31
31
|
export { preventUnsupportedTTY, preventWindowsHomeDirRoot, preventWrongTerminalSize, } from "./utils/prevent.js";
|
|
@@ -33,6 +33,9 @@ export { completePrompt, renderEndLine, renderEndLineInput, } from "./utils/prom
|
|
|
33
33
|
export { streamText, streamTextBox, streamTextWithSpinner, } from "./utils/stream-text.js";
|
|
34
34
|
export { pm, reliversePrompts } from "./utils/system.js";
|
|
35
35
|
export { isTerminalInteractive, isValidName, normalizeName, } from "./utils/validate.js";
|
|
36
|
-
export { animationMap, animateText, } from "./components/
|
|
37
|
-
export { createAsciiArt } from "./components/
|
|
38
|
-
export { useSpinner } from "./
|
|
36
|
+
export { animationMap, animateText, } from "./components/animate/animate.js";
|
|
37
|
+
export { createAsciiArt } from "./components/ascii-art/ascii-art.js";
|
|
38
|
+
export { useSpinner } from "./components/spinner/spinner-mod.js";
|
|
39
|
+
export { log } from "./components/log/log.js";
|
|
40
|
+
export { cancel, isCancel, createCancel, CANCEL, block, setRawMode, getColumns, isWindows, type CancelValue, } from "./components/cancel/cancel.js";
|
|
41
|
+
export { password, input, text, multiselect, select, startPrompt, intro, endPrompt, outro, spinner, } from "./components/aliases/aliases-mod.js";
|
package/bin/mod.js
CHANGED
|
@@ -5,7 +5,7 @@ export {
|
|
|
5
5
|
mainSymbols,
|
|
6
6
|
fallbackSymbols
|
|
7
7
|
} from "./components/figures/figures-mod.js";
|
|
8
|
-
export { confirmPrompt } from "./components/
|
|
8
|
+
export { confirmPrompt } from "./components/confirm/confirm-prompt.js";
|
|
9
9
|
export { inputPrompt } from "./components/input/input-prompt.js";
|
|
10
10
|
export * from "./components/launcher/launcher-types.js";
|
|
11
11
|
export {
|
|
@@ -56,10 +56,10 @@ export { numMultiSelectPrompt } from "./components/select/nummultiselect-prompt.
|
|
|
56
56
|
export { numSelectPrompt } from "./components/select/numselect-prompt.js";
|
|
57
57
|
export { selectPrompt } from "./components/select/select-prompt.js";
|
|
58
58
|
export { togglePrompt } from "./components/select/toggle-prompt.js";
|
|
59
|
-
export {
|
|
60
|
-
export {
|
|
61
|
-
export {
|
|
62
|
-
export {
|
|
59
|
+
export { introPrompt } from "./components/intro/intro-start.js";
|
|
60
|
+
export { outroPrompt } from "./components/outro/outro-end.js";
|
|
61
|
+
export { taskProgressPrompt } from "./components/task/progress.js";
|
|
62
|
+
export { taskSpinPrompt } from "./components/task/task-spin.js";
|
|
63
63
|
export { colorize } from "./utils/colorize.js";
|
|
64
64
|
export { errorHandler } from "./utils/errors.js";
|
|
65
65
|
export {
|
|
@@ -86,6 +86,29 @@ export {
|
|
|
86
86
|
export {
|
|
87
87
|
animationMap,
|
|
88
88
|
animateText
|
|
89
|
-
} from "./components/
|
|
90
|
-
export { createAsciiArt } from "./components/
|
|
91
|
-
export { useSpinner } from "./
|
|
89
|
+
} from "./components/animate/animate.js";
|
|
90
|
+
export { createAsciiArt } from "./components/ascii-art/ascii-art.js";
|
|
91
|
+
export { useSpinner } from "./components/spinner/spinner-mod.js";
|
|
92
|
+
export { log } from "./components/log/log.js";
|
|
93
|
+
export {
|
|
94
|
+
cancel,
|
|
95
|
+
isCancel,
|
|
96
|
+
createCancel,
|
|
97
|
+
CANCEL,
|
|
98
|
+
block,
|
|
99
|
+
setRawMode,
|
|
100
|
+
getColumns,
|
|
101
|
+
isWindows
|
|
102
|
+
} from "./components/cancel/cancel.js";
|
|
103
|
+
export {
|
|
104
|
+
password,
|
|
105
|
+
input,
|
|
106
|
+
text,
|
|
107
|
+
multiselect,
|
|
108
|
+
select,
|
|
109
|
+
startPrompt,
|
|
110
|
+
intro,
|
|
111
|
+
endPrompt,
|
|
112
|
+
outro,
|
|
113
|
+
spinner
|
|
114
|
+
} from "./components/aliases/aliases-mod.js";
|