@reliverse/rempts 1.7.44 → 1.7.45

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 (134) hide show
  1. package/README.md +1 -1
  2. package/dist-npm/bin/mod.d.mts +2333 -0
  3. package/dist-npm/bin/mod.mjs +8236 -0
  4. package/package.json +84 -42
  5. package/bin/libs/animate/animate-mod.d.ts +0 -14
  6. package/bin/libs/animate/animate-mod.js +0 -62
  7. package/bin/libs/anykey/anykey-mod.d.ts +0 -12
  8. package/bin/libs/anykey/anykey-mod.js +0 -125
  9. package/bin/libs/cancel/cancel.d.ts +0 -45
  10. package/bin/libs/cancel/cancel.js +0 -72
  11. package/bin/libs/confirm/confirm-alias.d.ts +0 -2
  12. package/bin/libs/confirm/confirm-alias.js +0 -2
  13. package/bin/libs/confirm/confirm-mod.d.ts +0 -5
  14. package/bin/libs/confirm/confirm-mod.js +0 -179
  15. package/bin/libs/date/date.d.ts +0 -2
  16. package/bin/libs/date/date.js +0 -236
  17. package/bin/libs/editor/editor-mod.d.ts +0 -25
  18. package/bin/libs/editor/editor-mod.js +0 -897
  19. package/bin/libs/figures/figures-mod.d.ts +0 -461
  20. package/bin/libs/figures/figures-mod.js +0 -285
  21. package/bin/libs/group/group-mod.d.ts +0 -33
  22. package/bin/libs/group/group-mod.js +0 -93
  23. package/bin/libs/input/input-alias.d.ts +0 -5
  24. package/bin/libs/input/input-alias.js +0 -4
  25. package/bin/libs/input/input-mod.d.ts +0 -16
  26. package/bin/libs/input/input-mod.js +0 -372
  27. package/bin/libs/intro/intro-alias.d.ts +0 -2
  28. package/bin/libs/intro/intro-alias.js +0 -3
  29. package/bin/libs/intro/intro-mod.d.ts +0 -20
  30. package/bin/libs/intro/intro-mod.js +0 -81
  31. package/bin/libs/launcher/command-runner.d.ts +0 -18
  32. package/bin/libs/launcher/command-runner.js +0 -79
  33. package/bin/libs/launcher/command-typed.d.ts +0 -16
  34. package/bin/libs/launcher/command-typed.js +0 -60
  35. package/bin/libs/launcher/launcher-alias.d.ts +0 -2
  36. package/bin/libs/launcher/launcher-alias.js +0 -2
  37. package/bin/libs/launcher/launcher-mod.d.ts +0 -162
  38. package/bin/libs/launcher/launcher-mod.js +0 -1222
  39. package/bin/libs/launcher/launcher-types.d.ts +0 -159
  40. package/bin/libs/launcher/launcher-types.js +0 -0
  41. package/bin/libs/launcher/trpc-orpc-support/completions.d.ts +0 -4
  42. package/bin/libs/launcher/trpc-orpc-support/completions.js +0 -45
  43. package/bin/libs/launcher/trpc-orpc-support/errors.d.ts +0 -11
  44. package/bin/libs/launcher/trpc-orpc-support/errors.js +0 -10
  45. package/bin/libs/launcher/trpc-orpc-support/index.d.ts +0 -34
  46. package/bin/libs/launcher/trpc-orpc-support/index.js +0 -641
  47. package/bin/libs/launcher/trpc-orpc-support/json-schema.d.ts +0 -17
  48. package/bin/libs/launcher/trpc-orpc-support/json-schema.js +0 -168
  49. package/bin/libs/launcher/trpc-orpc-support/json.d.ts +0 -44
  50. package/bin/libs/launcher/trpc-orpc-support/json.js +0 -41
  51. package/bin/libs/launcher/trpc-orpc-support/logging.d.ts +0 -11
  52. package/bin/libs/launcher/trpc-orpc-support/logging.js +0 -26
  53. package/bin/libs/launcher/trpc-orpc-support/parse-procedure.d.ts +0 -2
  54. package/bin/libs/launcher/trpc-orpc-support/parse-procedure.js +0 -486
  55. package/bin/libs/launcher/trpc-orpc-support/prompts.d.ts +0 -18
  56. package/bin/libs/launcher/trpc-orpc-support/prompts.js +0 -534
  57. package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.d.ts +0 -53
  58. package/bin/libs/launcher/trpc-orpc-support/standard-schema/contract.js +0 -0
  59. package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.d.ts +0 -9
  60. package/bin/libs/launcher/trpc-orpc-support/standard-schema/errors.js +0 -47
  61. package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.d.ts +0 -3
  62. package/bin/libs/launcher/trpc-orpc-support/standard-schema/utils.js +0 -6
  63. package/bin/libs/launcher/trpc-orpc-support/trpc-compat.d.ts +0 -71
  64. package/bin/libs/launcher/trpc-orpc-support/trpc-compat.js +0 -11
  65. package/bin/libs/launcher/trpc-orpc-support/types.d.ts +0 -276
  66. package/bin/libs/launcher/trpc-orpc-support/types.js +0 -0
  67. package/bin/libs/launcher/trpc-orpc-support/util.d.ts +0 -9
  68. package/bin/libs/launcher/trpc-orpc-support/util.js +0 -9
  69. package/bin/libs/log/log-alias.d.ts +0 -1
  70. package/bin/libs/log/log-alias.js +0 -2
  71. package/bin/libs/msg-fmt/colors.d.ts +0 -30
  72. package/bin/libs/msg-fmt/colors.js +0 -42
  73. package/bin/libs/msg-fmt/logger.d.ts +0 -17
  74. package/bin/libs/msg-fmt/logger.js +0 -103
  75. package/bin/libs/msg-fmt/mapping.d.ts +0 -3
  76. package/bin/libs/msg-fmt/mapping.js +0 -49
  77. package/bin/libs/msg-fmt/messages.d.ts +0 -35
  78. package/bin/libs/msg-fmt/messages.js +0 -319
  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 -348
  87. package/bin/libs/next-steps/next-steps.d.ts +0 -14
  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 -194
  91. package/bin/libs/outro/outro-alias.d.ts +0 -2
  92. package/bin/libs/outro/outro-alias.js +0 -3
  93. package/bin/libs/outro/outro-mod.d.ts +0 -8
  94. package/bin/libs/outro/outro-mod.js +0 -55
  95. package/bin/libs/results/results.d.ts +0 -7
  96. package/bin/libs/results/results.js +0 -27
  97. package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
  98. package/bin/libs/select/nummultiselect-prompt.js +0 -105
  99. package/bin/libs/select/numselect-prompt.d.ts +0 -7
  100. package/bin/libs/select/numselect-prompt.js +0 -115
  101. package/bin/libs/select/select-alias.d.ts +0 -9
  102. package/bin/libs/select/select-alias.js +0 -9
  103. package/bin/libs/select/select-prompt.d.ts +0 -5
  104. package/bin/libs/select/select-prompt.js +0 -314
  105. package/bin/libs/select/toggle-prompt.d.ts +0 -5
  106. package/bin/libs/select/toggle-prompt.js +0 -209
  107. package/bin/libs/spinner/spinner-alias.d.ts +0 -1
  108. package/bin/libs/spinner/spinner-alias.js +0 -2
  109. package/bin/libs/spinner/spinner-mod.d.ts +0 -106
  110. package/bin/libs/spinner/spinner-mod.js +0 -265
  111. package/bin/libs/task/progress.d.ts +0 -2
  112. package/bin/libs/task/progress.js +0 -57
  113. package/bin/libs/task/task-spin.d.ts +0 -15
  114. package/bin/libs/task/task-spin.js +0 -110
  115. package/bin/libs/utils/colorize.d.ts +0 -2
  116. package/bin/libs/utils/colorize.js +0 -135
  117. package/bin/libs/utils/errors.d.ts +0 -1
  118. package/bin/libs/utils/errors.js +0 -17
  119. package/bin/libs/utils/prevent.d.ts +0 -8
  120. package/bin/libs/utils/prevent.js +0 -65
  121. package/bin/libs/utils/prompt-end.d.ts +0 -8
  122. package/bin/libs/utils/prompt-end.js +0 -34
  123. package/bin/libs/utils/stream-text.d.ts +0 -18
  124. package/bin/libs/utils/stream-text.js +0 -136
  125. package/bin/libs/utils/system.d.ts +0 -6
  126. package/bin/libs/utils/system.js +0 -7
  127. package/bin/libs/utils/validate.d.ts +0 -21
  128. package/bin/libs/utils/validate.js +0 -17
  129. package/bin/libs/visual/visual-mod.d.ts +0 -6
  130. package/bin/libs/visual/visual-mod.js +0 -13
  131. package/bin/mod.d.ts +0 -69
  132. package/bin/mod.js +0 -159
  133. package/bin/types.d.ts +0 -371
  134. package/bin/types.js +0 -0
