@depup/ora 9.3.0-depup.0

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 (5) hide show
  1. package/index.d.ts +334 -0
  2. package/index.js +633 -0
  3. package/license +9 -0
  4. package/package.json +63 -0
  5. package/readme.md +399 -0
package/index.d.ts ADDED
@@ -0,0 +1,334 @@
1
+ import {type SpinnerName} from 'cli-spinners';
2
+
3
+ export type Spinner = {
4
+ readonly interval?: number;
5
+ readonly frames: string[];
6
+ };
7
+
8
+ export type Color =
9
+ | 'black'
10
+ | 'red'
11
+ | 'green'
12
+ | 'yellow'
13
+ | 'blue'
14
+ | 'magenta'
15
+ | 'cyan'
16
+ | 'white'
17
+ | 'gray';
18
+
19
+ export type PrefixTextGenerator = () => string;
20
+
21
+ export type SuffixTextGenerator = () => string;
22
+
23
+ export type Options = {
24
+ /**
25
+ The text to display next to the spinner.
26
+ */
27
+ readonly text?: string;
28
+
29
+ /**
30
+ Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
31
+ */
32
+ readonly prefixText?: string | PrefixTextGenerator;
33
+
34
+ /**
35
+ Text or a function that returns text to display after the spinner text. No suffix text will be displayed if set to an empty string.
36
+ */
37
+ readonly suffixText?: string | SuffixTextGenerator;
38
+
39
+ /**
40
+ The name of one of the provided spinners. See `example.js` in this repo if you want to test out different spinners. On Windows (except for Windows Terminal), it will always use the line spinner as the Windows command-line doesn't have proper Unicode support.
41
+
42
+ @default 'dots'
43
+
44
+ Or an object like:
45
+
46
+ @example
47
+ ```
48
+ {
49
+ frames: ['-', '+', '-'],
50
+ interval: 80 // Optional
51
+ }
52
+ ```
53
+ */
54
+ readonly spinner?: SpinnerName | Spinner;
55
+
56
+ /**
57
+ The color of the spinner.
58
+
59
+ @default 'cyan'
60
+ */
61
+ readonly color?: Color | boolean;
62
+
63
+ /**
64
+ Set to `false` to stop Ora from hiding the cursor.
65
+
66
+ @default true
67
+ */
68
+ readonly hideCursor?: boolean;
69
+
70
+ /**
71
+ Indent the spinner with the given number of spaces.
72
+
73
+ @default 0
74
+ */
75
+ readonly indent?: number;
76
+
77
+ /**
78
+ Interval between each frame.
79
+
80
+ Spinners provide their own recommended interval, so you don't really need to specify this.
81
+
82
+ Default: Provided by the spinner or `100`.
83
+ */
84
+ readonly interval?: number;
85
+
86
+ /**
87
+ Stream to write the output.
88
+
89
+ You could for example set this to `process.stdout` instead.
90
+
91
+ @default process.stderr
92
+ */
93
+ readonly stream?: NodeJS.WritableStream;
94
+
95
+ /**
96
+ Force enable/disable the spinner. If not specified, the spinner will be enabled if the `stream` is being run inside a TTY context (not spawned or piped) and/or not in a CI environment.
97
+
98
+ Note that `{isEnabled: false}` doesn't mean it won't output anything. It just means it won't output the spinner, colors, and other ansi escape codes. It will still log text.
99
+ */
100
+ readonly isEnabled?: boolean;
101
+
102
+ /**
103
+ Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
104
+
105
+ @default false
106
+ */
107
+ readonly isSilent?: boolean;
108
+
109
+ /**
110
+ Discard stdin input (except Ctrl+C) while running if it's TTY. This prevents the spinner from twitching on input, outputting broken lines on `Enter` key presses, and prevents buffering of input while the spinner is running.
111
+
112
+ This has no effect on Windows as there is no good way to implement discarding stdin properly there.
113
+
114
+ Note: `discardStdin` puts stdin into raw mode. In raw mode, `Ctrl+C` no longer generates `SIGINT` from the terminal. Ora re-emits `Ctrl+C` from stdin input, but if your code blocks the event loop with synchronous work, `Ctrl+C` handling is delayed until the blocking work ends. Use async APIs, a worker thread, or a child process to keep `Ctrl+C` responsive, or set `discardStdin` to `false`.
115
+
116
+ @default true
117
+ */
118
+ readonly discardStdin?: boolean;
119
+ };
120
+
121
+ export type PersistOptions = {
122
+ /**
123
+ Symbol to replace the spinner with.
124
+
125
+ @default ' '
126
+ */
127
+ readonly symbol?: string;
128
+
129
+ /**
130
+ Text to be persisted after the symbol.
131
+
132
+ Default: Current `text`.
133
+ */
134
+ readonly text?: string;
135
+
136
+ /**
137
+ Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
138
+
139
+ Default: Current `prefixText`.
140
+ */
141
+ readonly prefixText?: string | PrefixTextGenerator;
142
+
143
+ /**
144
+ Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string.
145
+
146
+ Default: Current `suffixText`.
147
+ */
148
+ readonly suffixText?: string | SuffixTextGenerator;
149
+ };
150
+
151
+ export type PromiseOptions<T> = {
152
+ /**
153
+ The new text of the spinner when the promise is resolved.
154
+
155
+ Keeps the existing text if `undefined`.
156
+ */
157
+ successText?: string | ((result: T) => string) | undefined;
158
+
159
+ /**
160
+ The new text of the spinner when the promise is rejected.
161
+
162
+ Keeps the existing text if `undefined`.
163
+ */
164
+ failText?: string | ((error: Error) => string) | undefined;
165
+ } & Options;
166
+
167
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
168
+ export interface Ora {
169
+ /**
170
+ Change the text after the spinner.
171
+ */
172
+ text: string;
173
+
174
+ /**
175
+ Change the text or function that returns text before the spinner.
176
+
177
+ No prefix text will be displayed if set to an empty string.
178
+ */
179
+ prefixText: string;
180
+
181
+ /**
182
+ Change the text or function that returns text after the spinner text.
183
+
184
+ No suffix text will be displayed if set to an empty string.
185
+ */
186
+ suffixText: string;
187
+
188
+ /**
189
+ Change the spinner color.
190
+ */
191
+ color: Color | boolean;
192
+
193
+ /**
194
+ Change the spinner indent.
195
+ */
196
+ indent: number;
197
+
198
+ /**
199
+ Get the spinner.
200
+ */
201
+ get spinner(): Spinner;
202
+
203
+ /**
204
+ Set the spinner.
205
+ */
206
+ set spinner(spinner: SpinnerName | Spinner);
207
+
208
+ /**
209
+ A boolean indicating whether the instance is currently spinning.
210
+ */
211
+ get isSpinning(): boolean;
212
+
213
+ /**
214
+ The interval between each frame.
215
+
216
+ The interval is decided by the chosen spinner.
217
+ */
218
+ get interval(): number;
219
+
220
+ /**
221
+ Start the spinner.
222
+
223
+ @param text - Set the current text.
224
+ @returns The spinner instance.
225
+ */
226
+ start(text?: string): this;
227
+
228
+ /**
229
+ Stop and clear the spinner.
230
+
231
+ @returns The spinner instance.
232
+ */
233
+ stop(): this;
234
+
235
+ /**
236
+ Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
237
+
238
+ @param text - Will persist text if provided.
239
+ @returns The spinner instance.
240
+ */
241
+ succeed(text?: string): this;
242
+
243
+ /**
244
+ Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
245
+
246
+ @param text - Will persist text if provided.
247
+ @returns The spinner instance.
248
+ */
249
+ fail(text?: string): this;
250
+
251
+ /**
252
+ Stop the spinner, change it to a yellow `âš ` and persist the current text, or `text` if provided.
253
+
254
+ @param text - Will persist text if provided.
255
+ @returns The spinner instance.
256
+ */
257
+ warn(text?: string): this;
258
+
259
+ /**
260
+ Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
261
+
262
+ @param text - Will persist text if provided.
263
+ @returns The spinner instance.
264
+ */
265
+ info(text?: string): this;
266
+
267
+ /**
268
+ Stop the spinner and change the symbol or text.
269
+
270
+ @returns The spinner instance.
271
+ */
272
+ stopAndPersist(options?: PersistOptions): this;
273
+
274
+ /**
275
+ Clear the spinner.
276
+
277
+ @returns The spinner instance.
278
+ */
279
+ clear(): this;
280
+
281
+ /**
282
+ Manually render a new frame.
283
+
284
+ @returns The spinner instance.
285
+ */
286
+ render(): this;
287
+
288
+ /**
289
+ Get a new frame.
290
+
291
+ @returns The spinner instance text.
292
+ */
293
+ frame(): string;
294
+ }
295
+
296
+ /**
297
+ Elegant terminal spinner.
298
+
299
+ @param options - If a string is provided, it is treated as a shortcut for `options.text`.
300
+
301
+ @example
302
+ ```
303
+ import ora from 'ora';
304
+
305
+ const spinner = ora('Loading unicorns').start();
306
+
307
+ setTimeout(() => {
308
+ spinner.color = 'yellow';
309
+ spinner.text = 'Loading rainbows';
310
+ }, 1000);
311
+ ```
312
+ */
313
+ export default function ora(options?: string | Options): Ora;
314
+
315
+ /**
316
+ Starts a spinner for a promise or promise-returning function. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
317
+
318
+ @param action - The promise to start the spinner for or a promise-returning function.
319
+ @param options - If a string is provided, it is treated as a shortcut for `options.text`.
320
+ @returns The given promise.
321
+
322
+ @example
323
+ ```
324
+ import {oraPromise} from 'ora';
325
+
326
+ await oraPromise(somePromise);
327
+ ```
328
+ */
329
+ export function oraPromise<T>(
330
+ action: PromiseLike<T> | ((spinner: Ora) => PromiseLike<T>),
331
+ options?: string | PromiseOptions<T>
332
+ ): Promise<T>;
333
+
334
+ export {default as spinners} from 'cli-spinners';
package/index.js ADDED
@@ -0,0 +1,633 @@
1
+ import process from 'node:process';
2
+ import {stripVTControlCharacters} from 'node:util';
3
+ import chalk from 'chalk';
4
+ import cliCursor from 'cli-cursor';
5
+ import cliSpinners from 'cli-spinners';
6
+ import logSymbols from 'log-symbols';
7
+ import stringWidth from 'string-width';
8
+ import isInteractive from 'is-interactive';
9
+ import isUnicodeSupported from 'is-unicode-supported';
10
+ import stdinDiscarder from 'stdin-discarder';
11
+
12
+ // Constants
13
+ const RENDER_DEFERRAL_TIMEOUT = 200; // Milliseconds to wait before re-rendering after partial chunk write
14
+ const SYNCHRONIZED_OUTPUT_ENABLE = '\u001B[?2026h';
15
+ const SYNCHRONIZED_OUTPUT_DISABLE = '\u001B[?2026l';
16
+
17
+ // Global state for concurrent spinner detection
18
+ const activeHooksPerStream = new Map(); // Stream → ora instance
19
+
20
+ class Ora {
21
+ #linesToClear = 0;
22
+ #frameIndex = -1;
23
+ #lastFrameTime = 0;
24
+ #options;
25
+ #spinner;
26
+ #stream;
27
+ #id;
28
+ #hookedStreams = new Map();
29
+ #isInternalWrite = false;
30
+ #drainHandler;
31
+ #deferRenderTimer;
32
+ #isDiscardingStdin = false;
33
+ color;
34
+
35
+ // Helper to execute writes while preventing hook recursion
36
+ #internalWrite(fn) {
37
+ this.#isInternalWrite = true;
38
+ try {
39
+ return fn();
40
+ } finally {
41
+ this.#isInternalWrite = false;
42
+ }
43
+ }
44
+
45
+ // Helper to render if still spinning
46
+ #tryRender() {
47
+ if (this.isSpinning) {
48
+ this.render();
49
+ }
50
+ }
51
+
52
+ #stringifyChunk(chunk, encoding) {
53
+ if (chunk === undefined || chunk === null) {
54
+ return '';
55
+ }
56
+
57
+ if (typeof chunk === 'string') {
58
+ return chunk;
59
+ }
60
+
61
+ /* eslint-disable n/prefer-global/buffer */
62
+ if (Buffer.isBuffer(chunk) || ArrayBuffer.isView(chunk)) {
63
+ const normalizedEncoding = (typeof encoding === 'string' && encoding && encoding !== 'buffer') ? encoding : 'utf8';
64
+ return Buffer.from(chunk).toString(normalizedEncoding);
65
+ }
66
+ /* eslint-enable n/prefer-global/buffer */
67
+
68
+ return String(chunk);
69
+ }
70
+
71
+ #chunkTerminatesLine(chunkString) {
72
+ if (!chunkString) {
73
+ return false;
74
+ }
75
+
76
+ const lastCharacter = chunkString.at(-1);
77
+ return lastCharacter === '\n' || lastCharacter === '\r';
78
+ }
79
+
80
+ #scheduleRenderDeferral() {
81
+ // If already deferred, don't reset timer - let it complete
82
+ if (this.#deferRenderTimer) {
83
+ return;
84
+ }
85
+
86
+ this.#deferRenderTimer = setTimeout(() => {
87
+ this.#deferRenderTimer = undefined;
88
+
89
+ if (this.isSpinning) {
90
+ this.#tryRender();
91
+ }
92
+ }, RENDER_DEFERRAL_TIMEOUT);
93
+
94
+ if (typeof this.#deferRenderTimer?.unref === 'function') {
95
+ this.#deferRenderTimer.unref();
96
+ }
97
+ }
98
+
99
+ #clearRenderDeferral() {
100
+ if (this.#deferRenderTimer) {
101
+ clearTimeout(this.#deferRenderTimer);
102
+ this.#deferRenderTimer = undefined;
103
+ }
104
+ }
105
+
106
+ // Helper to build complete line with symbol, text, prefix, and suffix
107
+ #buildOutputLine(symbol, text, prefixText, suffixText) {
108
+ const fullPrefixText = this.#getFullPrefixText(prefixText, ' ');
109
+ const separatorText = symbol ? ' ' : '';
110
+ const fullText = (typeof text === 'string') ? separatorText + text : '';
111
+ const fullSuffixText = this.#getFullSuffixText(suffixText, ' ');
112
+ return fullPrefixText + symbol + fullText + fullSuffixText;
113
+ }
114
+
115
+ constructor(options) {
116
+ if (typeof options === 'string') {
117
+ options = {
118
+ text: options,
119
+ };
120
+ }
121
+
122
+ this.#options = {
123
+ color: 'cyan',
124
+ stream: process.stderr,
125
+ discardStdin: true,
126
+ hideCursor: true,
127
+ ...options,
128
+ };
129
+
130
+ // Public
131
+ this.color = this.#options.color;
132
+
133
+ this.#stream = this.#options.stream;
134
+
135
+ // Normalize isEnabled and isSilent into options
136
+ if (typeof this.#options.isEnabled !== 'boolean') {
137
+ this.#options.isEnabled = isInteractive({stream: this.#stream});
138
+ }
139
+
140
+ if (typeof this.#options.isSilent !== 'boolean') {
141
+ this.#options.isSilent = false;
142
+ }
143
+
144
+ // Set *after* `this.#stream`.
145
+ // Store original interval before spinner setter clears it
146
+ const userInterval = this.#options.interval;
147
+ // It's important that these use the public setters.
148
+ this.spinner = this.#options.spinner;
149
+ this.#options.interval = userInterval;
150
+ this.text = this.#options.text;
151
+ this.prefixText = this.#options.prefixText;
152
+ this.suffixText = this.#options.suffixText;
153
+ this.indent = this.#options.indent;
154
+
155
+ if (process.env.NODE_ENV === 'test') {
156
+ this._stream = this.#stream;
157
+ this._isEnabled = this.#options.isEnabled;
158
+
159
+ Object.defineProperty(this, '_linesToClear', {
160
+ get() {
161
+ return this.#linesToClear;
162
+ },
163
+ set(newValue) {
164
+ this.#linesToClear = newValue;
165
+ },
166
+ });
167
+
168
+ Object.defineProperty(this, '_frameIndex', {
169
+ get() {
170
+ return this.#frameIndex;
171
+ },
172
+ });
173
+
174
+ Object.defineProperty(this, '_lineCount', {
175
+ get() {
176
+ const columns = this.#stream.columns ?? 80;
177
+ const prefixText = typeof this.#options.prefixText === 'function' ? '' : this.#options.prefixText;
178
+ const suffixText = typeof this.#options.suffixText === 'function' ? '' : this.#options.suffixText;
179
+ const fullPrefixText = (typeof prefixText === 'string' && prefixText !== '') ? prefixText + ' ' : '';
180
+ const fullSuffixText = (typeof suffixText === 'string' && suffixText !== '') ? ' ' + suffixText : '';
181
+ const spinnerChar = '-';
182
+ const fullText = ' '.repeat(this.#options.indent) + fullPrefixText + spinnerChar + (typeof this.#options.text === 'string' ? ' ' + this.#options.text : '') + fullSuffixText;
183
+ return this.#computeLineCountFrom(fullText, columns);
184
+ },
185
+ });
186
+ }
187
+ }
188
+
189
+ get indent() {
190
+ return this.#options.indent;
191
+ }
192
+
193
+ set indent(indent = 0) {
194
+ if (!(indent >= 0 && Number.isInteger(indent))) {
195
+ throw new Error('The `indent` option must be an integer from 0 and up');
196
+ }
197
+
198
+ this.#options.indent = indent;
199
+ }
200
+
201
+ get interval() {
202
+ return this.#options.interval ?? this.#spinner.interval ?? 100;
203
+ }
204
+
205
+ get spinner() {
206
+ return this.#spinner;
207
+ }
208
+
209
+ set spinner(spinner) {
210
+ this.#frameIndex = -1;
211
+ this.#options.interval = undefined;
212
+
213
+ if (typeof spinner === 'object') {
214
+ if (!Array.isArray(spinner.frames) || spinner.frames.length === 0 || spinner.frames.some(frame => typeof frame !== 'string')) {
215
+ throw new Error('The given spinner must have a non-empty `frames` array of strings');
216
+ }
217
+
218
+ if (spinner.interval !== undefined && !(Number.isInteger(spinner.interval) && spinner.interval > 0)) {
219
+ throw new Error('`spinner.interval` must be a positive integer if provided');
220
+ }
221
+
222
+ this.#spinner = spinner;
223
+ } else if (!isUnicodeSupported()) {
224
+ this.#spinner = cliSpinners.line;
225
+ } else if (spinner === undefined) {
226
+ // Set default spinner
227
+ this.#spinner = cliSpinners.dots;
228
+ } else if (spinner !== 'default' && cliSpinners[spinner]) {
229
+ this.#spinner = cliSpinners[spinner];
230
+ } else {
231
+ throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
232
+ }
233
+ }
234
+
235
+ get text() {
236
+ return this.#options.text;
237
+ }
238
+
239
+ set text(value = '') {
240
+ this.#options.text = value;
241
+ }
242
+
243
+ get prefixText() {
244
+ return this.#options.prefixText;
245
+ }
246
+
247
+ set prefixText(value = '') {
248
+ this.#options.prefixText = value;
249
+ }
250
+
251
+ get suffixText() {
252
+ return this.#options.suffixText;
253
+ }
254
+
255
+ set suffixText(value = '') {
256
+ this.#options.suffixText = value;
257
+ }
258
+
259
+ get isSpinning() {
260
+ return this.#id !== undefined;
261
+ }
262
+
263
+ #formatAffix(value, separator, placeBefore = false) {
264
+ const resolved = typeof value === 'function' ? value() : value;
265
+ if (typeof resolved === 'string' && resolved !== '') {
266
+ return placeBefore ? (separator + resolved) : (resolved + separator);
267
+ }
268
+
269
+ return '';
270
+ }
271
+
272
+ #getFullPrefixText(prefixText = this.#options.prefixText, postfix = ' ') {
273
+ return this.#formatAffix(prefixText, postfix, false);
274
+ }
275
+
276
+ #getFullSuffixText(suffixText = this.#options.suffixText, prefix = ' ') {
277
+ return this.#formatAffix(suffixText, prefix, true);
278
+ }
279
+
280
+ #computeLineCountFrom(text, columns) {
281
+ let count = 0;
282
+ for (const line of stripVTControlCharacters(text).split('\n')) {
283
+ count += Math.max(1, Math.ceil(stringWidth(line) / columns));
284
+ }
285
+
286
+ return count;
287
+ }
288
+
289
+ get isEnabled() {
290
+ return this.#options.isEnabled && !this.#options.isSilent;
291
+ }
292
+
293
+ set isEnabled(value) {
294
+ if (typeof value !== 'boolean') {
295
+ throw new TypeError('The `isEnabled` option must be a boolean');
296
+ }
297
+
298
+ this.#options.isEnabled = value;
299
+ }
300
+
301
+ get isSilent() {
302
+ return this.#options.isSilent;
303
+ }
304
+
305
+ set isSilent(value) {
306
+ if (typeof value !== 'boolean') {
307
+ throw new TypeError('The `isSilent` option must be a boolean');
308
+ }
309
+
310
+ this.#options.isSilent = value;
311
+ }
312
+
313
+ frame() {
314
+ // Only advance frame if enough time has passed (throttle to interval)
315
+ const now = Date.now();
316
+ if (this.#frameIndex === -1 || now - this.#lastFrameTime >= this.interval) {
317
+ this.#frameIndex = (this.#frameIndex + 1) % this.#spinner.frames.length;
318
+ this.#lastFrameTime = now;
319
+ }
320
+
321
+ const {frames} = this.#spinner;
322
+ let frame = frames[this.#frameIndex];
323
+
324
+ if (this.color) {
325
+ frame = chalk[this.color](frame);
326
+ }
327
+
328
+ const fullPrefixText = this.#getFullPrefixText(this.#options.prefixText, ' ');
329
+ const fullText = typeof this.text === 'string' ? ' ' + this.text : '';
330
+ const fullSuffixText = this.#getFullSuffixText(this.#options.suffixText, ' ');
331
+
332
+ return fullPrefixText + frame + fullText + fullSuffixText;
333
+ }
334
+
335
+ clear() {
336
+ if (!this.isEnabled || !this.#stream.isTTY) {
337
+ return this;
338
+ }
339
+
340
+ // Protect cursor control methods (cursorTo, moveCursor, clearLine) which internally call stream.write
341
+ this.#internalWrite(() => {
342
+ this.#stream.cursorTo(0);
343
+
344
+ for (let index = 0; index < this.#linesToClear; index++) {
345
+ if (index > 0) {
346
+ this.#stream.moveCursor(0, -1);
347
+ }
348
+
349
+ this.#stream.clearLine(1);
350
+ }
351
+
352
+ if (this.#options.indent) {
353
+ this.#stream.cursorTo(this.#options.indent);
354
+ }
355
+ });
356
+
357
+ this.#linesToClear = 0;
358
+
359
+ return this;
360
+ }
361
+
362
+ // Helper to hook a single stream
363
+ #hookStream(stream) {
364
+ if (!stream || this.#hookedStreams.has(stream) || !stream.isTTY || typeof stream.write !== 'function') {
365
+ return;
366
+ }
367
+
368
+ // Detect concurrent spinners
369
+ if (activeHooksPerStream.has(stream)) {
370
+ console.warn('[ora] Multiple concurrent spinners detected. This may cause visual corruption. Use one spinner at a time.');
371
+ }
372
+
373
+ const originalWrite = stream.write;
374
+ this.#hookedStreams.set(stream, originalWrite);
375
+ activeHooksPerStream.set(stream, this);
376
+ stream.write = (chunk, encoding, callback) => this.#hookedWrite(stream, originalWrite, chunk, encoding, callback);
377
+ }
378
+
379
+ /**
380
+ Intercept stream writes while spinner is active to handle external writes cleanly without visual corruption.
381
+ Hooks process stdio streams and the active spinner stream so console.log(), console.error(), and direct writes stay tidy.
382
+ */
383
+ #installHook() {
384
+ if (!this.isEnabled || this.#hookedStreams.size > 0) {
385
+ return;
386
+ }
387
+
388
+ const streamsToHook = new Set([this.#stream, process.stdout, process.stderr]);
389
+
390
+ for (const stream of streamsToHook) {
391
+ this.#hookStream(stream);
392
+ }
393
+ }
394
+
395
+ #uninstallHook() {
396
+ for (const [stream, originalWrite] of this.#hookedStreams) {
397
+ stream.write = originalWrite;
398
+ if (activeHooksPerStream.get(stream) === this) {
399
+ activeHooksPerStream.delete(stream);
400
+ }
401
+ }
402
+
403
+ this.#hookedStreams.clear();
404
+ }
405
+
406
+ // eslint-disable-next-line max-params -- Need stream and originalWrite for multi-stream support
407
+ #hookedWrite(stream, originalWrite, chunk, encoding, callback) {
408
+ // Handle both write(chunk, encoding, callback) and write(chunk, callback) signatures
409
+ if (typeof encoding === 'function') {
410
+ callback = encoding;
411
+ encoding = undefined;
412
+ }
413
+
414
+ // Pass through our own internal writes (spinner rendering, cursor control)
415
+ if (this.#isInternalWrite) {
416
+ return originalWrite.call(stream, chunk, encoding, callback);
417
+ }
418
+
419
+ // External write detected - clear spinner, write content, re-render if appropriate
420
+ this.clear();
421
+
422
+ const chunkString = this.#stringifyChunk(chunk, encoding);
423
+ const chunkTerminatesLine = this.#chunkTerminatesLine(chunkString);
424
+
425
+ const writeResult = originalWrite.call(stream, chunk, encoding, callback);
426
+
427
+ // Schedule or clear render deferral based on chunk content
428
+ if (chunkTerminatesLine) {
429
+ this.#clearRenderDeferral();
430
+ } else if (chunkString.length > 0) {
431
+ this.#scheduleRenderDeferral();
432
+ }
433
+
434
+ // Re-render spinner below the new output if still spinning and not deferred
435
+ if (this.isSpinning && !this.#deferRenderTimer) {
436
+ this.render();
437
+ }
438
+
439
+ return writeResult;
440
+ }
441
+
442
+ render() {
443
+ if (!this.isEnabled || this.#drainHandler || this.#deferRenderTimer) {
444
+ return this;
445
+ }
446
+
447
+ const useSynchronizedOutput = this.#stream.isTTY;
448
+ let shouldDisableSynchronizedOutput = false;
449
+
450
+ try {
451
+ if (useSynchronizedOutput) {
452
+ this.#internalWrite(() => this.#stream.write(SYNCHRONIZED_OUTPUT_ENABLE));
453
+ shouldDisableSynchronizedOutput = true;
454
+ }
455
+
456
+ this.clear();
457
+
458
+ let frameContent = this.frame();
459
+ const columns = this.#stream.columns ?? 80;
460
+ const actualLineCount = this.#computeLineCountFrom(frameContent, columns);
461
+
462
+ // If content would exceed viewport height, truncate it to prevent garbage
463
+ const consoleHeight = this.#stream.rows;
464
+ if (consoleHeight && consoleHeight > 1 && actualLineCount > consoleHeight) {
465
+ const lines = frameContent.split('\n');
466
+ const maxLines = consoleHeight - 1; // Reserve one line for truncation message
467
+ frameContent = [...lines.slice(0, maxLines), '... (content truncated to fit terminal)'].join('\n');
468
+ }
469
+
470
+ const canContinue = this.#internalWrite(() => this.#stream.write(frameContent));
471
+
472
+ // Handle backpressure - pause rendering if stream buffer is full
473
+ if (canContinue === false && this.#stream.isTTY) {
474
+ this.#drainHandler = () => {
475
+ this.#drainHandler = undefined;
476
+ this.#tryRender();
477
+ };
478
+
479
+ this.#stream.once('drain', this.#drainHandler);
480
+ }
481
+
482
+ this.#linesToClear = this.#computeLineCountFrom(frameContent, columns);
483
+ } finally {
484
+ if (shouldDisableSynchronizedOutput) {
485
+ this.#internalWrite(() => this.#stream.write(SYNCHRONIZED_OUTPUT_DISABLE));
486
+ }
487
+ }
488
+
489
+ return this;
490
+ }
491
+
492
+ start(text) {
493
+ if (text) {
494
+ this.text = text;
495
+ }
496
+
497
+ if (this.isSilent) {
498
+ return this;
499
+ }
500
+
501
+ if (!this.isEnabled) {
502
+ const symbol = this.text ? '-' : '';
503
+ const line = ' '.repeat(this.#options.indent) + this.#buildOutputLine(symbol, this.text, this.#options.prefixText, this.#options.suffixText);
504
+
505
+ if (line.trim() !== '') {
506
+ this.#internalWrite(() => this.#stream.write(line + '\n'));
507
+ }
508
+
509
+ return this;
510
+ }
511
+
512
+ if (this.isSpinning) {
513
+ return this;
514
+ }
515
+
516
+ if (this.#options.hideCursor) {
517
+ cliCursor.hide(this.#stream);
518
+ }
519
+
520
+ if (this.#options.discardStdin && process.stdin.isTTY) {
521
+ stdinDiscarder.start();
522
+ this.#isDiscardingStdin = true;
523
+ }
524
+
525
+ this.#installHook();
526
+ this.render();
527
+ this.#id = setInterval(this.render.bind(this), this.interval);
528
+
529
+ return this;
530
+ }
531
+
532
+ stop() {
533
+ clearInterval(this.#id);
534
+ this.#id = undefined;
535
+ this.#frameIndex = -1;
536
+ this.#lastFrameTime = 0;
537
+
538
+ this.#clearRenderDeferral();
539
+ this.#uninstallHook();
540
+
541
+ // Clean up drain handler if it exists
542
+ if (this.#drainHandler) {
543
+ this.#stream.removeListener('drain', this.#drainHandler);
544
+ this.#drainHandler = undefined;
545
+ }
546
+
547
+ if (this.isEnabled) {
548
+ this.clear();
549
+ if (this.#options.hideCursor) {
550
+ cliCursor.show(this.#stream);
551
+ }
552
+ }
553
+
554
+ if (this.#isDiscardingStdin) {
555
+ this.#isDiscardingStdin = false;
556
+ stdinDiscarder.stop();
557
+ }
558
+
559
+ return this;
560
+ }
561
+
562
+ succeed(text) {
563
+ return this.stopAndPersist({symbol: logSymbols.success, text});
564
+ }
565
+
566
+ fail(text) {
567
+ return this.stopAndPersist({symbol: logSymbols.error, text});
568
+ }
569
+
570
+ warn(text) {
571
+ return this.stopAndPersist({symbol: logSymbols.warning, text});
572
+ }
573
+
574
+ info(text) {
575
+ return this.stopAndPersist({symbol: logSymbols.info, text});
576
+ }
577
+
578
+ stopAndPersist(options = {}) {
579
+ if (this.isSilent) {
580
+ return this;
581
+ }
582
+
583
+ const symbol = options.symbol ?? ' ';
584
+ const text = options.text ?? this.text;
585
+ const prefixText = options.prefixText ?? this.#options.prefixText;
586
+ const suffixText = options.suffixText ?? this.#options.suffixText;
587
+
588
+ const textToWrite = this.#buildOutputLine(symbol, text, prefixText, suffixText) + '\n';
589
+
590
+ this.stop();
591
+ this.#internalWrite(() => this.#stream.write(textToWrite));
592
+
593
+ return this;
594
+ }
595
+ }
596
+
597
+ export default function ora(options) {
598
+ return new Ora(options);
599
+ }
600
+
601
+ export async function oraPromise(action, options) {
602
+ const actionIsFunction = typeof action === 'function';
603
+ const actionIsPromise = typeof action.then === 'function';
604
+
605
+ if (!actionIsFunction && !actionIsPromise) {
606
+ throw new TypeError('Parameter `action` must be a Function or a Promise');
607
+ }
608
+
609
+ const {successText, failText} = typeof options === 'object'
610
+ ? options
611
+ : {successText: undefined, failText: undefined};
612
+
613
+ const spinner = ora(options).start();
614
+
615
+ try {
616
+ const promise = actionIsFunction ? action(spinner) : action;
617
+ const result = await promise;
618
+
619
+ spinner.succeed(successText === undefined
620
+ ? undefined
621
+ : (typeof successText === 'string' ? successText : successText(result)));
622
+
623
+ return result;
624
+ } catch (error) {
625
+ spinner.fail(failText === undefined
626
+ ? undefined
627
+ : (typeof failText === 'string' ? failText : failText(error)));
628
+
629
+ throw error;
630
+ }
631
+ }
632
+
633
+ export {default as spinners} from 'cli-spinners';
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@depup/ora",
3
+ "version": "9.3.0-depup.0",
4
+ "description": "Elegant terminal spinner",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/ora",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "scripts": {
23
+ "test": "xo && NODE_ENV=test node --test test.js && tsd"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts"
28
+ ],
29
+ "keywords": [
30
+ "cli",
31
+ "spinner",
32
+ "spinners",
33
+ "terminal",
34
+ "term",
35
+ "console",
36
+ "ascii",
37
+ "unicode",
38
+ "loading",
39
+ "indicator",
40
+ "progress",
41
+ "busy",
42
+ "wait",
43
+ "idle"
44
+ ],
45
+ "dependencies": {
46
+ "chalk": "^5.6.2",
47
+ "cli-cursor": "^5.0.0",
48
+ "cli-spinners": "^3.4.0",
49
+ "is-interactive": "^2.0.0",
50
+ "is-unicode-supported": "^2.1.0",
51
+ "log-symbols": "^7.0.1",
52
+ "stdin-discarder": "^0.3.1",
53
+ "string-width": "^8.2.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^24.5.0",
57
+ "ava": "^6.4.1",
58
+ "get-stream": "^9.0.1",
59
+ "transform-tty": "^1.0.11",
60
+ "tsd": "^0.33.0",
61
+ "xo": "^1.2.2"
62
+ }
63
+ }
package/readme.md ADDED
@@ -0,0 +1,399 @@
1
+ # ora
2
+
3
+ > Elegant terminal spinner
4
+
5
+ <p align="center">
6
+ <br>
7
+ <img src="screenshot.svg" width="500">
8
+ <br>
9
+ </p>
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install ora
15
+ ```
16
+
17
+ *Check out [`yocto-spinner`](https://github.com/sindresorhus/yocto-spinner) for a smaller alternative.*
18
+
19
+ ## Usage
20
+
21
+ ```js
22
+ import ora from 'ora';
23
+
24
+ const spinner = ora('Loading unicorns').start();
25
+
26
+ setTimeout(() => {
27
+ spinner.color = 'yellow';
28
+ spinner.text = 'Loading rainbows';
29
+ }, 1000);
30
+ ```
31
+
32
+ ## API
33
+
34
+ ### ora(text)
35
+ ### ora(options)
36
+
37
+ If a string is provided, it is treated as a shortcut for [`options.text`](#text).
38
+
39
+ #### options
40
+
41
+ Type: `object`
42
+
43
+ ##### text
44
+
45
+ Type: `string`
46
+
47
+ The text to display next to the spinner.
48
+
49
+ ##### prefixText
50
+
51
+ Type: `string | () => string`
52
+
53
+ Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
54
+
55
+ ##### suffixText
56
+
57
+ Type: `string | () => string`
58
+
59
+ Text or a function that returns text to display after the spinner text. No suffix text will be displayed if set to an empty string.
60
+
61
+ ##### spinner
62
+
63
+ Type: `string | object`\
64
+ Default: `'dots'` <img src="screenshot-spinner.gif" width="14">
65
+
66
+ The name of one of the [provided spinners](#spinners). See `example.js` in this repo if you want to test out different spinners. On Windows (except for Windows Terminal), it will always use the `line` spinner as the Windows command-line doesn't have proper Unicode support.
67
+
68
+ Or an object like:
69
+
70
+ ```js
71
+ {
72
+ frames: ['-', '+', '-'],
73
+ interval: 80 // Optional
74
+ }
75
+ ```
76
+
77
+ ##### color
78
+
79
+ Type: `string | boolean`\
80
+ Default: `'cyan'`\
81
+ Values: `'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | boolean`
82
+
83
+ The color of the spinner. Set to `false` to disable coloring.
84
+
85
+ ##### hideCursor
86
+
87
+ Type: `boolean`\
88
+ Default: `true`
89
+
90
+ Set to `false` to stop Ora from hiding the cursor.
91
+
92
+ ##### indent
93
+
94
+ Type: `number`\
95
+ Default: `0`
96
+
97
+ Indent the spinner with the given number of spaces.
98
+
99
+ ##### interval
100
+
101
+ Type: `number`\
102
+ Default: Provided by the spinner or `100`
103
+
104
+ Interval between each frame.
105
+
106
+ Spinners provide their own recommended interval, so you don't really need to specify this.
107
+
108
+ ##### stream
109
+
110
+ Type: `stream.Writable`\
111
+ Default: `process.stderr`
112
+
113
+ Stream to write the output.
114
+
115
+ You could for example set this to `process.stdout` instead.
116
+
117
+ ##### isEnabled
118
+
119
+ Type: `boolean`
120
+
121
+ Force enable/disable the spinner. If not specified, the spinner will be enabled if the `stream` is being run inside a TTY context (not spawned or piped) and/or not in a CI environment.
122
+
123
+ Note that `{isEnabled: false}` doesn't mean it won't output anything. It just means it won't output the spinner, colors, and other ansi escape codes. It will still log text.
124
+
125
+ ##### isSilent
126
+
127
+ Type: `boolean`\
128
+ Default: `false`
129
+
130
+ Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
131
+
132
+ ##### discardStdin
133
+
134
+ Type: `boolean`\
135
+ Default: `true`
136
+
137
+ Discard stdin input (except Ctrl+C) while running if it's TTY. This prevents the spinner from twitching on input, outputting broken lines on <kbd>Enter</kbd> key presses, and prevents buffering of input while the spinner is running.
138
+
139
+ This has no effect on Windows as there is no good way to implement discarding stdin properly there.
140
+
141
+ Note: `discardStdin` puts stdin into raw mode. In raw mode, `Ctrl+C` no longer generates `SIGINT` from the terminal. Ora re-emits `Ctrl+C` from stdin input, but if your code blocks the event loop with synchronous work, `Ctrl+C` handling is delayed until the blocking work ends. Use async APIs, a worker thread, or a child process to keep `Ctrl+C` responsive, or set `discardStdin` to `false`.
142
+
143
+ ### Instance
144
+
145
+ #### .text <sup>get/set</sup>
146
+
147
+ Change the text displayed after the spinner.
148
+
149
+ #### .prefixText <sup>get/set</sup>
150
+
151
+ Change the text before the spinner.
152
+
153
+ No prefix text will be displayed if set to an empty string.
154
+
155
+ #### .suffixText <sup>get/set</sup>
156
+
157
+ Change the text after the spinner text.
158
+
159
+ No suffix text will be displayed if set to an empty string.
160
+
161
+ #### .color <sup>get/set</sup>
162
+
163
+ Change the spinner color.
164
+
165
+ #### .spinner <sup>get/set</sup>
166
+
167
+ Change the spinner.
168
+
169
+ #### .indent <sup>get/set</sup>
170
+
171
+ Change the spinner indent.
172
+
173
+ #### .isSpinning <sup>get</sup>
174
+
175
+ A boolean indicating whether the instance is currently spinning.
176
+
177
+ #### .interval <sup>get</sup>
178
+
179
+ The interval between each frame.
180
+
181
+ The interval is decided by the chosen spinner.
182
+
183
+ #### .start(text?)
184
+
185
+ Start the spinner. Returns the instance. Set the current text if `text` is provided.
186
+
187
+ #### .stop()
188
+
189
+ Stop and clear the spinner. Returns the instance.
190
+
191
+ #### .succeed(text?)
192
+
193
+ Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
194
+
195
+ #### .fail(text?)
196
+
197
+ Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
198
+
199
+ #### .warn(text?)
200
+
201
+ Stop the spinner, change it to a yellow `âš ` and persist the current text, or `text` if provided. Returns the instance.
202
+
203
+ #### .info(text?)
204
+
205
+ Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided. Returns the instance.
206
+
207
+ #### .stopAndPersist(options?)
208
+
209
+ Stop the spinner and change the symbol or text. Returns the instance. See the GIF below.
210
+
211
+ ##### options
212
+
213
+ Type: `object`
214
+
215
+ ###### symbol
216
+
217
+ Type: `string`\
218
+ Default: `' '`
219
+
220
+ Symbol to replace the spinner with.
221
+
222
+ ###### text
223
+
224
+ Type: `string`\
225
+ Default: Current `'text'`
226
+
227
+ Text to be persisted after the symbol.
228
+
229
+ ###### prefixText
230
+
231
+ Type: `string | () => string`\
232
+ Default: Current `prefixText`
233
+
234
+ Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
235
+
236
+ ###### suffixText
237
+
238
+ Type: `string | () => string`\
239
+ Default: Current `suffixText`
240
+
241
+ Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string.
242
+
243
+ <img src="screenshot-2.gif" width="480">
244
+
245
+ #### .clear()
246
+
247
+ Clear the spinner. Returns the instance.
248
+
249
+ #### .render()
250
+
251
+ Manually render a new frame. Returns the instance.
252
+
253
+ #### .frame()
254
+
255
+ Get a new frame.
256
+
257
+ ### oraPromise(action, text)
258
+ ### oraPromise(action, options)
259
+
260
+ Starts a spinner for a promise or promise-returning function. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects. Returns the promise.
261
+
262
+ ```js
263
+ import {oraPromise} from 'ora';
264
+
265
+ await oraPromise(somePromise);
266
+ ```
267
+
268
+ #### action
269
+
270
+ Type: `Promise | ((spinner: ora.Ora) => Promise)`
271
+
272
+ #### options
273
+
274
+ Type: `object`
275
+
276
+ All of the [options](#options) plus the following:
277
+
278
+ ##### successText
279
+
280
+ Type: `string | ((result: T) => string) | undefined`
281
+
282
+ The new text of the spinner when the promise is resolved.
283
+
284
+ Keeps the existing text if `undefined`.
285
+
286
+ ##### failText
287
+
288
+ Type: `string | ((error: Error) => string) | undefined`
289
+
290
+ The new text of the spinner when the promise is rejected.
291
+
292
+ Keeps the existing text if `undefined`.
293
+
294
+ ### spinners
295
+
296
+ Type: `Record<string, Spinner>`
297
+
298
+ All [provided spinners](https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json).
299
+
300
+ ## FAQ
301
+
302
+ ### How do I change the color of the text?
303
+
304
+ Use [`chalk`](https://github.com/chalk/chalk) or [`yoctocolors`](https://github.com/sindresorhus/yoctocolors):
305
+
306
+ ```js
307
+ import ora from 'ora';
308
+ import chalk from 'chalk';
309
+
310
+ const spinner = ora(`Loading ${chalk.red('unicorns')}`).start();
311
+ ```
312
+
313
+ ### Why does the spinner freeze?
314
+
315
+ JavaScript is single-threaded, so any synchronous operations will block the spinner's animation. To avoid this, prefer using asynchronous operations.
316
+
317
+ ### Why do I get the line spinner on Windows Terminal or WSL?
318
+
319
+ Windows Terminal does [not expose](https://github.com/microsoft/terminal/issues/1040) a reliable, stable way to detect itself or Unicode support from Node, and `WT_SESSION` is explicitly informative, not a detection API and can be inherited by other terminals. That makes environment-based detection best-effort. If you are in a Unicode-capable terminal, set `spinner` explicitly, for example `ora({spinner: 'dots'})`.
320
+
321
+ ### Can I log messages while the spinner is running?
322
+
323
+ Yes! Ora automatically handles writes to the same stream. The spinner will temporarily clear itself, output your message, and re-render below:
324
+
325
+ ```js
326
+ const spinner = ora('Processing...').start();
327
+
328
+ console.log('Step 1 complete');
329
+ console.log('Step 2 complete');
330
+
331
+ spinner.succeed('Done!');
332
+ ```
333
+
334
+ The output will be clean with each log appearing above the spinner. This works seamlessly without requiring any special logging methods. Both `console.log()` (stdout) and `console.error()`/`console.warn()` (stderr) are supported.
335
+
336
+ > [!NOTE]
337
+ > Don't run multiple spinners concurrently. Use one spinner at a time.
338
+
339
+ ### Can I display multiple spinners simultaneously?
340
+
341
+ No. Ora is designed to display a single spinner at a time. For multiple concurrent progress indicators, consider alternatives like [listr2](https://github.com/listr2/listr2) or [spinnies](https://github.com/jcarpanelli/spinnies).
342
+
343
+ ### Can I use Ora with [log-update](https://github.com/sindresorhus/log-update)?
344
+
345
+ Yes, use the `.frame()` method to get the current spinner frame and include it in your log-update output.
346
+
347
+ ### Does Ora work in Node.js Worker threads?
348
+
349
+ No. Ora requires an interactive terminal environment and Worker threads are not considered interactive, so the spinner will not animate. Run the spinner in the main thread and control it via worker messages:
350
+
351
+ ```js
352
+ // main.js
353
+ import {Worker} from 'node:worker_threads';
354
+ import ora from 'ora';
355
+
356
+ const spinner = ora().start();
357
+ const worker = new Worker('./worker.js');
358
+
359
+ worker.on('message', message => {
360
+ switch (message.type) {
361
+ case 'ora:text':
362
+ spinner.text = message.text;
363
+ break;
364
+ case 'ora:succeed':
365
+ spinner.succeed(message.text);
366
+ break;
367
+ case 'ora:fail':
368
+ spinner.fail(message.text);
369
+ break;
370
+ }
371
+ });
372
+ ```
373
+
374
+ ```js
375
+ // worker.js
376
+ import {parentPort} from 'node:worker_threads';
377
+
378
+ parentPort.postMessage({type: 'ora:text', text: 'Working...'});
379
+
380
+ // Do work...
381
+
382
+ parentPort.postMessage({type: 'ora:succeed', text: 'Done!'});
383
+ ```
384
+
385
+ ## Related
386
+
387
+ - [yocto-spinner](https://github.com/sindresorhus/yocto-spinner) - Tiny terminal spinner
388
+ - [cli-spinners](https://github.com/sindresorhus/cli-spinners) - Spinners for use in the terminal
389
+
390
+ **Ports**
391
+
392
+ - [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinner library for Swift
393
+ - [halo](https://github.com/ManrajGrover/halo) - Python port
394
+ - [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust
395
+ - [marquee-ora](https://github.com/joeycozza/marquee-ora) - Scrolling marquee spinner for Ora
396
+ - [briandowns/spinner](https://github.com/briandowns/spinner) - Terminal spinner/progress indicator for Go
397
+ - [tj/go-spin](https://github.com/tj/go-spin) - Terminal spinner package for Go
398
+ - [observablehq.com/@victordidenko/ora](https://observablehq.com/@victordidenko/ora) - Ora port to Observable notebooks
399
+ - [kia](https://github.com/HarryPeach/kia) - Simple terminal spinners for Deno 🦕