@reliverse/rempts 1.7.65 → 2.2.7

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.
Files changed (131) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1534 -1431
  3. package/cleanup.mjs +33 -0
  4. package/dist/cancel.d.ts +31 -0
  5. package/dist/cancel.js +28 -0
  6. package/dist/ffi.d.ts +1 -0
  7. package/dist/ffi.js +165 -0
  8. package/dist/group.d.ts +16 -0
  9. package/dist/group.js +22 -0
  10. package/dist/launcher/command.d.ts +8 -0
  11. package/dist/launcher/command.js +10 -0
  12. package/dist/launcher/discovery.d.ts +3 -0
  13. package/dist/launcher/discovery.js +207 -0
  14. package/dist/launcher/errors.d.ts +15 -0
  15. package/dist/launcher/errors.js +31 -0
  16. package/dist/launcher/help.d.ts +3 -0
  17. package/dist/launcher/help.js +145 -0
  18. package/dist/launcher/mod.d.ts +12 -0
  19. package/dist/launcher/mod.js +222 -0
  20. package/dist/launcher/parser.d.ts +14 -0
  21. package/dist/launcher/parser.js +255 -0
  22. package/dist/launcher/registry.d.ts +10 -0
  23. package/dist/launcher/registry.js +42 -0
  24. package/dist/launcher/types.d.ts +78 -0
  25. package/dist/launcher/validator.d.ts +3 -0
  26. package/dist/launcher/validator.js +39 -0
  27. package/dist/mod.d.ts +6 -0
  28. package/dist/mod.js +6 -0
  29. package/dist/prompt.d.ts +13 -0
  30. package/dist/prompt.js +53 -0
  31. package/dist/selection.d.ts +92 -0
  32. package/dist/selection.js +191 -0
  33. package/dist/spinner.d.ts +26 -0
  34. package/dist/spinner.js +141 -0
  35. package/dist/utils.d.ts +3 -0
  36. package/dist/utils.js +11 -0
  37. package/package.json +41 -47
  38. package/bin/libs/animate/animate-mod.ts.txt +0 -78
  39. package/bin/libs/anykey/anykey-mod.d.ts +0 -12
  40. package/bin/libs/anykey/anykey-mod.js +0 -125
  41. package/bin/libs/cancel/cancel.d.ts +0 -45
  42. package/bin/libs/cancel/cancel.js +0 -72
  43. package/bin/libs/confirm/confirm-alias.d.ts +0 -2
  44. package/bin/libs/confirm/confirm-alias.js +0 -2
  45. package/bin/libs/confirm/confirm-mod.d.ts +0 -5
  46. package/bin/libs/confirm/confirm-mod.js +0 -179
  47. package/bin/libs/date/date.d.ts +0 -2
  48. package/bin/libs/date/date.js +0 -254
  49. package/bin/libs/editor/editor-mod.d.ts +0 -25
  50. package/bin/libs/editor/editor-mod.js +0 -1133
  51. package/bin/libs/figures/figures-mod.d.ts +0 -461
  52. package/bin/libs/figures/figures-mod.js +0 -285
  53. package/bin/libs/group/group-mod.d.ts +0 -33
  54. package/bin/libs/group/group-mod.js +0 -89
  55. package/bin/libs/input/input-alias.d.ts +0 -5
  56. package/bin/libs/input/input-alias.js +0 -4
  57. package/bin/libs/input/input-mod.d.ts +0 -16
  58. package/bin/libs/input/input-mod.js +0 -370
  59. package/bin/libs/intro/intro-alias.d.ts +0 -3
  60. package/bin/libs/intro/intro-alias.js +0 -3
  61. package/bin/libs/intro/intro-mod.d.ts +0 -19
  62. package/bin/libs/intro/intro-mod.js +0 -71
  63. package/bin/libs/launcher/command-runner.d.ts +0 -31
  64. package/bin/libs/launcher/command-runner.js +0 -229
  65. package/bin/libs/launcher/launcher-alias.d.ts +0 -2
  66. package/bin/libs/launcher/launcher-alias.js +0 -2
  67. package/bin/libs/launcher/launcher-mod.d.ts +0 -66
  68. package/bin/libs/launcher/launcher-mod.js +0 -1037
  69. package/bin/libs/launcher/launcher-types.d.ts +0 -176
  70. package/bin/libs/launcher/launcher-types.js +0 -0
  71. package/bin/libs/log/log-alias.d.ts +0 -1
  72. package/bin/libs/log/log-alias.js +0 -2
  73. package/bin/libs/msg-fmt/colors.d.ts +0 -30
  74. package/bin/libs/msg-fmt/colors.js +0 -42
  75. package/bin/libs/msg-fmt/mapping.d.ts +0 -3
  76. package/bin/libs/msg-fmt/mapping.js +0 -41
  77. package/bin/libs/msg-fmt/messages.d.ts +0 -35
  78. package/bin/libs/msg-fmt/messages.js +0 -305
  79. package/bin/libs/msg-fmt/terminal.d.ts +0 -15
  80. package/bin/libs/msg-fmt/terminal.js +0 -60
  81. package/bin/libs/msg-fmt/variants.d.ts +0 -11
  82. package/bin/libs/msg-fmt/variants.js +0 -52
  83. package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
  84. package/bin/libs/multiselect/multiselect-alias.js +0 -2
  85. package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
  86. package/bin/libs/multiselect/multiselect-prompt.js +0 -340
  87. package/bin/libs/next-steps/next-steps.d.ts +0 -13
  88. package/bin/libs/next-steps/next-steps.js +0 -24
  89. package/bin/libs/number/number-mod.d.ts +0 -28
  90. package/bin/libs/number/number-mod.js +0 -234
  91. package/bin/libs/outro/outro-alias.d.ts +0 -3
  92. package/bin/libs/outro/outro-alias.js +0 -3
  93. package/bin/libs/outro/outro-mod.d.ts +0 -7
  94. package/bin/libs/outro/outro-mod.js +0 -49
  95. package/bin/libs/reliarg/reliarg-mod.d.ts +0 -76
  96. package/bin/libs/reliarg/reliarg-mod.js +0 -276
  97. package/bin/libs/results/results.d.ts +0 -7
  98. package/bin/libs/results/results.js +0 -27
  99. package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
  100. package/bin/libs/select/nummultiselect-prompt.js +0 -141
  101. package/bin/libs/select/numselect-prompt.d.ts +0 -7
  102. package/bin/libs/select/numselect-prompt.js +0 -111
  103. package/bin/libs/select/select-alias.d.ts +0 -9
  104. package/bin/libs/select/select-alias.js +0 -9
  105. package/bin/libs/select/select-prompt.d.ts +0 -5
  106. package/bin/libs/select/select-prompt.js +0 -311
  107. package/bin/libs/select/toggle-prompt.d.ts +0 -5
  108. package/bin/libs/select/toggle-prompt.js +0 -207
  109. package/bin/libs/spinner/spinner-impl.d.ts +0 -70
  110. package/bin/libs/spinner/spinner-impl.js +0 -336
  111. package/bin/libs/spinner/spinner-mod.d.ts +0 -167
  112. package/bin/libs/spinner/spinner-mod.js +0 -447
  113. package/bin/libs/utils/colorize.d.ts +0 -2
  114. package/bin/libs/utils/colorize.js +0 -122
  115. package/bin/libs/utils/errors.d.ts +0 -1
  116. package/bin/libs/utils/errors.js +0 -17
  117. package/bin/libs/utils/prevent.d.ts +0 -8
  118. package/bin/libs/utils/prevent.js +0 -62
  119. package/bin/libs/utils/prompt-end.d.ts +0 -8
  120. package/bin/libs/utils/prompt-end.js +0 -36
  121. package/bin/libs/utils/stream-text.d.ts +0 -18
  122. package/bin/libs/utils/stream-text.js +0 -138
  123. package/bin/libs/utils/system.d.ts +0 -6
  124. package/bin/libs/utils/system.js +0 -7
  125. package/bin/libs/utils/validate.d.ts +0 -21
  126. package/bin/libs/utils/validate.js +0 -17
  127. package/bin/libs/visual/visual-mod.ts.txt +0 -19
  128. package/bin/mod.d.ts +0 -50
  129. package/bin/mod.js +0 -127
  130. package/bin/types.d.ts +0 -372
  131. /package/{bin → dist/launcher}/types.js +0 -0
