@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
package/README.md
CHANGED
|
@@ -52,10 +52,10 @@ All main prompts APIs are available from the package root:
|
|
|
52
52
|
import {
|
|
53
53
|
// ...prompts
|
|
54
54
|
inputPrompt, selectPrompt, multiselectPrompt, numberPrompt,
|
|
55
|
-
confirmPrompt, togglePrompt,
|
|
55
|
+
confirmPrompt, togglePrompt,
|
|
56
56
|
startPrompt, endPrompt, resultPrompt, nextStepsPrompt,
|
|
57
57
|
// ...hooks
|
|
58
|
-
|
|
58
|
+
createSpinner,
|
|
59
59
|
// ...launcher
|
|
60
60
|
createCli, defineCommand, defineArgs,
|
|
61
61
|
// ...types
|
|
@@ -71,18 +71,16 @@ import {
|
|
|
71
71
|
|
|
72
72
|
| Prompt | Description |
|
|
73
73
|
|---------------------------|-----------------------------------------------------------|
|
|
74
|
-
| `
|
|
74
|
+
| `createSpinner` | Start/stop spinner |
|
|
75
75
|
| `inputPrompt` | Single-line input (with mask support, e.g. for passwords) |
|
|
76
76
|
| `selectPrompt` | Single-choice radio menu |
|
|
77
77
|
| `multiselectPrompt` | Multi-choice checkbox menu |
|
|
78
78
|
| `numberPrompt` | Type-safe number input |
|
|
79
79
|
| `confirmPrompt` | Yes/No toggle |
|
|
80
80
|
| `togglePrompt` | Custom on/off toggles |
|
|
81
|
-
| `taskProgressPrompt` | Progress bar for async tasks |
|
|
82
81
|
| `resultPrompt` | Show results in a styled box |
|
|
83
82
|
| `nextStepsPrompt` | Show next steps in a styled list |
|
|
84
83
|
| `startPrompt`/`endPrompt` | Makes CLI start/end flows look nice |
|
|
85
|
-
| `taskSpinPrompt` | Async loader with spinner (possibly will be deprecated) |
|
|
86
84
|
| `datePrompt` | Date input with format validation |
|
|
87
85
|
| `anykeyPrompt` | Wait for any keypress |
|
|
88
86
|
|
|
@@ -95,7 +93,7 @@ To help you migrate from the different CLI frameworks, `@reliverse/rempts` has s
|
|
|
95
93
|
| `createCli` | `runMain` |
|
|
96
94
|
| `onCmdInit` | `setup` |
|
|
97
95
|
| `onCmdExit` | `cleanup` |
|
|
98
|
-
| `
|
|
96
|
+
| `createSpinner` | `spinner` |
|
|
99
97
|
| `selectPrompt` | `select` |
|
|
100
98
|
| `multiselectPrompt` | `multiselect` |
|
|
101
99
|
| `inputPrompt` | `text`, `input` |
|
|
@@ -125,7 +123,7 @@ async function main() {
|
|
|
125
123
|
defaultValue: "my-cool-project",
|
|
126
124
|
});
|
|
127
125
|
|
|
128
|
-
const spinner =
|
|
126
|
+
const spinner = createSpinner({
|
|
129
127
|
text: "Loading...",
|
|
130
128
|
indicator: "timer", // or "dots"
|
|
131
129
|
frames: ["◒", "◐", "◓", "◑"], // custom frames
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import { ChalkAnimation } from "@figliolia/chalk-animation";
|
|
1
|
+
import { type Animation, type AnimationName, ChalkAnimation } from "@figliolia/chalk-animation";
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import type { BorderColorName, ColorName, MsgType, TypographyName } from "../../types";
|
|
4
|
+
import { msg } from "../msg-fmt/messages";
|
|
5
|
+
import { deleteLastLine, getTerminalWidth } from "../msg-fmt/terminal";
|
|
6
|
+
|
|
7
|
+
export const animationMap: Record<AnimationName, (text: string) => Animation> = {
|
|
6
8
|
rainbow: ChalkAnimation.rainbow,
|
|
7
9
|
pulse: ChalkAnimation.pulse,
|
|
8
10
|
glitch: ChalkAnimation.glitch,
|
|
9
11
|
radar: ChalkAnimation.radar,
|
|
10
12
|
neon: ChalkAnimation.neon,
|
|
11
|
-
karaoke: ChalkAnimation.karaoke
|
|
13
|
+
karaoke: ChalkAnimation.karaoke,
|
|
12
14
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
function calculateDelay(text: string): number {
|
|
17
|
+
const baseDelay = 1000;
|
|
15
18
|
const delayPerCharacter = 50;
|
|
16
19
|
return baseDelay + text.length * delayPerCharacter;
|
|
17
20
|
}
|
|
21
|
+
|
|
18
22
|
export async function animateText({
|
|
19
23
|
title = "",
|
|
20
24
|
anim,
|
|
@@ -24,32 +28,46 @@ export async function animateText({
|
|
|
24
28
|
titleTypography = "none",
|
|
25
29
|
border = true,
|
|
26
30
|
borderColor = "dim",
|
|
27
|
-
horizontalLineLength = 0
|
|
31
|
+
horizontalLineLength = 0,
|
|
32
|
+
}: {
|
|
33
|
+
title: string;
|
|
34
|
+
anim: AnimationName;
|
|
35
|
+
delay?: number;
|
|
36
|
+
type?: MsgType;
|
|
37
|
+
titleColor?: ColorName;
|
|
38
|
+
titleTypography?: TypographyName;
|
|
39
|
+
borderColor?: BorderColorName;
|
|
40
|
+
border?: boolean;
|
|
41
|
+
horizontalLineLength?: number;
|
|
28
42
|
}) {
|
|
29
43
|
if (horizontalLineLength === 0) {
|
|
30
44
|
horizontalLineLength = getTerminalWidth() - 5;
|
|
31
45
|
}
|
|
46
|
+
|
|
32
47
|
const finalDelay = delay ?? calculateDelay(title);
|
|
33
48
|
const animation = animationMap[anim](title);
|
|
49
|
+
|
|
34
50
|
try {
|
|
35
|
-
await new Promise((resolve) => {
|
|
51
|
+
await new Promise<void>((resolve) => {
|
|
36
52
|
setTimeout(() => {
|
|
37
53
|
animation.stop();
|
|
38
54
|
deleteLastLine();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
|
|
56
|
+
if (title.includes("│ ")) {
|
|
57
|
+
title = title.replace("│ ", "");
|
|
58
|
+
} else if (title.includes("ℹ ")) {
|
|
59
|
+
title = title.replace("ℹ ", "");
|
|
43
60
|
}
|
|
61
|
+
|
|
44
62
|
msg({
|
|
45
63
|
type,
|
|
46
|
-
title,
|
|
64
|
+
title: title,
|
|
47
65
|
titleColor,
|
|
48
66
|
titleTypography,
|
|
49
67
|
content: "",
|
|
50
68
|
borderColor,
|
|
51
69
|
border,
|
|
52
|
-
horizontalLineLength
|
|
70
|
+
horizontalLineLength,
|
|
53
71
|
});
|
|
54
72
|
resolve();
|
|
55
73
|
}, finalDelay);
|
|
@@ -229,7 +229,7 @@ export declare const mainSymbols: {
|
|
|
229
229
|
lineSlash: string;
|
|
230
230
|
};
|
|
231
231
|
export declare const fallbackSymbols: Record<string, string>;
|
|
232
|
-
export declare const figures:
|
|
232
|
+
export declare const figures: {
|
|
233
233
|
tick: string;
|
|
234
234
|
info: string;
|
|
235
235
|
warning: string;
|
|
@@ -458,4 +458,4 @@ export declare const figures: Record<string, string> | {
|
|
|
458
458
|
lineCross: string;
|
|
459
459
|
lineBackslash: string;
|
|
460
460
|
lineSlash: string;
|
|
461
|
-
}
|
|
461
|
+
} | Record<string, string>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Fonts } from "figlet";
|
|
2
1
|
import type { PreventWrongTerminalSizeOptions, PromptOptions } from "../../types";
|
|
3
2
|
type StartPromptOptions = PromptOptions & {
|
|
4
3
|
clearConsole?: boolean;
|
|
@@ -14,7 +13,7 @@ type StartPromptOptions = PromptOptions & {
|
|
|
14
13
|
windowsHomeDirRoot?: boolean;
|
|
15
14
|
};
|
|
16
15
|
variant?: "header" | "ascii-art";
|
|
17
|
-
asciiArtFont?:
|
|
16
|
+
asciiArtFont?: any;
|
|
18
17
|
};
|
|
19
18
|
export declare function introPrompt(optionsOrTitle: StartPromptOptions | string): Promise<void>;
|
|
20
19
|
export {};
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
preventWrongTerminalSize
|
|
9
9
|
} from "../utils/prevent.js";
|
|
10
10
|
import { pm, reliversePrompts } from "../utils/system.js";
|
|
11
|
-
import { createAsciiArt } from "../visual/visual-mod.js";
|
|
12
11
|
export async function introPrompt(optionsOrTitle) {
|
|
13
12
|
const options = typeof optionsOrTitle === "string" ? { title: optionsOrTitle } : optionsOrTitle;
|
|
14
13
|
const {
|
|
@@ -29,8 +28,8 @@ export async function introPrompt(optionsOrTitle) {
|
|
|
29
28
|
wrongTerminalSize: true,
|
|
30
29
|
windowsHomeDirRoot: true
|
|
31
30
|
},
|
|
32
|
-
variant = "header"
|
|
33
|
-
asciiArtFont
|
|
31
|
+
variant = "header"
|
|
32
|
+
// asciiArtFont,
|
|
34
33
|
} = options;
|
|
35
34
|
let horizontalLineLength = initialHorizontalLineLength;
|
|
36
35
|
if (prevent.windowsHomeDirRoot) {
|
|
@@ -47,11 +46,6 @@ export async function introPrompt(optionsOrTitle) {
|
|
|
47
46
|
const terminalHeight = getTerminalHeight();
|
|
48
47
|
const formattedTitle = title !== "" ? title : `${packageName} v${packageVersion} | ${pm.packageManager} v${pm.version} | ${getCurrentTerminalName()}${isDev && terminalWidth > 80 ? ` | isDev | w${terminalWidth} h${terminalHeight}` : ""}`;
|
|
49
48
|
if (variant === "ascii-art") {
|
|
50
|
-
await createAsciiArt({
|
|
51
|
-
message: formattedTitle,
|
|
52
|
-
...asciiArtFont !== void 0 && { font: asciiArtFont },
|
|
53
|
-
clearConsole
|
|
54
|
-
});
|
|
55
49
|
return;
|
|
56
50
|
}
|
|
57
51
|
if (horizontalLineLength === 0) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Fonts } from "figlet";
|
|
2
1
|
import type { PromptOptions } from "../../types";
|
|
3
2
|
type EndPromptOptions = PromptOptions & {
|
|
4
3
|
variant?: "footer" | "ascii-art";
|
|
5
|
-
asciiArtFont?:
|
|
4
|
+
asciiArtFont?: any;
|
|
6
5
|
};
|
|
7
6
|
export declare function outroPrompt(optionsOrTitle: EndPromptOptions | string): Promise<void>;
|
|
8
7
|
export {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { animateText } from "../animate/animate-mod.js";
|
|
2
1
|
import { msg } from "../msg-fmt/messages.js";
|
|
3
2
|
import { getExactTerminalWidth } from "../msg-fmt/terminal.js";
|
|
4
|
-
import { createAsciiArt } from "../visual/visual-mod.js";
|
|
5
3
|
export async function outroPrompt(optionsOrTitle) {
|
|
6
4
|
const options = typeof optionsOrTitle === "string" ? { title: optionsOrTitle } : optionsOrTitle;
|
|
7
5
|
const {
|
|
@@ -14,24 +12,20 @@ export async function outroPrompt(optionsOrTitle) {
|
|
|
14
12
|
border = true,
|
|
15
13
|
borderColor = "dim",
|
|
16
14
|
horizontalLineLength: initialHorizontalLineLength = 0,
|
|
17
|
-
variant = "footer"
|
|
18
|
-
asciiArtFont
|
|
15
|
+
variant = "footer"
|
|
16
|
+
// asciiArtFont,
|
|
19
17
|
} = options;
|
|
20
18
|
let horizontalLineLength = initialHorizontalLineLength;
|
|
21
19
|
if (variant === "ascii-art") {
|
|
22
|
-
await createAsciiArt({
|
|
23
|
-
message: title || " ",
|
|
24
|
-
...asciiArtFont !== void 0 && { font: asciiArtFont }
|
|
25
|
-
});
|
|
26
20
|
return;
|
|
27
21
|
}
|
|
28
22
|
if (horizontalLineLength === 0) {
|
|
29
23
|
horizontalLineLength = getExactTerminalWidth() - 3;
|
|
30
24
|
}
|
|
31
25
|
if (titleAnimation) {
|
|
32
|
-
await
|
|
26
|
+
await msg({
|
|
33
27
|
title: title ? title : " ",
|
|
34
|
-
anim: titleAnimation,
|
|
28
|
+
// anim: titleAnimation,
|
|
35
29
|
...titleAnimationDelay !== void 0 && { delay: titleAnimationDelay },
|
|
36
30
|
type: "M_END",
|
|
37
31
|
titleColor,
|
|
@@ -225,6 +225,8 @@ export async function selectPrompt(params) {
|
|
|
225
225
|
void confirmSelection();
|
|
226
226
|
} else if (key.name === "c" && key.ctrl) {
|
|
227
227
|
void endPrompt(true);
|
|
228
|
+
} else {
|
|
229
|
+
void endPrompt(true);
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
function moveSelectionUp() {
|
|
@@ -279,6 +281,7 @@ export async function selectPrompt(params) {
|
|
|
279
281
|
);
|
|
280
282
|
}
|
|
281
283
|
async function endPrompt(isCtrlC = false) {
|
|
284
|
+
deleteLastLine();
|
|
282
285
|
await completePrompt(
|
|
283
286
|
"select",
|
|
284
287
|
isCtrlC,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { WriteStream } from "node:tty";
|
|
2
|
+
import { type ColorName } from "@reliverse/relico";
|
|
3
|
+
import { type Spinner } from "cli-spinners";
|
|
4
|
+
export declare const info: string;
|
|
5
|
+
export declare const success: string;
|
|
6
|
+
export declare const warning: string;
|
|
7
|
+
export declare const error: string;
|
|
8
|
+
export interface OraOptions {
|
|
9
|
+
text?: string | undefined;
|
|
10
|
+
spinner?: string | Spinner;
|
|
11
|
+
color?: ColorName;
|
|
12
|
+
stream?: WriteStream;
|
|
13
|
+
discardStdin?: boolean;
|
|
14
|
+
hideCursor?: boolean;
|
|
15
|
+
interval?: number;
|
|
16
|
+
isEnabled?: boolean;
|
|
17
|
+
isSilent?: boolean;
|
|
18
|
+
prefixText?: string | (() => string) | undefined;
|
|
19
|
+
suffixText?: string | (() => string) | undefined;
|
|
20
|
+
indent?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface StopAndPersistOptions {
|
|
23
|
+
symbol?: string;
|
|
24
|
+
text?: string | undefined;
|
|
25
|
+
prefixText?: string | (() => string) | undefined;
|
|
26
|
+
suffixText?: string | (() => string) | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface OraPromiseOptions<T = any> extends OraOptions {
|
|
29
|
+
successText?: string | ((result: T) => string);
|
|
30
|
+
failText?: string | ((error: any) => string);
|
|
31
|
+
}
|
|
32
|
+
export declare class Ora {
|
|
33
|
+
#private;
|
|
34
|
+
color: ColorName;
|
|
35
|
+
lastIndent?: number;
|
|
36
|
+
_stream?: WriteStream;
|
|
37
|
+
_isEnabled?: boolean;
|
|
38
|
+
constructor(options?: string | OraOptions);
|
|
39
|
+
get indent(): number | undefined;
|
|
40
|
+
set indent(indent: number | undefined);
|
|
41
|
+
get interval(): number;
|
|
42
|
+
get spinner(): string | Spinner | undefined;
|
|
43
|
+
set spinner(spinner: string | Spinner | undefined);
|
|
44
|
+
get text(): string | undefined;
|
|
45
|
+
set text(value: string | undefined);
|
|
46
|
+
get prefixText(): string | (() => string) | undefined;
|
|
47
|
+
set prefixText(value: string | (() => string) | undefined);
|
|
48
|
+
get suffixText(): string | (() => string) | undefined;
|
|
49
|
+
set suffixText(value: string | (() => string) | undefined);
|
|
50
|
+
get isSpinning(): boolean;
|
|
51
|
+
get isEnabled(): boolean;
|
|
52
|
+
set isEnabled(value: boolean);
|
|
53
|
+
get isSilent(): boolean;
|
|
54
|
+
set isSilent(value: boolean);
|
|
55
|
+
frame(): string;
|
|
56
|
+
clear(): this;
|
|
57
|
+
render(): this;
|
|
58
|
+
start(text?: string): this;
|
|
59
|
+
stop(): this;
|
|
60
|
+
succeed(text?: string): this;
|
|
61
|
+
fail(text?: string): this;
|
|
62
|
+
warn(text?: string): this;
|
|
63
|
+
info(text?: string): this;
|
|
64
|
+
stopAndPersist(options?: StopAndPersistOptions): this;
|
|
65
|
+
}
|
|
66
|
+
export default function ora(options?: string | OraOptions): Ora;
|
|
67
|
+
export declare function oraPromise<T>(action: ((spinner: Ora) => Promise<T>) | Promise<T>, options?: string | (OraPromiseOptions<T> & {
|
|
68
|
+
text?: string | undefined;
|
|
69
|
+
})): Promise<T>;
|
|
70
|
+
export { default as spinners } from "cli-spinners";
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { re } from "@reliverse/relico";
|
|
3
|
+
import cliCursor from "cli-cursor";
|
|
4
|
+
import cliSpinners from "cli-spinners";
|
|
5
|
+
import isInteractive from "is-interactive";
|
|
6
|
+
import isUnicodeSupported from "is-unicode-supported";
|
|
7
|
+
import stdinDiscarder from "stdin-discarder";
|
|
8
|
+
import stringWidth from "string-width";
|
|
9
|
+
import stripAnsi from "strip-ansi";
|
|
10
|
+
const _isUnicodeSupported = isUnicodeSupported();
|
|
11
|
+
export const info = re.blue(_isUnicodeSupported ? "\u2139" : "i");
|
|
12
|
+
export const success = re.green(_isUnicodeSupported ? "\u2714" : "\u221A");
|
|
13
|
+
export const warning = re.yellow(_isUnicodeSupported ? "\u26A0" : "\u203C");
|
|
14
|
+
export const error = re.red(_isUnicodeSupported ? "\u2716" : "\xD7");
|
|
15
|
+
export class Ora {
|
|
16
|
+
#linesToClear = 0;
|
|
17
|
+
#isDiscardingStdin = false;
|
|
18
|
+
#lineCount = 0;
|
|
19
|
+
#frameIndex = -1;
|
|
20
|
+
#lastSpinnerFrameTime = 0;
|
|
21
|
+
#options;
|
|
22
|
+
#spinner;
|
|
23
|
+
#stream;
|
|
24
|
+
#id;
|
|
25
|
+
#initialInterval;
|
|
26
|
+
#isEnabled;
|
|
27
|
+
#isSilent;
|
|
28
|
+
#indent;
|
|
29
|
+
#text;
|
|
30
|
+
#prefixText;
|
|
31
|
+
#suffixText;
|
|
32
|
+
color;
|
|
33
|
+
lastIndent;
|
|
34
|
+
_stream;
|
|
35
|
+
_isEnabled;
|
|
36
|
+
constructor(options) {
|
|
37
|
+
if (typeof options === "string") {
|
|
38
|
+
options = {
|
|
39
|
+
text: options
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
this.#options = {
|
|
43
|
+
color: "cyan",
|
|
44
|
+
stream: process.stderr,
|
|
45
|
+
discardStdin: true,
|
|
46
|
+
hideCursor: true,
|
|
47
|
+
...options
|
|
48
|
+
};
|
|
49
|
+
this.color = this.#options.color ?? "cyan";
|
|
50
|
+
this.spinner = this.#options.spinner;
|
|
51
|
+
this.#initialInterval = this.#options.interval;
|
|
52
|
+
this.#stream = this.#options.stream ?? process.stderr;
|
|
53
|
+
this.#isEnabled = typeof this.#options.isEnabled === "boolean" ? this.#options.isEnabled : isInteractive({ stream: this.#stream });
|
|
54
|
+
this.#isSilent = typeof this.#options.isSilent === "boolean" ? this.#options.isSilent : false;
|
|
55
|
+
this.text = this.#options.text ?? "";
|
|
56
|
+
this.prefixText = this.#options.prefixText ?? "";
|
|
57
|
+
this.suffixText = this.#options.suffixText ?? "";
|
|
58
|
+
this.indent = this.#options.indent ?? 0;
|
|
59
|
+
if (process.env.NODE_ENV === "test") {
|
|
60
|
+
this._stream = this.#stream;
|
|
61
|
+
this._isEnabled = this.#isEnabled;
|
|
62
|
+
Object.defineProperty(this, "_linesToClear", {
|
|
63
|
+
get() {
|
|
64
|
+
return this.#linesToClear;
|
|
65
|
+
},
|
|
66
|
+
set(newValue) {
|
|
67
|
+
this.#linesToClear = newValue;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "_frameIndex", {
|
|
71
|
+
get() {
|
|
72
|
+
return this.#frameIndex;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "_lineCount", {
|
|
76
|
+
get() {
|
|
77
|
+
return this.#lineCount;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
get indent() {
|
|
83
|
+
return this.#indent;
|
|
84
|
+
}
|
|
85
|
+
set indent(indent) {
|
|
86
|
+
const indentValue = indent ?? 0;
|
|
87
|
+
if (!(indentValue >= 0 && Number.isInteger(indentValue))) {
|
|
88
|
+
throw new Error("The `indent` option must be an integer from 0 and up");
|
|
89
|
+
}
|
|
90
|
+
this.#indent = indentValue;
|
|
91
|
+
this.#updateLineCount();
|
|
92
|
+
}
|
|
93
|
+
get interval() {
|
|
94
|
+
return this.#initialInterval ?? this.#spinner.interval ?? 100;
|
|
95
|
+
}
|
|
96
|
+
get spinner() {
|
|
97
|
+
return this.#spinner;
|
|
98
|
+
}
|
|
99
|
+
set spinner(spinner) {
|
|
100
|
+
this.#frameIndex = -1;
|
|
101
|
+
this.#initialInterval = void 0;
|
|
102
|
+
if (typeof spinner === "object") {
|
|
103
|
+
if (spinner.frames === void 0) {
|
|
104
|
+
throw new Error("The given spinner must have a `frames` property");
|
|
105
|
+
}
|
|
106
|
+
this.#spinner = spinner;
|
|
107
|
+
} else if (!isUnicodeSupported()) {
|
|
108
|
+
this.#spinner = cliSpinners.line;
|
|
109
|
+
} else if (spinner === void 0) {
|
|
110
|
+
this.#spinner = cliSpinners.dots;
|
|
111
|
+
} else if (spinner !== "default" && typeof spinner === "string" && spinner in cliSpinners) {
|
|
112
|
+
this.#spinner = cliSpinners[spinner];
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
get text() {
|
|
120
|
+
return this.#text;
|
|
121
|
+
}
|
|
122
|
+
set text(value) {
|
|
123
|
+
this.#text = value ?? "";
|
|
124
|
+
this.#updateLineCount();
|
|
125
|
+
}
|
|
126
|
+
get prefixText() {
|
|
127
|
+
return this.#prefixText;
|
|
128
|
+
}
|
|
129
|
+
set prefixText(value) {
|
|
130
|
+
this.#prefixText = value;
|
|
131
|
+
this.#updateLineCount();
|
|
132
|
+
}
|
|
133
|
+
get suffixText() {
|
|
134
|
+
return this.#suffixText;
|
|
135
|
+
}
|
|
136
|
+
set suffixText(value) {
|
|
137
|
+
this.#suffixText = value;
|
|
138
|
+
this.#updateLineCount();
|
|
139
|
+
}
|
|
140
|
+
get isSpinning() {
|
|
141
|
+
return this.#id !== void 0;
|
|
142
|
+
}
|
|
143
|
+
#getFullPrefixText(prefixText = this.#prefixText, postfix = " ") {
|
|
144
|
+
if (typeof prefixText === "string" && prefixText !== "") {
|
|
145
|
+
return prefixText + postfix;
|
|
146
|
+
}
|
|
147
|
+
if (typeof prefixText === "function") {
|
|
148
|
+
return prefixText() + postfix;
|
|
149
|
+
}
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
#getFullSuffixText(suffixText = this.#suffixText, prefix = " ") {
|
|
153
|
+
if (typeof suffixText === "string" && suffixText !== "") {
|
|
154
|
+
return prefix + suffixText;
|
|
155
|
+
}
|
|
156
|
+
if (typeof suffixText === "function") {
|
|
157
|
+
return prefix + suffixText();
|
|
158
|
+
}
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
161
|
+
#updateLineCount() {
|
|
162
|
+
const columns = this.#stream.columns ?? 80;
|
|
163
|
+
const fullPrefixText = this.#getFullPrefixText(this.#prefixText, "-");
|
|
164
|
+
const fullSuffixText = this.#getFullSuffixText(this.#suffixText, "-");
|
|
165
|
+
const fullText = " ".repeat(this.#indent) + fullPrefixText + "--" + this.#text + "--" + fullSuffixText;
|
|
166
|
+
this.#lineCount = 0;
|
|
167
|
+
for (const line of stripAnsi(fullText).split("\n")) {
|
|
168
|
+
this.#lineCount += Math.max(
|
|
169
|
+
1,
|
|
170
|
+
Math.ceil(stringWidth(line, { countAnsiEscapeCodes: true }) / columns)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
get isEnabled() {
|
|
175
|
+
return this.#isEnabled && !this.#isSilent;
|
|
176
|
+
}
|
|
177
|
+
set isEnabled(value) {
|
|
178
|
+
if (typeof value !== "boolean") {
|
|
179
|
+
throw new TypeError("The `isEnabled` option must be a boolean");
|
|
180
|
+
}
|
|
181
|
+
this.#isEnabled = value;
|
|
182
|
+
}
|
|
183
|
+
get isSilent() {
|
|
184
|
+
return this.#isSilent;
|
|
185
|
+
}
|
|
186
|
+
set isSilent(value) {
|
|
187
|
+
if (typeof value !== "boolean") {
|
|
188
|
+
throw new TypeError("The `isSilent` option must be a boolean");
|
|
189
|
+
}
|
|
190
|
+
this.#isSilent = value;
|
|
191
|
+
}
|
|
192
|
+
frame() {
|
|
193
|
+
const now = Date.now();
|
|
194
|
+
if (this.#frameIndex === -1 || now - this.#lastSpinnerFrameTime >= this.interval) {
|
|
195
|
+
this.#frameIndex = ++this.#frameIndex % this.#spinner.frames.length;
|
|
196
|
+
this.#lastSpinnerFrameTime = now;
|
|
197
|
+
}
|
|
198
|
+
const { frames } = this.#spinner;
|
|
199
|
+
let frame = frames[this.#frameIndex];
|
|
200
|
+
if (this.color) {
|
|
201
|
+
frame = re[this.color](frame ?? "");
|
|
202
|
+
}
|
|
203
|
+
const fullPrefixText = typeof this.#prefixText === "string" && this.#prefixText !== "" ? this.#prefixText + " " : "";
|
|
204
|
+
const fullText = typeof this.text === "string" ? " " + this.text : "";
|
|
205
|
+
const fullSuffixText = typeof this.#suffixText === "string" && this.#suffixText !== "" ? " " + this.#suffixText : "";
|
|
206
|
+
return fullPrefixText + frame + fullText + fullSuffixText;
|
|
207
|
+
}
|
|
208
|
+
clear() {
|
|
209
|
+
if (!this.#isEnabled || !this.#stream.isTTY) {
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
this.#stream.cursorTo(0);
|
|
213
|
+
for (let index = 0; index < this.#linesToClear; index++) {
|
|
214
|
+
if (index > 0) {
|
|
215
|
+
this.#stream.moveCursor(0, -1);
|
|
216
|
+
}
|
|
217
|
+
this.#stream.clearLine(1);
|
|
218
|
+
}
|
|
219
|
+
if (this.#indent || this.lastIndent !== this.#indent) {
|
|
220
|
+
this.#stream.cursorTo(this.#indent);
|
|
221
|
+
}
|
|
222
|
+
this.lastIndent = this.#indent;
|
|
223
|
+
this.#linesToClear = 0;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
render() {
|
|
227
|
+
if (this.#isSilent) {
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
this.clear();
|
|
231
|
+
this.#stream.write(this.frame());
|
|
232
|
+
this.#linesToClear = this.#lineCount;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
start(text) {
|
|
236
|
+
if (text) {
|
|
237
|
+
this.text = text;
|
|
238
|
+
}
|
|
239
|
+
if (this.#isSilent) {
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
if (!this.#isEnabled) {
|
|
243
|
+
if (this.text) {
|
|
244
|
+
this.#stream.write(`- ${this.text}
|
|
245
|
+
`);
|
|
246
|
+
}
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
if (this.isSpinning) {
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
if (this.#options.hideCursor) {
|
|
253
|
+
cliCursor.hide(this.#stream);
|
|
254
|
+
}
|
|
255
|
+
if (this.#options.discardStdin && process.stdin.isTTY) {
|
|
256
|
+
this.#isDiscardingStdin = true;
|
|
257
|
+
stdinDiscarder.start();
|
|
258
|
+
}
|
|
259
|
+
this.render();
|
|
260
|
+
this.#id = setInterval(this.render.bind(this), this.interval);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
stop() {
|
|
264
|
+
if (!this.#isEnabled) {
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
clearInterval(this.#id);
|
|
268
|
+
this.#id = void 0;
|
|
269
|
+
this.#frameIndex = 0;
|
|
270
|
+
this.clear();
|
|
271
|
+
if (this.#options.hideCursor) {
|
|
272
|
+
cliCursor.show(this.#stream);
|
|
273
|
+
}
|
|
274
|
+
if (this.#options.discardStdin && process.stdin.isTTY && this.#isDiscardingStdin) {
|
|
275
|
+
stdinDiscarder.stop();
|
|
276
|
+
this.#isDiscardingStdin = false;
|
|
277
|
+
}
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
succeed(text) {
|
|
281
|
+
return this.stopAndPersist({ symbol: success, text });
|
|
282
|
+
}
|
|
283
|
+
fail(text) {
|
|
284
|
+
return this.stopAndPersist({ symbol: error, text });
|
|
285
|
+
}
|
|
286
|
+
warn(text) {
|
|
287
|
+
return this.stopAndPersist({ symbol: warning, text });
|
|
288
|
+
}
|
|
289
|
+
info(text) {
|
|
290
|
+
return this.stopAndPersist({ symbol: info, text });
|
|
291
|
+
}
|
|
292
|
+
stopAndPersist(options = {}) {
|
|
293
|
+
if (this.#isSilent) {
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
const prefixText = options.prefixText ?? this.#prefixText;
|
|
297
|
+
const fullPrefixText = this.#getFullPrefixText(prefixText, " ");
|
|
298
|
+
const symbolText = options.symbol ?? " ";
|
|
299
|
+
const text = options.text ?? this.text;
|
|
300
|
+
const separatorText = symbolText ? " " : "";
|
|
301
|
+
const fullText = typeof text === "string" ? separatorText + text : "";
|
|
302
|
+
const suffixText = options.suffixText ?? this.#suffixText;
|
|
303
|
+
const fullSuffixText = this.#getFullSuffixText(suffixText, " ");
|
|
304
|
+
const textToWrite = fullPrefixText + symbolText + fullText + fullSuffixText + "\n";
|
|
305
|
+
this.stop();
|
|
306
|
+
this.#stream.write(textToWrite);
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export default function ora(options) {
|
|
311
|
+
return new Ora(options);
|
|
312
|
+
}
|
|
313
|
+
export async function oraPromise(action, options) {
|
|
314
|
+
const actionIsFunction = typeof action === "function";
|
|
315
|
+
const actionIsPromise = !actionIsFunction && typeof action.then === "function";
|
|
316
|
+
if (!actionIsFunction && !actionIsPromise) {
|
|
317
|
+
throw new TypeError("Parameter `action` must be a Function or a Promise");
|
|
318
|
+
}
|
|
319
|
+
const { successText, failText } = typeof options === "object" ? options : { successText: void 0, failText: void 0 };
|
|
320
|
+
const spinnerOptions = typeof options === "object" && "text" in options ? options : typeof options === "string" ? { text: options } : {};
|
|
321
|
+
const spinner = ora(spinnerOptions).start();
|
|
322
|
+
try {
|
|
323
|
+
const promise = actionIsFunction ? action(spinner) : action;
|
|
324
|
+
const result = await promise;
|
|
325
|
+
spinner.succeed(
|
|
326
|
+
successText === void 0 ? void 0 : typeof successText === "string" ? successText : successText(result)
|
|
327
|
+
);
|
|
328
|
+
return result;
|
|
329
|
+
} catch (error2) {
|
|
330
|
+
spinner.fail(
|
|
331
|
+
failText === void 0 ? void 0 : typeof failText === "string" ? failText : failText(error2)
|
|
332
|
+
);
|
|
333
|
+
throw error2;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
export { default as spinners } from "cli-spinners";
|