@@ -1,209 +0,0 @@
1
- import { re } from "@reliverse/relico";
2
- import { relinka } from "@reliverse/relinka";
3
- import { stdin as input, stdout as output } from "node:process";
4
- import readline from "node:readline";
5
- import { msg } from "../msg-fmt/messages.js";
6
- import { deleteLastLine } from "../msg-fmt/terminal.js";
7
- import { completePrompt } from "../utils/prompt-end.js";
8
- function renderTogglePrompt(params) {
9
- const {
10
- title,
11
- content,
12
- options,
13
- selectedIndex,
14
- errorMessage,
15
- instructions,
16
- titleColor,
17
- titleTypography,
18
- titleVariant,
19
- contentColor,
20
- contentTypography,
21
- displayInstructions,
22
- debug,
23
- isRerender = false
24
- } = params;
25
- if (!isRerender) {
26
- msg({
27
- type: "M_GENERAL",
28
- title,
29
- titleColor,
30
- titleTypography,
31
- ...titleVariant ? { titleVariant } : {}
32
- });
33
- if (content) {
34
- msg({
35
- type: "M_NULL",
36
- content: content.split("\n").map((line) => line.trim()).join("\n"),
37
- contentColor,
38
- contentTypography
39
- });
40
- }
41
- }
42
- let uiLineCount = 0;
43
- if (errorMessage) {
44
- msg({
45
- type: "M_NULL",
46
- title: re.redBright(errorMessage)
47
- });
48
- uiLineCount++;
49
- } else if (displayInstructions && !isRerender) {
50
- msg({
51
- type: "M_NULL",
52
- title: re.yellow(instructions)
53
- });
54
- uiLineCount++;
55
- }
56
- const displayString = options.map(
57
- (option, index) => index === selectedIndex ? re.yellow(option) : re.reset(option)
58
- ).join(re.dim(re.reset(" / ")));
59
- msg({ type: "M_NULL", title: displayString });
60
- uiLineCount++;
61
- if (debug) {
62
- relinka("log", "", {
63
- selectedIndex,
64
- displayOptions: options
65
- });
66
- }
67
- return uiLineCount;
68
- }
69
- export async function togglePrompt(params) {
70
- const {
71
- title = "",
72
- content = "",
73
- options = ["Yes", "No"],
74
- defaultValue = "Yes",
75
- borderColor = "dim",
76
- titleColor = "cyan",
77
- titleTypography = "none",
78
- titleVariant,
79
- contentColor = "dim",
80
- contentTypography = "italic",
81
- border = true,
82
- endTitle = "",
83
- endTitleColor = "dim",
84
- displayInstructions = false,
85
- debug = false
86
- } = params;
87
- if (options.length !== 2) {
88
- throw new Error("togglePrompt requires exactly two options.");
89
- }
90
- let selectedIndex = options.findIndex((option) => option === defaultValue);
91
- if (selectedIndex === -1) {
92
- selectedIndex = 0;
93
- }
94
- const rl = readline.createInterface({ input, output });
95
- readline.emitKeypressEvents(input, rl);
96
- if (typeof input.setRawMode === "function") {
97
- input.setRawMode(true);
98
- }
99
- const instructions = "Use <\u2190/\u2192> or <h/l> to navigate, <Enter> to select, <Ctrl+C> to exit";
100
- let errorMessage = "";
101
- let lastUILineCount = 0;
102
- function renderOptions() {
103
- if (lastUILineCount > 0) {
104
- for (let i = 0; i < lastUILineCount; i++) {
105
- process.stdout.write("\x1B[1A\x1B[2K");
106
- }
107
- }
108
- lastUILineCount = renderTogglePrompt({
109
- title,
110
- content,
111
- options,
112
- selectedIndex,
113
- errorMessage,
114
- instructions,
115
- borderColor,
116
- titleColor,
117
- titleTypography,
118
- ...titleVariant ? { titleVariant } : {},
119
- contentColor,
120
- contentTypography,
121
- border,
122
- displayInstructions,
123
- debug,
124
- isRerender: true
125
- });
126
- }
127
- lastUILineCount = renderTogglePrompt({
128
- title,
129
- content,
130
- options,
131
- selectedIndex,
132
- errorMessage,
133
- instructions,
134
- borderColor,
135
- titleColor,
136
- titleTypography,
137
- ...titleVariant ? { titleVariant } : {},
138
- contentColor,
139
- contentTypography,
140
- border,
141
- displayInstructions,
142
- debug,
143
- isRerender: false
144
- });
145
- return new Promise((resolve) => {
146
- function cleanup(isCtrlC = false) {
147
- if (typeof input.setRawMode === "function") {
148
- input.setRawMode(false);
149
- }
150
- rl.close();
151
- input.removeListener("keypress", handleKeypress);
152
- if (isCtrlC) {
153
- process.exit(0);
154
- }
155
- }
156
- function endPrompt(isCtrlC = false) {
157
- if (endTitle !== "") {
158
- msg({
159
- type: "M_END",
160
- title: endTitle,
161
- titleColor: endTitleColor,
162
- titleTypography,
163
- ...titleVariant ? { titleVariant } : {},
164
- border,
165
- borderColor
166
- });
167
- }
168
- cleanup(isCtrlC);
169
- }
170
- function handleKeypress(_str, key) {
171
- if (key.name === "left" || key.name === "h") {
172
- selectedIndex = (selectedIndex - 1 + options.length) % options.length;
173
- errorMessage = "";
174
- renderOptions();
175
- } else if (key.name === "right" || key.name === "l") {
176
- selectedIndex = (selectedIndex + 1) % options.length;
177
- errorMessage = "";
178
- renderOptions();
179
- } else if (key.name === "return") {
180
- const selectedOption = options[selectedIndex];
181
- if (!selectedOption) {
182
- errorMessage = "You must select an option.";
183
- renderOptions();
184
- } else {
185
- cleanup();
186
- const booleanValue = selectedIndex === 0;
187
- void completePrompt(
188
- "toggle",
189
- false,
190
- endTitle,
191
- endTitleColor,
192
- titleTypography,
193
- titleVariant ? titleVariant : void 0,
194
- border,
195
- borderColor,
196
- void 0,
197
- booleanValue
198
- );
199
- resolve(booleanValue);
200
- deleteLastLine();
201
- msg({ type: "M_BAR", borderColor });
202
- }
203
- } else if (key.name === "c" && key.ctrl) {
204
- endPrompt(true);
205
- }
206
- }
207
- input.on("keypress", handleKeypress);
208
- });
209
- }
@@ -1 +0,0 @@
1
- export declare const spinner: any;
@@ -1,2 +0,0 @@
1
- import { useSpinner } from "./spinner-mod.js";
2
- export const spinner = useSpinner;
@@ -1,106 +0,0 @@
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 {};
@@ -1,265 +0,0 @@
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(
113
- (options.frames ?? defaultFrames)[frameIndex] ?? ""
114
- );
115
- if (process.env.CI) {
116
- process.stdout.write(`${frame} ${state.text}...`);
117
- } else if (options.indicator === "timer") {
118
- process.stdout.write(
119
- `${frame} ${state.text} ${formatTimer(state.origin)}`
120
- );
121
- } else {
122
- const loadingDots = ".".repeat(Math.floor(state.indicatorTimer)).slice(0, 3);
123
- process.stdout.write(`${frame} ${state.text}${loadingDots}`);
124
- }
125
- frameIndex = (frameIndex + 1) % (options.frames ?? defaultFrames).length;
126
- state.indicatorTimer = state.indicatorTimer < 4 ? state.indicatorTimer + 0.125 : 0;
127
- }, options.delay ?? defaultDelay);
128
- return controls;
129
- },
130
- stop: (text, code = 0) => {
131
- if (!state.isActive) return;
132
- state.isActive = false;
133
- clearInterval(loop);
134
- clearPrevMessage();
135
- const step = code === 0 ? re.green("\u2713") : code === 1 ? re.red("\u2717") : re.red("\u2717");
136
- const finalText = text ?? state.text;
137
- if (options.indicator === "timer") {
138
- process.stdout.write(
139
- `${step} ${finalText} ${formatTimer(state.origin)}
140
- `
141
- );
142
- } else {
143
- process.stdout.write(`${step} ${finalText}
144
- `);
145
- }
146
- clearHooks();
147
- if (unblock) unblock();
148
- },
149
- setText: (text) => {
150
- state.text = removeTrailingDots(text);
151
- options.text = text;
152
- },
153
- setProgress: (progress) => {
154
- const progressText = formatProgress(progress);
155
- const newText = `${state.text} [${progressText}]`;
156
- state.text = newText;
157
- options.text = newText;
158
- },
159
- succeed: (text) => {
160
- const successText = text ?? options.successText ?? state.text;
161
- controls.stop(successText, 0);
162
- },
163
- fail: (text) => {
164
- const failText = text ?? options.failText ?? state.text;
165
- controls.stop(failText, 2);
166
- },
167
- warn: (text) => {
168
- const warnText = text ?? state.text;
169
- controls.stop(warnText, 0);
170
- },
171
- info: (text) => {
172
- const infoText = text ?? state.text;
173
- controls.stop(infoText, 0);
174
- },
175
- isSpinning: () => {
176
- return state.isActive && !state.isPaused;
177
- },
178
- clear: () => {
179
- clearPrevMessage();
180
- },
181
- getElapsedTime: () => {
182
- if (!state.startTime) return 0;
183
- const currentTime = Date.now();
184
- return currentTime - state.startTime - state.pausedTime;
185
- },
186
- pause: () => {
187
- if (state.isActive && !state.isPaused) {
188
- clearInterval(loop);
189
- state.isPaused = true;
190
- }
191
- },
192
- resume: () => {
193
- if (state.isActive && state.isPaused) {
194
- loop = setInterval(() => {
195
- }, options.delay ?? defaultDelay);
196
- state.isPaused = false;
197
- }
198
- },
199
- dispose: () => {
200
- if (state.isActive) {
201
- controls.stop();
202
- }
203
- state.isActive = false;
204
- state.isPaused = false;
205
- },
206
- get isCancelled() {
207
- return state.isCancelled;
208
- }
209
- };
210
- return controls;
211
- }
212
- useSpinner.promise = async (operation, options) => {
213
- const spinner = useSpinner(options).start();
214
- try {
215
- const result = await operation(spinner);
216
- spinner.succeed();
217
- return result;
218
- } catch (error) {
219
- spinner.fail();
220
- throw error;
221
- } finally {
222
- spinner.dispose();
223
- }
224
- };
225
- useSpinner.nested = (parentOptions) => {
226
- const parentSpinner = useSpinner({
227
- ...parentOptions,
228
- silent: true
229
- // Parent is silent, children will show progress
230
- });
231
- return {
232
- start: () => {
233
- parentSpinner.start();
234
- return {
235
- child: (childOptions) => useSpinner(childOptions),
236
- finish: (success, text) => {
237
- if (success) {
238
- parentSpinner.succeed(text);
239
- } else {
240
- parentSpinner.fail(text);
241
- }
242
- },
243
- dispose: () => parentSpinner.dispose()
244
- };
245
- }
246
- };
247
- };
248
- useSpinner.withTiming = async (operation, options) => {
249
- const spinner = useSpinner(options).start();
250
- const startTime = Date.now();
251
- try {
252
- const result = await operation(spinner);
253
- const duration = Date.now() - startTime;
254
- spinner.succeed(`${options.successText || options.text} (${duration}ms)`);
255
- return { result, duration };
256
- } catch (error) {
257
- const duration = Date.now() - startTime;
258
- spinner.fail(
259
- `${options.failText || options.text} (failed after ${duration}ms)`
260
- );
261
- throw error;
262
- } finally {
263
- spinner.dispose();
264
- }
265
- };
@@ -1,2 +0,0 @@
1
- import type { ProgressBar, ProgressBarOptions } from "../../types.js";
2
- export declare function taskProgressPrompt(options: ProgressBarOptions): Promise<ProgressBar>;
@@ -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 {};