@@ -1,167 +0,0 @@
1
- /**
2
- * Environment toggles:
3
- * - Disable by setting CLI_NO_SPINNER=1 or CLI_NO_COLOR=1
4
- * - Auto-disables in CI and when not a TTY; override with isEnabled: true
5
- * - Respect env behavior can be bypassed with respectEnv: false
6
- * Defaults:
7
- * - spinner: "dots", color: "cyan", hideCursor: true, discardStdin: true, stream defaults to stderr.
8
- */
9
- import { type Ora, type OraOptions, type OraPromiseOptions } from "./spinner-impl.js";
10
- export interface SpinnerOptions extends Omit<OraOptions, "text"> {
11
- readonly respectEnv?: boolean;
12
- readonly showTiming?: boolean;
13
- readonly defaultSuccess?: string;
14
- readonly defaultFail?: string;
15
- text?: string;
16
- readonly textColor?: string | ((text: string) => string);
17
- readonly prefixColor?: string | ((text: string) => string);
18
- readonly suffixColor?: string | ((text: string) => string);
19
- readonly successColor?: string | ((text: string) => string);
20
- readonly failColor?: string | ((text: string) => string);
21
- readonly theme?: {
22
- readonly info?: (text: string) => string;
23
- readonly success?: (text: string) => string;
24
- readonly error?: (text: string) => string;
25
- readonly dim?: (text: string) => string;
26
- readonly progress?: (text: string) => string;
27
- readonly rate?: (text: string) => string;
28
- readonly bytes?: (text: string) => string;
29
- readonly percentage?: (text: string) => string;
30
- };
31
- }
32
- export interface SpinnerGroupOptions extends SpinnerOptions {
33
- readonly items: readonly string[];
34
- readonly concurrent?: boolean;
35
- }
36
- export interface FileProgressOptions {
37
- readonly totalBytes?: number;
38
- readonly showBytes?: boolean;
39
- readonly showRate?: boolean;
40
- }
41
- export type SimpleSpinner = Ora;
42
- export declare const defaultSpinnerOptions: Readonly<SpinnerOptions>;
43
- export declare function isSpinnerEnabled(options?: {
44
- stream?: NodeJS.WriteStream;
45
- respectEnv?: boolean;
46
- isEnabled?: boolean;
47
- }): boolean;
48
- export declare function createSpinner(input?: string | SpinnerOptions): SimpleSpinner;
49
- export declare function withSpinnerPromise<T>(action: Promise<T> | ((spinner: Ora) => Promise<T>), options?: string | (OraPromiseOptions<T> & SpinnerOptions)): Promise<T>;
50
- export declare function withSpinner<T>(textOrOptions: string | SpinnerOptions, action: (spinner: Ora) => Promise<T>, onSuccessText?: string | ((result: T) => string), onFailText?: string | ((error: Error) => string)): Promise<T>;
51
- /**
52
- * Update spinner text with optional prefix/suffix
53
- */
54
- export declare function updateSpinnerText(spinner: SimpleSpinner, text: string, options?: {
55
- prefix?: string;
56
- suffix?: string;
57
- }): void;
58
- /**
59
- * Stop spinner and persist with custom symbol and text
60
- */
61
- export declare function stopAndPersist(spinner: SimpleSpinner, options: {
62
- symbol?: string;
63
- text?: string;
64
- prefixText?: string | (() => string);
65
- suffixText?: string | (() => string);
66
- }): void;
67
- /**
68
- * Create a spinner with timing that automatically shows elapsed time
69
- */
70
- export declare function createTimedSpinner(input?: string | Omit<SpinnerOptions, "showTiming">): {
71
- spinner: SimpleSpinner;
72
- getElapsed: () => number;
73
- succeedWithTiming: (text?: string) => void;
74
- failWithTiming: (text?: string) => void;
75
- };
76
- /**
77
- * Create multiple spinners for concurrent operations
78
- */
79
- export declare function createSpinnerGroup(options: SpinnerGroupOptions): {
80
- spinners: SimpleSpinner[];
81
- updateAll: (text: string) => void;
82
- succeedAll: (text?: string) => void;
83
- failAll: (text?: string) => void;
84
- stopAll: () => void;
85
- };
86
- /**
87
- * Enhanced withSpinner that includes common patterns used in the codebase
88
- */
89
- export declare function withEnhancedSpinner<T>(textOrOptions: string | (SpinnerOptions & {
90
- successText?: string;
91
- failText?: string;
92
- showTiming?: boolean;
93
- }), action: (spinner: SimpleSpinner & {
94
- updateText: (text: string, options?: {
95
- prefix?: string;
96
- suffix?: string;
97
- }) => void;
98
- setProgress: (current: number, total: number, text?: string) => void;
99
- }) => Promise<T>): Promise<T>;
100
- /**
101
- * Check if a spinner is currently running
102
- */
103
- export declare function isSpinnerRunning(spinner: SimpleSpinner): boolean;
104
- /**
105
- * Safely stop a spinner if it's running
106
- */
107
- export declare function safeStopSpinner(spinner: SimpleSpinner | null): void;
108
- /**
109
- * Create a spinner that automatically handles common build/publish patterns
110
- */
111
- export declare function createBuildSpinner(operation: string, options?: Omit<SpinnerOptions, "text">): {
112
- spinner: SimpleSpinner;
113
- complete: (message?: string) => void;
114
- error: (error: Error | string) => void;
115
- updateProgress: (step: string) => void;
116
- };
117
- /**
118
- * Create a spinner with file progress tracking
119
- */
120
- export declare function createFileProgressSpinner(operation: string, options?: SpinnerOptions & FileProgressOptions): {
121
- spinner: SimpleSpinner;
122
- updateProgress: (bytesProcessed: number, fileName?: string) => void;
123
- updateRate: (bytesPerSecond: number) => void;
124
- complete: (message?: string) => void;
125
- error: (error: Error | string) => void;
126
- };
127
- /**
128
- * Create a multi-step operation spinner with automatic timing
129
- */
130
- export declare function createMultiStepSpinner(operationName: string, steps: readonly string[], options?: SpinnerOptions): {
131
- spinner: SimpleSpinner;
132
- nextStep: (stepIndex?: number) => void;
133
- complete: (message?: string) => void;
134
- error: (error: Error | string, stepIndex?: number) => void;
135
- getCurrentStep: () => number;
136
- };
137
- /**
138
- * Enhanced timing utility using pretty-ms
139
- */
140
- export declare function formatSpinnerTiming(startTime: number, options?: {
141
- verbose?: boolean;
142
- }): string;
143
- /**
144
- * Format bytes for spinner display using pretty-bytes
145
- */
146
- export declare function formatSpinnerBytes(bytes: number, options?: {
147
- binary?: boolean;
148
- }): string;
149
- /**
150
- * Format elapsed time for spinner display using pretty-ms
151
- */
152
- export declare function formatSpinnerElapsed(elapsed: number, options?: {
153
- verbose?: boolean;
154
- }): string;
155
- /**
156
- * Create a spinner for download/upload operations with byte tracking
157
- */
158
- export declare function createTransferSpinner(operation: string, options?: SpinnerOptions & {
159
- totalBytes?: number;
160
- showRate?: boolean;
161
- }): {
162
- spinner: SimpleSpinner;
163
- updateBytes: (bytesTransferred: number, fileName?: string) => void;
164
- updateRate: (bytesPerSecond: number) => void;
165
- complete: (message?: string, totalBytesTransferred?: number) => void;
166
- error: (error: Error | string) => void;
167
- };
@@ -1,447 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import prettyBytes from "pretty-bytes";
3
- import prettyMilliseconds from "pretty-ms";
4
- import { ora } from "./spinner-impl.js";
5
- import { oraPromise } from "./spinner-impl.js";
6
- function isColorsEnabled(isSpinnerEnabledFlag) {
7
- if (process.env["CLI_NO_COLOR"] === "1") return false;
8
- return isSpinnerEnabledFlag;
9
- }
10
- function toStyler(input, fallback) {
11
- if (!input) return fallback;
12
- if (typeof input === "function") return input;
13
- const fn = re[input];
14
- if (typeof fn === "function") return fn;
15
- return fallback;
16
- }
17
- const identity = (s) => s;
18
- function isCIEnvironment() {
19
- const { CI, GITHUB_ACTIONS, BUILD_NUMBER, RUN_ID } = process.env;
20
- return CI === "true" || GITHUB_ACTIONS === "true" || typeof BUILD_NUMBER !== "undefined" || typeof RUN_ID !== "undefined";
21
- }
22
- const defaultStderr = process.stderr;
23
- function isInteractive(stream = defaultStderr) {
24
- return Boolean(stream && stream.isTTY);
25
- }
26
- function getDefaultEnabled(stream = defaultStderr) {
27
- const disabledByEnv = process.env["CLI_NO_SPINNER"] === "1" || process.env["CLI_NO_COLOR"] === "1";
28
- if (disabledByEnv) return false;
29
- if (isCIEnvironment()) return false;
30
- return isInteractive(stream);
31
- }
32
- export const defaultSpinnerOptions = {
33
- color: "cyan",
34
- spinner: "dots",
35
- hideCursor: true,
36
- indent: 0,
37
- discardStdin: true,
38
- respectEnv: true,
39
- showTiming: false
40
- };
41
- export function isSpinnerEnabled(options) {
42
- const stream = options?.stream ?? defaultStderr;
43
- const respectEnv = options?.respectEnv !== false;
44
- if (typeof options?.isEnabled === "boolean") return options.isEnabled;
45
- return respectEnv ? getDefaultEnabled(stream) : true;
46
- }
47
- export function createSpinner(input) {
48
- const base = typeof input === "string" ? { text: input } : { ...input ?? {} };
49
- const stream = base.stream ?? defaultStderr;
50
- const respectEnv = base.respectEnv !== false;
51
- const isEnabled = base.isEnabled ?? (respectEnv ? getDefaultEnabled(stream) : true);
52
- const isSilent = base.isSilent ?? false;
53
- const resolvedColor = base.color ?? defaultSpinnerOptions.color ?? "cyan";
54
- const resolvedSpinner = base.spinner ?? defaultSpinnerOptions.spinner ?? "dots";
55
- const resolvedHideCursor = base.hideCursor ?? defaultSpinnerOptions.hideCursor ?? true;
56
- const resolvedIndent = base.indent ?? defaultSpinnerOptions.indent ?? 0;
57
- const resolvedDiscardStdin = base.discardStdin ?? defaultSpinnerOptions.discardStdin ?? true;
58
- const options = {
59
- // Defaults chosen to be broadly useful; callers can override
60
- color: resolvedColor,
61
- hideCursor: resolvedHideCursor,
62
- indent: resolvedIndent,
63
- stream,
64
- isEnabled,
65
- isSilent,
66
- discardStdin: resolvedDiscardStdin,
67
- ...resolvedSpinner !== void 0 ? { spinner: resolvedSpinner } : {},
68
- ...base.interval !== void 0 ? { interval: base.interval } : {},
69
- ...base.prefixText !== void 0 ? { prefixText: base.prefixText } : {},
70
- ...base.suffixText !== void 0 ? { suffixText: base.suffixText } : {},
71
- ...base.text !== void 0 ? { text: base.text } : {}
72
- };
73
- const spinner = ora(options);
74
- const colorsEnabled = isColorsEnabled(isEnabled);
75
- const themeObj = base.theme ?? {};
76
- const dim = colorsEnabled ? themeObj.dim ?? re.dim ?? identity : identity;
77
- const info = colorsEnabled ? themeObj.info ?? re.cyan ?? identity : identity;
78
- const success = colorsEnabled ? themeObj.success ?? re.green ?? identity : identity;
79
- const error = colorsEnabled ? themeObj.error ?? re.red ?? identity : identity;
80
- const progress = colorsEnabled ? themeObj.progress ?? re.cyan ?? identity : identity;
81
- const rate = colorsEnabled ? themeObj.rate ?? re.cyan ?? identity : identity;
82
- const bytesColor = colorsEnabled ? themeObj.bytes ?? re.cyan ?? identity : identity;
83
- const percent = colorsEnabled ? themeObj.percentage ?? re.yellow ?? identity : identity;
84
- spinner.__reTheme = { dim, info, success, error, progress, rate, bytesColor, percent };
85
- spinner.__textStyler = toStyler(base.textColor, info);
86
- spinner.__prefixStyler = toStyler(base.prefixColor, identity);
87
- spinner.__suffixStyler = toStyler(base.suffixColor, identity);
88
- spinner.__successStyler = toStyler(base.successColor, success);
89
- spinner.__failStyler = toStyler(base.failColor, error);
90
- if (options.text) {
91
- const style = spinner.__textStyler;
92
- spinner.text = style(options.text);
93
- }
94
- return spinner;
95
- }
96
- export async function withSpinnerPromise(action, options) {
97
- return oraPromise(action, options);
98
- }
99
- export async function withSpinner(textOrOptions, action, onSuccessText, onFailText) {
100
- const startTime = Date.now();
101
- const options = typeof textOrOptions === "string" ? { text: textOrOptions } : textOrOptions;
102
- const spinner = createSpinner(textOrOptions).start();
103
- try {
104
- const result = await action(spinner);
105
- const successMsg = getSuccessMessage(result, onSuccessText, options, startTime);
106
- const style = spinner.__successStyler ?? identity;
107
- spinner.succeed(successMsg ? style(successMsg) : void 0);
108
- return result;
109
- } catch (error) {
110
- const err = error;
111
- const failMsg = getFailMessage(err, onFailText, options);
112
- const style = spinner.__failStyler ?? identity;
113
- spinner.fail(failMsg ? style(failMsg) : void 0);
114
- throw err;
115
- }
116
- }
117
- function getSuccessMessage(result, onSuccessText, options, startTime) {
118
- let message;
119
- if (typeof onSuccessText === "function") {
120
- message = onSuccessText(result);
121
- } else if (typeof onSuccessText === "string") {
122
- message = onSuccessText;
123
- } else if (options.defaultSuccess) {
124
- message = options.defaultSuccess;
125
- }
126
- if (options.showTiming && message) {
127
- const elapsed = Date.now() - startTime;
128
- const timing = prettyMilliseconds(elapsed, { compact: true });
129
- message = `${message} (${timing})`;
130
- }
131
- return message;
132
- }
133
- function getFailMessage(error, onFailText, options) {
134
- if (typeof onFailText === "function") {
135
- return onFailText(error);
136
- } else if (typeof onFailText === "string") {
137
- return onFailText;
138
- } else if (options.defaultFail) {
139
- return options.defaultFail;
140
- }
141
- }
142
- export function updateSpinnerText(spinner, text, options) {
143
- const { prefix, suffix } = options ?? {};
144
- const styleText = spinner.__textStyler ?? identity;
145
- const stylePrefix = spinner.__prefixStyler ?? identity;
146
- const styleSuffix = spinner.__suffixStyler ?? identity;
147
- const prefixStyled = prefix ? stylePrefix(prefix) : "";
148
- const suffixStyled = suffix ? styleSuffix(suffix) : "";
149
- const fullText = `${prefixStyled}${styleText(text)}${suffixStyled}`;
150
- spinner.text = fullText;
151
- }
152
- export function stopAndPersist(spinner, options) {
153
- spinner.stopAndPersist({
154
- symbol: options.symbol ?? " ",
155
- text: options.text ?? spinner.text,
156
- prefixText: options.prefixText ?? spinner.prefixText,
157
- suffixText: options.suffixText ?? spinner.suffixText
158
- });
159
- }
160
- export function createTimedSpinner(input) {
161
- const startTime = Date.now();
162
- const options = typeof input === "string" ? { text: input } : { ...input ?? {} };
163
- const spinner = createSpinner({ ...options, showTiming: true });
164
- return {
165
- spinner,
166
- getElapsed: () => Date.now() - startTime,
167
- succeedWithTiming: (text) => {
168
- const elapsed = Date.now() - startTime;
169
- const timing = prettyMilliseconds(elapsed, { compact: true });
170
- const dim = spinner.__reTheme?.dim ?? identity;
171
- const successStyle = spinner.__successStyler ?? identity;
172
- const message = text ? `${successStyle(text)} ${dim(`(${timing})`)}` : void 0;
173
- spinner.succeed(message);
174
- },
175
- failWithTiming: (text) => {
176
- const elapsed = Date.now() - startTime;
177
- const timing = prettyMilliseconds(elapsed, { compact: true });
178
- const dim = spinner.__reTheme?.dim ?? identity;
179
- const failStyle = spinner.__failStyler ?? identity;
180
- const message = text ? `${failStyle(text)} ${dim(`(failed after ${timing})`)}` : void 0;
181
- spinner.fail(message);
182
- }
183
- };
184
- }
185
- export function createSpinnerGroup(options) {
186
- const { items, concurrent = false, ...baseOptions } = options;
187
- const spinners = items.map((item, index) => {
188
- const spinnerOptions = {
189
- ...baseOptions,
190
- text: item,
191
- indent: (baseOptions.indent ?? 0) + (concurrent ? 0 : index * 2)
192
- };
193
- return createSpinner(spinnerOptions);
194
- });
195
- return {
196
- spinners,
197
- updateAll: (text) => {
198
- for (const spinner of spinners) {
199
- updateSpinnerText(spinner, text);
200
- }
201
- },
202
- succeedAll: (text) => {
203
- for (const spinner of spinners) {
204
- const style = spinner.__successStyler ?? identity;
205
- spinner.succeed(text ? style(text) : void 0);
206
- }
207
- },
208
- failAll: (text) => {
209
- for (const spinner of spinners) {
210
- const style = spinner.__failStyler ?? identity;
211
- spinner.fail(text ? style(text) : void 0);
212
- }
213
- },
214
- stopAll: () => {
215
- for (const spinner of spinners) {
216
- spinner.stop();
217
- }
218
- }
219
- };
220
- }
221
- export async function withEnhancedSpinner(textOrOptions, action) {
222
- const startTime = Date.now();
223
- const options = typeof textOrOptions === "string" ? { text: textOrOptions, showTiming: false } : { showTiming: false, ...textOrOptions };
224
- const baseSpinner = createSpinner(options).start();
225
- const enhancedSpinner = Object.assign(baseSpinner, {
226
- updateText: (text, updateOptions) => {
227
- updateSpinnerText(baseSpinner, text, updateOptions);
228
- },
229
- setProgress: (current, total, text) => {
230
- const progressText = text ? `${text} (${current}/${total})` : `${current}/${total}`;
231
- baseSpinner.text = progressText;
232
- }
233
- });
234
- try {
235
- const result = await action(enhancedSpinner);
236
- let successText = options.successText;
237
- if (options.showTiming && successText) {
238
- const elapsed = Date.now() - startTime;
239
- const timing = prettyMilliseconds(elapsed, { compact: true });
240
- successText = `${successText} (${timing})`;
241
- }
242
- baseSpinner.succeed(successText);
243
- return result;
244
- } catch (error) {
245
- const err = error;
246
- let failText = options.failText;
247
- if (options.showTiming && failText) {
248
- const elapsed = Date.now() - startTime;
249
- const timing = prettyMilliseconds(elapsed, { compact: true });
250
- failText = `${failText} (failed after ${timing})`;
251
- }
252
- baseSpinner.fail(failText);
253
- throw err;
254
- }
255
- }
256
- export function isSpinnerRunning(spinner) {
257
- return spinner.isSpinning;
258
- }
259
- export function safeStopSpinner(spinner) {
260
- if (spinner?.isSpinning) {
261
- spinner.stop();
262
- }
263
- }
264
- export function createBuildSpinner(operation, options) {
265
- const spinner = createSpinner({ text: operation, ...options }).start();
266
- return {
267
- spinner,
268
- complete: (message) => {
269
- const successStyle = spinner.__successStyler ?? identity;
270
- spinner.succeed(successStyle(message ?? `${operation} completed successfully!`));
271
- },
272
- error: (error) => {
273
- const errorMessage = typeof error === "string" ? error : error.message;
274
- const failStyle = spinner.__failStyler ?? identity;
275
- spinner.fail(failStyle(`${operation} failed: ${errorMessage}`));
276
- },
277
- updateProgress: (step) => {
278
- const info = spinner.__reTheme?.info ?? identity;
279
- updateSpinnerText(spinner, `${operation} - ${info(step)}`);
280
- }
281
- };
282
- }
283
- export function createFileProgressSpinner(operation, options) {
284
- const { totalBytes, showBytes = true, showRate = false, ...spinnerOptions } = options ?? {};
285
- const startTime = Date.now();
286
- const spinner = createSpinner({ text: operation, ...spinnerOptions }).start();
287
- return {
288
- spinner,
289
- updateProgress: (bytesProcessed, fileName) => {
290
- let progressText = operation;
291
- if (fileName) {
292
- const info = spinner.__reTheme?.info ?? identity;
293
- progressText += ` - ${info(fileName)}`;
294
- }
295
- if (showBytes) {
296
- if (totalBytes) {
297
- const percentage = Math.round(bytesProcessed / totalBytes * 100);
298
- const bytesColor = spinner.__reTheme?.bytesColor ?? identity;
299
- const percent = spinner.__reTheme?.percent ?? identity;
300
- progressText += ` (${bytesColor(prettyBytes(bytesProcessed))}/${bytesColor(prettyBytes(totalBytes))} - ${percent(`${percentage}%`)})`;
301
- } else {
302
- const bytesColor = spinner.__reTheme?.bytesColor ?? identity;
303
- progressText += ` (${bytesColor(prettyBytes(bytesProcessed))})`;
304
- }
305
- }
306
- spinner.text = progressText;
307
- },
308
- updateRate: (bytesPerSecond) => {
309
- if (showRate) {
310
- const currentText = spinner.text;
311
- const rate = spinner.__reTheme?.rate ?? identity;
312
- const rateText = rate(`${prettyBytes(bytesPerSecond)}/s`);
313
- spinner.text = `${currentText} @ ${rateText}`;
314
- }
315
- },
316
- complete: (message) => {
317
- const elapsed = Date.now() - startTime;
318
- const timing = prettyMilliseconds(elapsed, { compact: true });
319
- const dim = spinner.__reTheme?.dim ?? identity;
320
- const successStyle = spinner.__successStyler ?? identity;
321
- const successMessage = successStyle(message ?? `${operation} completed successfully`);
322
- spinner.succeed(`${successMessage} ${dim(`(${timing})`)}`);
323
- },
324
- error: (error) => {
325
- const elapsed = Date.now() - startTime;
326
- const timing = prettyMilliseconds(elapsed, { compact: true });
327
- const errorMessage = typeof error === "string" ? error : error.message;
328
- const dim = spinner.__reTheme?.dim ?? identity;
329
- const failStyle = spinner.__failStyler ?? identity;
330
- spinner.fail(
331
- `${failStyle(`${operation} failed: ${errorMessage}`)} ${dim(`(after ${timing})`)}`
332
- );
333
- }
334
- };
335
- }
336
- export function createMultiStepSpinner(operationName, steps, options) {
337
- const startTime = Date.now();
338
- let currentStepIndex = 0;
339
- const totalSteps = steps.length;
340
- const getStepText = (stepIndex) => {
341
- const step = steps[stepIndex];
342
- return `${operationName} - ${step} (${stepIndex + 1}/${totalSteps})`;
343
- };
344
- const spinner = createSpinner({ text: getStepText(0), ...options }).start();
345
- return {
346
- spinner,
347
- nextStep: (stepIndex) => {
348
- if (stepIndex !== void 0) {
349
- currentStepIndex = Math.min(stepIndex, totalSteps - 1);
350
- } else {
351
- currentStepIndex = Math.min(currentStepIndex + 1, totalSteps - 1);
352
- }
353
- const text = getStepText(currentStepIndex);
354
- updateSpinnerText(spinner, text);
355
- },
356
- complete: (message) => {
357
- const elapsed = Date.now() - startTime;
358
- const timing = prettyMilliseconds(elapsed, { compact: true });
359
- const dim = spinner.__reTheme?.dim ?? identity;
360
- const successStyle = spinner.__successStyler ?? identity;
361
- const successMessage = successStyle(message ?? `${operationName} completed successfully`);
362
- spinner.succeed(`${successMessage} ${dim(`(${timing})`)}`);
363
- },
364
- error: (error, stepIndex) => {
365
- const elapsed = Date.now() - startTime;
366
- const timing = prettyMilliseconds(elapsed, { compact: true });
367
- const errorMessage = typeof error === "string" ? error : error.message;
368
- const stepInfo = stepIndex !== void 0 ? ` at step ${stepIndex + 1}` : "";
369
- const dim = spinner.__reTheme?.dim ?? identity;
370
- const failStyle = spinner.__failStyler ?? identity;
371
- spinner.fail(
372
- `${failStyle(`${operationName} failed${stepInfo}: ${errorMessage}`)} ${dim(`(after ${timing})`)}`
373
- );
374
- },
375
- getCurrentStep: () => currentStepIndex
376
- };
377
- }
378
- export function formatSpinnerTiming(startTime, options) {
379
- const elapsed = Date.now() - startTime;
380
- const pmOptions = { compact: !options?.verbose };
381
- if (options?.verbose !== void 0) pmOptions["verbose"] = options.verbose;
382
- return prettyMilliseconds(elapsed, pmOptions);
383
- }
384
- export function formatSpinnerBytes(bytes, options) {
385
- return prettyBytes(bytes, options);
386
- }
387
- export function formatSpinnerElapsed(elapsed, options) {
388
- const pmOptions = { compact: !options?.verbose };
389
- if (options?.verbose !== void 0) pmOptions["verbose"] = options.verbose;
390
- return prettyMilliseconds(elapsed, pmOptions);
391
- }
392
- export function createTransferSpinner(operation, options) {
393
- const { totalBytes, showRate = true, ...spinnerOptions } = options ?? {};
394
- const startTime = Date.now();
395
- const spinner = createSpinner({ text: operation, ...spinnerOptions }).start();
396
- return {
397
- spinner,
398
- updateBytes: (bytesTransferred, fileName) => {
399
- let text = operation;
400
- if (fileName) {
401
- const info = spinner.__reTheme?.info ?? identity;
402
- text += ` - ${info(fileName)}`;
403
- }
404
- if (totalBytes) {
405
- const percentage = Math.round(bytesTransferred / totalBytes * 100);
406
- const bytesColor = spinner.__reTheme?.bytesColor ?? identity;
407
- const percent = spinner.__reTheme?.percent ?? identity;
408
- text += ` (${bytesColor(prettyBytes(bytesTransferred))}/${bytesColor(prettyBytes(totalBytes))} - ${percent(`${percentage}%`)})`;
409
- } else {
410
- const bytesColor = spinner.__reTheme?.bytesColor ?? identity;
411
- text += ` (${bytesColor(prettyBytes(bytesTransferred))})`;
412
- }
413
- spinner.text = text;
414
- },
415
- updateRate: (bytesPerSecond) => {
416
- if (showRate) {
417
- const currentText = spinner.text;
418
- const rate = spinner.__reTheme?.rate ?? identity;
419
- const rateText = rate(`${prettyBytes(bytesPerSecond)}/s`);
420
- spinner.text = `${currentText} @ ${rateText}`;
421
- }
422
- },
423
- complete: (message, totalBytesTransferred) => {
424
- const elapsed = Date.now() - startTime;
425
- const timing = prettyMilliseconds(elapsed, { compact: true });
426
- const dim = spinner.__reTheme?.dim ?? identity;
427
- const successStyle = spinner.__successStyler ?? identity;
428
- let successMessage = successStyle(message ?? `${operation} completed successfully`);
429
- if (totalBytesTransferred) {
430
- const bytesColor = spinner.__reTheme?.bytesColor ?? identity;
431
- successMessage += ` (${bytesColor(prettyBytes(totalBytesTransferred))})`;
432
- }
433
- successMessage += ` ${dim(`in ${timing}`)}`;
434
- spinner.succeed(successMessage);
435
- },
436
- error: (error) => {
437
- const elapsed = Date.now() - startTime;
438
- const timing = prettyMilliseconds(elapsed, { compact: true });
439
- const errorMessage = typeof error === "string" ? error : error.message;
440
- const dim = spinner.__reTheme?.dim ?? identity;
441
- const failStyle = spinner.__failStyler ?? identity;
442
- spinner.fail(
443
- `${failStyle(`${operation} failed: ${errorMessage}`)} ${dim(`(after ${timing})`)}`
444
- );
445
- }
446
- };
447
- }
@@ -1,2 +0,0 @@
1
- import type { ColorName, TypographyName } from "../../types";
2
- export declare function colorize(text: string, colorName?: ColorName, typography?: TypographyName): string;