@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,207 +0,0 @@
1
- import { stdin as input, stdout as output } from "node:process";
2
- import readline from "node:readline";
3
- import { re } from "@reliverse/relico";
4
- import { relinka } from "@reliverse/relinka";
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((option, index) => index === selectedIndex ? re.yellow(option) : re.reset(option)).join(re.dim(re.reset(" / ")));
57
- msg({ type: "M_NULL", title: displayString });
58
- uiLineCount++;
59
- if (debug) {
60
- relinka("log", "", {
61
- selectedIndex,
62
- displayOptions: options
63
- });
64
- }
65
- return uiLineCount;
66
- }
67
- export async function togglePrompt(params) {
68
- const {
69
- title = "",
70
- content = "",
71
- options = ["Yes", "No"],
72
- defaultValue = "Yes",
73
- borderColor = "dim",
74
- titleColor = "cyan",
75
- titleTypography = "none",
76
- titleVariant,
77
- contentColor = "dim",
78
- contentTypography = "italic",
79
- border = true,
80
- endTitle = "",
81
- endTitleColor = "dim",
82
- displayInstructions = false,
83
- debug = false
84
- } = params;
85
- if (options.length !== 2) {
86
- throw new Error("togglePrompt requires exactly two options.");
87
- }
88
- let selectedIndex = options.indexOf(defaultValue);
89
- if (selectedIndex === -1) {
90
- selectedIndex = 0;
91
- }
92
- const rl = readline.createInterface({ input, output });
93
- readline.emitKeypressEvents(input, rl);
94
- if (typeof input.setRawMode === "function") {
95
- input.setRawMode(true);
96
- }
97
- const instructions = "Use <\u2190/\u2192> or <h/l> to navigate, <Enter> to select, <Ctrl+C> to exit";
98
- let errorMessage = "";
99
- let lastUILineCount = 0;
100
- function renderOptions() {
101
- if (lastUILineCount > 0) {
102
- for (let i = 0; i < lastUILineCount; i++) {
103
- process.stdout.write("\x1B[1A\x1B[2K");
104
- }
105
- }
106
- lastUILineCount = renderTogglePrompt({
107
- title,
108
- content,
109
- options,
110
- selectedIndex,
111
- errorMessage,
112
- instructions,
113
- borderColor,
114
- titleColor,
115
- titleTypography,
116
- ...titleVariant ? { titleVariant } : {},
117
- contentColor,
118
- contentTypography,
119
- border,
120
- displayInstructions,
121
- debug,
122
- isRerender: true
123
- });
124
- }
125
- lastUILineCount = renderTogglePrompt({
126
- title,
127
- content,
128
- options,
129
- selectedIndex,
130
- errorMessage,
131
- instructions,
132
- borderColor,
133
- titleColor,
134
- titleTypography,
135
- ...titleVariant ? { titleVariant } : {},
136
- contentColor,
137
- contentTypography,
138
- border,
139
- displayInstructions,
140
- debug,
141
- isRerender: false
142
- });
143
- return new Promise((resolve) => {
144
- function cleanup(isCtrlC = false) {
145
- if (typeof input.setRawMode === "function") {
146
- input.setRawMode(false);
147
- }
148
- rl.close();
149
- input.removeListener("keypress", handleKeypress);
150
- if (isCtrlC) {
151
- process.exit(0);
152
- }
153
- }
154
- function endPrompt(isCtrlC = false) {
155
- if (endTitle !== "") {
156
- msg({
157
- type: "M_END",
158
- title: endTitle,
159
- titleColor: endTitleColor,
160
- titleTypography,
161
- ...titleVariant ? { titleVariant } : {},
162
- border,
163
- borderColor
164
- });
165
- }
166
- cleanup(isCtrlC);
167
- }
168
- function handleKeypress(_str, key) {
169
- if (key.name === "left" || key.name === "h") {
170
- selectedIndex = (selectedIndex - 1 + options.length) % options.length;
171
- errorMessage = "";
172
- renderOptions();
173
- } else if (key.name === "right" || key.name === "l") {
174
- selectedIndex = (selectedIndex + 1) % options.length;
175
- errorMessage = "";
176
- renderOptions();
177
- } else if (key.name === "return") {
178
- const selectedOption = options[selectedIndex];
179
- if (!selectedOption) {
180
- errorMessage = "You must select an option.";
181
- renderOptions();
182
- } else {
183
- cleanup();
184
- const booleanValue = selectedIndex === 0;
185
- void completePrompt(
186
- "toggle",
187
- false,
188
- endTitle,
189
- endTitleColor,
190
- titleTypography,
191
- titleVariant ? titleVariant : void 0,
192
- border,
193
- borderColor,
194
- void 0,
195
- booleanValue
196
- );
197
- resolve(booleanValue);
198
- deleteLastLine();
199
- msg({ type: "M_BAR", borderColor });
200
- }
201
- } else if (key.name === "c" && key.ctrl) {
202
- endPrompt(true);
203
- }
204
- }
205
- input.on("keypress", handleKeypress);
206
- });
207
- }
@@ -1,70 +0,0 @@
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 declare 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, randomSpinner } from "cli-spinners";
@@ -1,336 +0,0 @@
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 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, randomSpinner } from "cli-spinners";