@reliverse/rempts 1.7.57 → 1.7.59
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 +5 -7
- package/bin/libs/animate/{animate-mod.js → animate-mod.ts.txt} +33 -15
- package/bin/libs/figures/figures-mod.d.ts +2 -2
- package/bin/libs/intro/intro-mod.d.ts +1 -2
- package/bin/libs/intro/intro-mod.js +2 -8
- package/bin/libs/outro/outro-mod.d.ts +1 -2
- package/bin/libs/outro/outro-mod.js +4 -10
- package/bin/libs/select/select-prompt.js +3 -0
- package/bin/libs/spinner/spinner-impl.d.ts +70 -0
- package/bin/libs/spinner/spinner-impl.js +336 -0
- package/bin/libs/spinner/spinner-mod.d.ts +256 -101
- package/bin/libs/spinner/spinner-mod.js +427 -231
- package/bin/libs/utils/prompt-end.js +3 -1
- package/bin/libs/utils/stream-text.js +2 -2
- package/bin/libs/visual/{visual-mod.js → visual-mod.ts.txt} +9 -3
- package/bin/mod.d.ts +2 -7
- package/bin/mod.js +25 -11
- package/bin/types.d.ts +4 -3
- package/package.json +10 -5
- package/bin/libs/animate/animate-mod.d.ts +0 -14
- package/bin/libs/msg-fmt/logger.d.ts +0 -17
- package/bin/libs/msg-fmt/logger.js +0 -103
- package/bin/libs/spinner/spinner-alias.d.ts +0 -2
- package/bin/libs/spinner/spinner-alias.js +0 -2
- package/bin/libs/task/progress.d.ts +0 -2
- package/bin/libs/task/progress.js +0 -57
- package/bin/libs/task/task-spin.d.ts +0 -15
- package/bin/libs/task/task-spin.js +0 -106
- package/bin/libs/visual/visual-mod.d.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { re } from "@reliverse/relico";
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
3
|
import { msg, symbols } from "../msg-fmt/messages.js";
|
|
4
|
-
import { getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
4
|
+
import { deleteLastLine, getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
5
5
|
export async function completePrompt(prompt, isCtrlC, _endTitle = "", _endTitleColor = "dim", _titleTypography = "none", _titleVariant, _border = true, borderColor = "dim", action, value) {
|
|
6
6
|
if (action && value) {
|
|
7
7
|
await action();
|
|
@@ -13,10 +13,12 @@ export async function completePrompt(prompt, isCtrlC, _endTitle = "", _endTitleC
|
|
|
13
13
|
if (isCtrlC) {
|
|
14
14
|
renderEndLine();
|
|
15
15
|
} else {
|
|
16
|
+
deleteLastLine();
|
|
16
17
|
msg({
|
|
17
18
|
type: "M_BAR",
|
|
18
19
|
borderColor
|
|
19
20
|
});
|
|
21
|
+
renderEndLineInput();
|
|
20
22
|
}
|
|
21
23
|
return value ?? false;
|
|
22
24
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { stdout } from "node:process";
|
|
2
2
|
import { re } from "@reliverse/relico";
|
|
3
|
-
import ora from "ora";
|
|
4
3
|
import { cursor } from "sisteransi";
|
|
5
4
|
import terminalSize from "terminal-size";
|
|
6
5
|
import wrapAnsi from "wrap-ansi";
|
|
7
6
|
import { toBaseColor } from "../msg-fmt/colors.js";
|
|
8
7
|
import { colorMap } from "../msg-fmt/mapping.js";
|
|
9
8
|
import { msg } from "../msg-fmt/messages.js";
|
|
9
|
+
import ora from "../spinner/spinner-impl.js";
|
|
10
10
|
function getTerminalWidth() {
|
|
11
11
|
return terminalSize().columns;
|
|
12
12
|
}
|
|
@@ -126,7 +126,7 @@ export async function streamTextWithSpinner({
|
|
|
126
126
|
...baseColor !== void 0 && { color: baseColor },
|
|
127
127
|
spinner: spinnerFrames ? {
|
|
128
128
|
frames: spinnerFrames,
|
|
129
|
-
|
|
129
|
+
interval: spinnerDelay ?? 80
|
|
130
130
|
} : "dots"
|
|
131
131
|
}).start();
|
|
132
132
|
for (const char of text) {
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { relinka } from "@reliverse/relinka";
|
|
2
|
-
import figlet from "figlet";
|
|
2
|
+
// import figlet, { type Fonts } from "figlet";
|
|
3
|
+
|
|
3
4
|
export async function createAsciiArt({
|
|
4
5
|
message,
|
|
5
6
|
font = "Standard",
|
|
6
|
-
clearConsole = false
|
|
7
|
-
}
|
|
7
|
+
clearConsole = false,
|
|
8
|
+
}: {
|
|
9
|
+
message: string;
|
|
10
|
+
font?: Fonts;
|
|
11
|
+
clearConsole?: boolean;
|
|
12
|
+
}): Promise<void> {
|
|
8
13
|
if (clearConsole) {
|
|
9
14
|
relinka("clear", "");
|
|
10
15
|
}
|
|
16
|
+
|
|
11
17
|
const asciiArt = figlet.textSync(message, { font });
|
|
12
18
|
relinka("log", asciiArt);
|
|
13
19
|
}
|
package/bin/mod.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { animateText, animationMap } from "./libs/animate/animate-mod";
|
|
2
1
|
export { anykeyPrompt } from "./libs/anykey/anykey-mod";
|
|
3
2
|
export type { CancelValue } from "./libs/cancel/cancel";
|
|
4
3
|
export { block, CANCEL, cancel, createCancel, getColumns, isCancel, isWindows, setRawMode, } from "./libs/cancel/cancel";
|
|
@@ -20,7 +19,6 @@ export { createCli, defineArgs, defineCommand, showUsage, } from "./libs/launche
|
|
|
20
19
|
export type { ArgDefinition, ArgDefinitions, ArrayArgDefinition, BaseArgDefinition, BaseArgProps, BooleanArgDefinition, Command, CommandContext, CommandHook, CommandMeta, CommandRun, CommandSpec, CommandsMap, DefineCommandOptions, EmptyArgs, FileBasedOptions, InferArgTypes, NumberArgDefinition, PositionalArgDefinition, StringArgDefinition, } from "./libs/launcher/launcher-types";
|
|
21
20
|
export { log } from "./libs/log/log-alias";
|
|
22
21
|
export { toBaseColor, toSolidColor } from "./libs/msg-fmt/colors";
|
|
23
|
-
export { relinkaAsyncByRemptsDeprecated, relinkaByRemptsDeprecated, throwError, } from "./libs/msg-fmt/logger";
|
|
24
22
|
export { colorMap, typographyMap } from "./libs/msg-fmt/mapping";
|
|
25
23
|
export { bar, fmt, msg, msgUndo, msgUndoAll, printLineBar, symbols, } from "./libs/msg-fmt/messages";
|
|
26
24
|
export { breakLines, countLines, deleteLastLine, deleteLastLines, getExactTerminalWidth, getTerminalHeight, getTerminalWidth, removeCursor, restoreCursor, } from "./libs/msg-fmt/terminal";
|
|
@@ -38,10 +36,8 @@ export { numSelectPrompt } from "./libs/select/numselect-prompt";
|
|
|
38
36
|
export { select, selectSimple } from "./libs/select/select-alias";
|
|
39
37
|
export { selectPrompt } from "./libs/select/select-prompt";
|
|
40
38
|
export { togglePrompt } from "./libs/select/toggle-prompt";
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export { taskProgressPrompt } from "./libs/task/progress";
|
|
44
|
-
export { taskSpinPrompt } from "./libs/task/task-spin";
|
|
39
|
+
export type { FileProgressOptions, SimpleSpinner, SpinnerGroupOptions, SpinnerOptions, } from "./libs/spinner/spinner-mod";
|
|
40
|
+
export { createBuildSpinner, createFileProgressSpinner, createMultiStepSpinner, createSpinner, createSpinnerGroup, createTimedSpinner, createTransferSpinner, defaultSpinnerOptions, formatSpinnerBytes, formatSpinnerElapsed, formatSpinnerTiming, isSpinnerEnabled, isSpinnerRunning, prettyBytes, prettyMilliseconds, randomSpinner, safeStopSpinner, spinners, stopAndPersist, updateSpinnerText, withEnhancedSpinner, withSpinner, withSpinnerPromise, } from "./libs/spinner/spinner-mod";
|
|
45
41
|
export { colorize } from "./libs/utils/colorize";
|
|
46
42
|
export { errorHandler } from "./libs/utils/errors";
|
|
47
43
|
export { preventUnsupportedTTY, preventWindowsHomeDirRoot, preventWrongTerminalSize, } from "./libs/utils/prevent";
|
|
@@ -49,5 +45,4 @@ export { completePrompt, renderEndLine, renderEndLineInput, } from "./libs/utils
|
|
|
49
45
|
export { streamText, streamTextBox, streamTextWithSpinner, } from "./libs/utils/stream-text";
|
|
50
46
|
export { pm, reliversePrompts } from "./libs/utils/system";
|
|
51
47
|
export { isTerminalInteractive, isValidName, normalizeName, } from "./libs/utils/validate";
|
|
52
|
-
export { createAsciiArt } from "./libs/visual/visual-mod";
|
|
53
48
|
export type { AllKinds, BorderColorName, ChoiceOptions, ColorName, ConfirmPromptOptions, DatePromptOptions, EditorExitResult, FmtMsgOptions, InputPromptOptions, MessageConfig, MessageKind, MsgConfig, MsgType, MultiselectPromptParams, OutputColor, PreventWrongTerminalSizeOptions, ProgressBar, ProgressBarOptions, PromptOptions, PromptType, RenderParams, SelectOption, SelectPromptParams, SeparatorOption, StandardColor, StreamOptions, StreamTextOptions, SymbolName, Symbols, TogglePromptParams, TypographyName, VariantName, } from "./types";
|
package/bin/mod.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { animateText, animationMap } from "./libs/animate/animate-mod.js";
|
|
2
1
|
export { anykeyPrompt } from "./libs/anykey/anykey-mod.js";
|
|
3
2
|
export {
|
|
4
3
|
block,
|
|
@@ -34,11 +33,6 @@ export {
|
|
|
34
33
|
} from "./libs/launcher/launcher-mod.js";
|
|
35
34
|
export { log } from "./libs/log/log-alias.js";
|
|
36
35
|
export { toBaseColor, toSolidColor } from "./libs/msg-fmt/colors.js";
|
|
37
|
-
export {
|
|
38
|
-
relinkaAsyncByRemptsDeprecated,
|
|
39
|
-
relinkaByRemptsDeprecated,
|
|
40
|
-
throwError
|
|
41
|
-
} from "./libs/msg-fmt/logger.js";
|
|
42
36
|
export { colorMap, typographyMap } from "./libs/msg-fmt/mapping.js";
|
|
43
37
|
export {
|
|
44
38
|
bar,
|
|
@@ -77,10 +71,31 @@ export { numSelectPrompt } from "./libs/select/numselect-prompt.js";
|
|
|
77
71
|
export { select, selectSimple } from "./libs/select/select-alias.js";
|
|
78
72
|
export { selectPrompt } from "./libs/select/select-prompt.js";
|
|
79
73
|
export { togglePrompt } from "./libs/select/toggle-prompt.js";
|
|
80
|
-
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
export {
|
|
75
|
+
createBuildSpinner,
|
|
76
|
+
createFileProgressSpinner,
|
|
77
|
+
createMultiStepSpinner,
|
|
78
|
+
createSpinner,
|
|
79
|
+
createSpinnerGroup,
|
|
80
|
+
createTimedSpinner,
|
|
81
|
+
createTransferSpinner,
|
|
82
|
+
defaultSpinnerOptions,
|
|
83
|
+
formatSpinnerBytes,
|
|
84
|
+
formatSpinnerElapsed,
|
|
85
|
+
formatSpinnerTiming,
|
|
86
|
+
isSpinnerEnabled,
|
|
87
|
+
isSpinnerRunning,
|
|
88
|
+
prettyBytes,
|
|
89
|
+
prettyMilliseconds,
|
|
90
|
+
randomSpinner,
|
|
91
|
+
safeStopSpinner,
|
|
92
|
+
spinners,
|
|
93
|
+
stopAndPersist,
|
|
94
|
+
updateSpinnerText,
|
|
95
|
+
withEnhancedSpinner,
|
|
96
|
+
withSpinner,
|
|
97
|
+
withSpinnerPromise
|
|
98
|
+
} from "./libs/spinner/spinner-mod.js";
|
|
84
99
|
export { colorize } from "./libs/utils/colorize.js";
|
|
85
100
|
export { errorHandler } from "./libs/utils/errors.js";
|
|
86
101
|
export {
|
|
@@ -104,4 +119,3 @@ export {
|
|
|
104
119
|
isValidName,
|
|
105
120
|
normalizeName
|
|
106
121
|
} from "./libs/utils/validate.js";
|
|
107
|
-
export { createAsciiArt } from "./libs/visual/visual-mod.js";
|
package/bin/types.d.ts
CHANGED
|
@@ -91,9 +91,10 @@ export interface MessageConfig {
|
|
|
91
91
|
}
|
|
92
92
|
export interface StreamOptions {
|
|
93
93
|
delay?: number;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
spinner?: {
|
|
95
|
+
frames?: string[];
|
|
96
|
+
delay?: number;
|
|
97
|
+
};
|
|
97
98
|
}
|
|
98
99
|
export interface ProgressBarOptions {
|
|
99
100
|
total: number;
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@figliolia/chalk-animation": "^1.0.4",
|
|
4
3
|
"@reliverse/relico": "^1.3.9",
|
|
5
|
-
"@reliverse/relinka": "^1.6.
|
|
4
|
+
"@reliverse/relinka": "^1.6.1",
|
|
6
5
|
"@reliverse/reltime": "^1.1.1",
|
|
7
6
|
"ansi-escapes": "^7.0.0",
|
|
7
|
+
"cli-cursor": "^5.0.0",
|
|
8
8
|
"cli-spinners": "^3.2.0",
|
|
9
|
-
"figlet": "^1.8.2",
|
|
10
9
|
"gradient-string": "^3.0.0",
|
|
10
|
+
"is-interactive": "^2.0.0",
|
|
11
|
+
"is-unicode-supported": "^2.1.0",
|
|
11
12
|
"log-update": "^6.1.0",
|
|
12
|
-
"ora": "^8.2.0",
|
|
13
13
|
"pkg-types": "^2.3.0",
|
|
14
|
+
"pretty-bytes": "^7.0.1",
|
|
15
|
+
"pretty-ms": "^9.2.0",
|
|
14
16
|
"sisteransi": "^1.0.5",
|
|
17
|
+
"stdin-discarder": "^0.2.2",
|
|
18
|
+
"string-width": "^8.0.0",
|
|
19
|
+
"strip-ansi": "^7.1.0",
|
|
15
20
|
"terminal-size": "^4.0.0",
|
|
16
21
|
"ts-regex-builder": "^1.8.2",
|
|
17
22
|
"wrap-ansi": "^9.0.0"
|
|
@@ -21,7 +26,7 @@
|
|
|
21
26
|
"license": "MIT",
|
|
22
27
|
"name": "@reliverse/rempts",
|
|
23
28
|
"type": "module",
|
|
24
|
-
"version": "1.7.
|
|
29
|
+
"version": "1.7.59",
|
|
25
30
|
"author": "reliverse",
|
|
26
31
|
"bugs": {
|
|
27
32
|
"email": "blefnk@gmail.com",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type Animation, type AnimationName } from "@figliolia/chalk-animation";
|
|
2
|
-
import type { BorderColorName, ColorName, MsgType, TypographyName } from "../../types";
|
|
3
|
-
export declare const animationMap: Record<AnimationName, (text: string) => Animation>;
|
|
4
|
-
export declare function animateText({ title, anim, delay, type, titleColor, titleTypography, border, borderColor, horizontalLineLength, }: {
|
|
5
|
-
title: string;
|
|
6
|
-
anim: AnimationName;
|
|
7
|
-
delay?: number;
|
|
8
|
-
type?: MsgType;
|
|
9
|
-
titleColor?: ColorName;
|
|
10
|
-
titleTypography?: TypographyName;
|
|
11
|
-
borderColor?: BorderColorName;
|
|
12
|
-
border?: boolean;
|
|
13
|
-
horizontalLineLength?: number;
|
|
14
|
-
}): Promise<void>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AllKinds, StreamOptions } from "../../types";
|
|
2
|
-
/**
|
|
3
|
-
* Logs messages with configurable styling and formatting.
|
|
4
|
-
* Doesn't support streaming functionality.
|
|
5
|
-
*/
|
|
6
|
-
export declare function relinkaByRemptsDeprecated(kind: AllKinds, title: string, content?: string, hint?: string): void;
|
|
7
|
-
/**
|
|
8
|
-
* Asynchronous version of relinka that supports streaming functionality.
|
|
9
|
-
* Use this when you want animated text output with optional spinner.
|
|
10
|
-
*
|
|
11
|
-
* Streaming is controlled by the streamOpts parameter:
|
|
12
|
-
* - Use { useSpinner: true } for spinner animation
|
|
13
|
-
* - Use { delay: number } for character-by-character streaming
|
|
14
|
-
* - Content and hint are optional regardless of streaming
|
|
15
|
-
*/
|
|
16
|
-
export declare const relinkaAsyncByRemptsDeprecated: (kind: AllKinds, title: string, content?: string, hint?: string, streamOpts?: StreamOptions) => Promise<void>;
|
|
17
|
-
export declare const throwError: (error: unknown) => never;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { streamText, streamTextWithSpinner } from "../utils/stream-text.js";
|
|
2
|
-
import { toSolidColor } from "./colors.js";
|
|
3
|
-
import { msg } from "./messages.js";
|
|
4
|
-
const verboseLogging = false;
|
|
5
|
-
const MESSAGE_CONFIGS = {
|
|
6
|
-
log: {
|
|
7
|
-
type: "M_INFO",
|
|
8
|
-
titleColor: "retroGradient",
|
|
9
|
-
titleTypography: "bold"
|
|
10
|
-
},
|
|
11
|
-
info: {
|
|
12
|
-
type: "M_INFO",
|
|
13
|
-
titleColor: "retroGradient",
|
|
14
|
-
titleTypography: "bold"
|
|
15
|
-
},
|
|
16
|
-
success: {
|
|
17
|
-
type: "M_INFO",
|
|
18
|
-
titleColor: "viceGradient",
|
|
19
|
-
titleTypography: "bold"
|
|
20
|
-
},
|
|
21
|
-
warn: {
|
|
22
|
-
type: "M_ERROR",
|
|
23
|
-
titleColor: "yellowBright",
|
|
24
|
-
titleTypography: "bold"
|
|
25
|
-
},
|
|
26
|
-
error: {
|
|
27
|
-
type: "M_ERROR",
|
|
28
|
-
titleColor: "yellowBright",
|
|
29
|
-
titleTypography: "bold"
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export function relinkaByRemptsDeprecated(kind, title, content, hint) {
|
|
33
|
-
const isVerbose = kind.endsWith("-verbose");
|
|
34
|
-
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
35
|
-
if (isVerbose && !verboseLogging) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const config = MESSAGE_CONFIGS[baseKind];
|
|
39
|
-
msg({
|
|
40
|
-
...config,
|
|
41
|
-
title: isVerbose ? `[debug] ${title}` : title,
|
|
42
|
-
content: content ?? "",
|
|
43
|
-
contentColor: "dim",
|
|
44
|
-
contentTypography: "italic",
|
|
45
|
-
hint: hint ?? ""
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
export const relinkaAsyncByRemptsDeprecated = async (kind, title, content, hint, streamOpts) => {
|
|
49
|
-
const isVerbose = kind.endsWith("-verbose");
|
|
50
|
-
const baseKind = isVerbose ? kind.replace("-verbose", "") : kind;
|
|
51
|
-
if (isVerbose && !verboseLogging) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const config = MESSAGE_CONFIGS[baseKind];
|
|
55
|
-
if (!streamOpts) {
|
|
56
|
-
msg({
|
|
57
|
-
...config,
|
|
58
|
-
title: isVerbose ? `[debug] ${title}` : title,
|
|
59
|
-
content: content ?? "",
|
|
60
|
-
contentColor: "dim",
|
|
61
|
-
contentTypography: "italic",
|
|
62
|
-
hint: hint ?? ""
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const titleText = isVerbose ? `[debug] ${title}` : title;
|
|
67
|
-
if (streamOpts.useSpinner) {
|
|
68
|
-
await streamTextWithSpinner({
|
|
69
|
-
text: titleText,
|
|
70
|
-
color: toSolidColor(config.titleColor),
|
|
71
|
-
...streamOpts.delay !== void 0 && { delay: streamOpts.delay },
|
|
72
|
-
...streamOpts.spinnerFrames !== void 0 && { spinnerFrames: streamOpts.spinnerFrames },
|
|
73
|
-
...streamOpts.spinnerDelay !== void 0 && { spinnerDelay: streamOpts.spinnerDelay }
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
await streamText({
|
|
77
|
-
text: titleText,
|
|
78
|
-
color: toSolidColor(config.titleColor),
|
|
79
|
-
...streamOpts.delay !== void 0 && { delay: streamOpts.delay }
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (content) {
|
|
83
|
-
await streamText({
|
|
84
|
-
text: content,
|
|
85
|
-
color: toSolidColor(config.contentColor) ?? "dim",
|
|
86
|
-
...streamOpts.delay !== void 0 && { delay: streamOpts.delay }
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (hint) {
|
|
90
|
-
await streamText({
|
|
91
|
-
text: hint,
|
|
92
|
-
color: "dim",
|
|
93
|
-
...streamOpts.delay !== void 0 && { delay: streamOpts.delay }
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
export const throwError = (error) => {
|
|
98
|
-
msg({
|
|
99
|
-
type: "M_ERROR",
|
|
100
|
-
title: error instanceof Error ? `\u{1F914} Failed to set up the project: ${error.message}` : "\u{1F914} An unknown error occurred."
|
|
101
|
-
});
|
|
102
|
-
process.exit(1);
|
|
103
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { re } from "@reliverse/relico";
|
|
2
|
-
import { cursor, erase } from "sisteransi";
|
|
3
|
-
export async function taskProgressPrompt(options) {
|
|
4
|
-
if (options.total <= 0) {
|
|
5
|
-
throw new Error("Total must be a positive number");
|
|
6
|
-
}
|
|
7
|
-
const state = {
|
|
8
|
-
total: options.total,
|
|
9
|
-
current: 0,
|
|
10
|
-
width: options.width ?? 40,
|
|
11
|
-
completeChar: options.completeChar ?? "\u2588",
|
|
12
|
-
incompleteChar: options.incompleteChar ?? "\u2591",
|
|
13
|
-
startTime: Date.now(),
|
|
14
|
-
format: options.format ?? "Progress: [:bar] :percent% | Elapsed: :elapsed s",
|
|
15
|
-
colorize: options.colorize ?? false
|
|
16
|
-
};
|
|
17
|
-
const getElapsedTime = () => {
|
|
18
|
-
return ((Date.now() - state.startTime) / 1e3).toFixed(2);
|
|
19
|
-
};
|
|
20
|
-
const getPercentage = () => {
|
|
21
|
-
return (state.current / state.total * 100).toFixed(2);
|
|
22
|
-
};
|
|
23
|
-
const getBar = () => {
|
|
24
|
-
const percent = state.current / state.total;
|
|
25
|
-
const filledLength = Math.round(state.width * percent);
|
|
26
|
-
const emptyLength = state.width - filledLength;
|
|
27
|
-
const filled = state.completeChar.repeat(filledLength);
|
|
28
|
-
const empty = state.incompleteChar.repeat(emptyLength);
|
|
29
|
-
return state.colorize ? re.green(filled) + re.red(empty) : filled + empty;
|
|
30
|
-
};
|
|
31
|
-
const render = async () => {
|
|
32
|
-
const bar = getBar();
|
|
33
|
-
const percentage = getPercentage();
|
|
34
|
-
const elapsed = getElapsedTime();
|
|
35
|
-
const output = state.format.replace(":bar", bar).replace(":percent", percentage).replace(":elapsed", elapsed);
|
|
36
|
-
process.stdout.write(cursor.move(-999, 0) + erase.line);
|
|
37
|
-
process.stdout.write(`${re.green("\u25C6")} ${output}`);
|
|
38
|
-
if (state.current >= state.total) {
|
|
39
|
-
process.stdout.write("\n");
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const update = async (value) => {
|
|
43
|
-
const newValue = Math.min(value, state.total);
|
|
44
|
-
if (newValue !== state.current) {
|
|
45
|
-
state.current = newValue;
|
|
46
|
-
await render();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const increment = async (amount = 1) => {
|
|
50
|
-
await update(state.current + amount);
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
update,
|
|
54
|
-
increment,
|
|
55
|
-
render
|
|
56
|
-
};
|
|
57
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { SpinnerName } from "cli-spinners";
|
|
2
|
-
type SimpleSpinnerType = "default" | "dottedCircle" | "boxSpinner";
|
|
3
|
-
type OraSpinnerType = Extract<SpinnerName, OraAllowedSpinners>;
|
|
4
|
-
type OraAllowedSpinners = "dots" | "bouncingBar" | "arc";
|
|
5
|
-
interface TaskOptions<T extends "simple" | "ora"> {
|
|
6
|
-
initialMessage: string;
|
|
7
|
-
successMessage?: string;
|
|
8
|
-
errorMessage?: string;
|
|
9
|
-
delay?: number;
|
|
10
|
-
spinnerSolution: T;
|
|
11
|
-
spinnerType?: T extends "simple" ? SimpleSpinnerType : OraSpinnerType;
|
|
12
|
-
action: (updateMessage: (message: string) => void) => Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare function taskSpinPrompt<T extends "simple" | "ora">(options: TaskOptions<T>): Promise<void>;
|
|
15
|
-
export {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import { re } from "@reliverse/relico";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { cursor, erase } from "sisteransi";
|
|
5
|
-
import { msg } from "../msg-fmt/messages.js";
|
|
6
|
-
export async function taskSpinPrompt(options) {
|
|
7
|
-
const {
|
|
8
|
-
initialMessage,
|
|
9
|
-
successMessage = "Task completed successfully.",
|
|
10
|
-
errorMessage = "An error occurred during the task.",
|
|
11
|
-
delay = 100,
|
|
12
|
-
spinnerSolution,
|
|
13
|
-
spinnerType,
|
|
14
|
-
action
|
|
15
|
-
} = options;
|
|
16
|
-
let message = initialMessage;
|
|
17
|
-
let interval = null;
|
|
18
|
-
let frameIndex = 0;
|
|
19
|
-
if (spinnerSolution === "ora") {
|
|
20
|
-
const oraSpinner = ora({
|
|
21
|
-
text: initialMessage,
|
|
22
|
-
spinner: spinnerType
|
|
23
|
-
});
|
|
24
|
-
try {
|
|
25
|
-
oraSpinner.start();
|
|
26
|
-
await action((newMessage) => {
|
|
27
|
-
message = newMessage;
|
|
28
|
-
oraSpinner.text = newMessage;
|
|
29
|
-
});
|
|
30
|
-
oraSpinner.stop();
|
|
31
|
-
msg({
|
|
32
|
-
type: "M_INFO",
|
|
33
|
-
title: successMessage,
|
|
34
|
-
titleColor: "cyan"
|
|
35
|
-
});
|
|
36
|
-
} catch (error) {
|
|
37
|
-
oraSpinner.stopAndPersist({
|
|
38
|
-
symbol: re.red("\u2716"),
|
|
39
|
-
text: errorMessage
|
|
40
|
-
});
|
|
41
|
-
msg({
|
|
42
|
-
type: "M_ERROR",
|
|
43
|
-
title: error instanceof Error ? error.message : "An unknown error occurred.",
|
|
44
|
-
titleColor: "red"
|
|
45
|
-
});
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
const simpleSpinners = {
|
|
50
|
-
default: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
|
|
51
|
-
dottedCircle: ["\u25CB", "\u25D4", "\u25D1", "\u25D5", "\u25CF"],
|
|
52
|
-
boxSpinner: ["\u2596", "\u2598", "\u259D", "\u2597"]
|
|
53
|
-
};
|
|
54
|
-
const frames = spinnerType && spinnerType in simpleSpinners ? simpleSpinners[spinnerType] : simpleSpinners.default;
|
|
55
|
-
const handleInput = (data) => {
|
|
56
|
-
const key = data.toString();
|
|
57
|
-
if (key === "\r" || key === "\n") {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
try {
|
|
62
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
63
|
-
process.stdin.setRawMode(true);
|
|
64
|
-
process.stdin.resume();
|
|
65
|
-
process.stdin.on("data", handleInput);
|
|
66
|
-
}
|
|
67
|
-
interval = setInterval(() => {
|
|
68
|
-
const frame = re.magenta(frames[frameIndex] ?? "");
|
|
69
|
-
process.stdout.write(`${cursor.move(-999, 0)}${erase.line}${frame} ${re.cyan(message)}`);
|
|
70
|
-
frameIndex = (frameIndex + 1) % frames.length;
|
|
71
|
-
}, delay);
|
|
72
|
-
await action((newMessage) => {
|
|
73
|
-
message = newMessage;
|
|
74
|
-
});
|
|
75
|
-
clearInterval(interval);
|
|
76
|
-
interval = null;
|
|
77
|
-
process.stdout.write(`\r${erase.line}${re.green("\u2714")} ${successMessage}
|
|
78
|
-
`);
|
|
79
|
-
msg({
|
|
80
|
-
type: "M_INFO",
|
|
81
|
-
title: successMessage,
|
|
82
|
-
titleColor: "cyan"
|
|
83
|
-
});
|
|
84
|
-
} catch (error) {
|
|
85
|
-
if (interval) {
|
|
86
|
-
clearInterval(interval);
|
|
87
|
-
}
|
|
88
|
-
process.stdout.write(
|
|
89
|
-
`\r${erase.line}${re.red("\u2716")} ${error instanceof Error ? errorMessage : "An unknown error occurred."}
|
|
90
|
-
`
|
|
91
|
-
);
|
|
92
|
-
msg({
|
|
93
|
-
type: "M_ERROR",
|
|
94
|
-
title: error instanceof Error ? error.message : "An unknown error occurred.",
|
|
95
|
-
titleColor: "red"
|
|
96
|
-
});
|
|
97
|
-
process.exit(1);
|
|
98
|
-
} finally {
|
|
99
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
100
|
-
process.stdin.setRawMode(false);
|
|
101
|
-
process.stdin.pause();
|
|
102
|
-
process.stdin.removeListener("data", handleInput);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|