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 |
|
26 |
|
27 | readonly text?: string;
|
28 |
|
29 | |
30 |
|
31 |
|
32 | readonly prefixText?: string | PrefixTextGenerator;
|
33 |
|
34 | |
35 |
|
36 |
|
37 | readonly suffixText?: string | SuffixTextGenerator;
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | readonly spinner?: SpinnerName | Spinner;
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | readonly color?: Color;
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 | readonly hideCursor?: boolean;
|
69 |
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | readonly indent?: number;
|
76 |
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | readonly interval?: number;
|
85 |
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | readonly stream?: NodeJS.WritableStream;
|
94 |
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 | readonly isEnabled?: boolean;
|
101 |
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 | readonly isSilent?: boolean;
|
108 |
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | readonly discardStdin?: boolean;
|
117 | };
|
118 |
|
119 | export type PersistOptions = {
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 | readonly symbol?: string;
|
126 |
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 | readonly text?: string;
|
133 |
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 | readonly prefixText?: string | PrefixTextGenerator;
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 | readonly suffixText?: string | SuffixTextGenerator;
|
147 | };
|
148 |
|
149 | export type PromiseOptions<T> = {
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 | successText?: string | ((result: T) => string) | undefined;
|
156 |
|
157 | /**
|
158 | The new text of the spinner when the promise is rejected.
|
159 |
|
160 | Keeps the existing text if `undefined`.
|
161 | */
|
162 | failText?: string | ((error: Error) => string) | undefined;
|
163 | } & Options;
|
164 |
|
165 | // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
166 | export interface Ora {
|
167 | /**
|
168 | Change the text after the spinner.
|
169 | */
|
170 | text: string;
|
171 |
|
172 | /**
|
173 | Change the text or function that returns text before the spinner.
|
174 |
|
175 | No prefix text will be displayed if set to an empty string.
|
176 | */
|
177 | prefixText: string;
|
178 |
|
179 | /**
|
180 | Change the text or function that returns text after the spinner text.
|
181 |
|
182 | No suffix text will be displayed if set to an empty string.
|
183 | */
|
184 | suffixText: string;
|
185 |
|
186 | /**
|
187 | Change the spinner color.
|
188 | */
|
189 | color: Color;
|
190 |
|
191 | /**
|
192 | Change the spinner indent.
|
193 | */
|
194 | indent: number;
|
195 |
|
196 | /**
|
197 | Get the spinner.
|
198 | */
|
199 | get spinner(): Spinner;
|
200 |
|
201 | /**
|
202 | Set the spinner.
|
203 | */
|
204 | set spinner(spinner: SpinnerName | Spinner);
|
205 |
|
206 | /**
|
207 | A boolean indicating whether the instance is currently spinning.
|
208 | */
|
209 | get isSpinning(): boolean;
|
210 |
|
211 | /**
|
212 | The interval between each frame.
|
213 |
|
214 | The interval is decided by the chosen spinner.
|
215 | */
|
216 | get interval(): number;
|
217 |
|
218 | /**
|
219 | Start the spinner.
|
220 |
|
221 | @param text - Set the current text.
|
222 | @returns The spinner instance.
|
223 | */
|
224 | start(text?: string): this;
|
225 |
|
226 | /**
|
227 | Stop and clear the spinner.
|
228 |
|
229 | @returns The spinner instance.
|
230 | */
|
231 | stop(): this;
|
232 |
|
233 | /**
|
234 | Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
|
235 |
|
236 | @param text - Will persist text if provided.
|
237 | @returns The spinner instance.
|
238 | */
|
239 | succeed(text?: string): this;
|
240 |
|
241 | /**
|
242 | Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
|
243 |
|
244 | @param text - Will persist text if provided.
|
245 | @returns The spinner instance.
|
246 | */
|
247 | fail(text?: string): this;
|
248 |
|
249 | /**
|
250 | Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
|
251 |
|
252 | @param text - Will persist text if provided.
|
253 | @returns The spinner instance.
|
254 | */
|
255 | warn(text?: string): this;
|
256 |
|
257 | /**
|
258 | Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
|
259 |
|
260 | @param text - Will persist text if provided.
|
261 | @returns The spinner instance.
|
262 | */
|
263 | info(text?: string): this;
|
264 |
|
265 | /**
|
266 | Stop the spinner and change the symbol or text.
|
267 |
|
268 | @returns The spinner instance.
|
269 | */
|
270 | stopAndPersist(options?: PersistOptions): this;
|
271 |
|
272 | /**
|
273 | Clear the spinner.
|
274 |
|
275 | @returns The spinner instance.
|
276 | */
|
277 | clear(): this;
|
278 |
|
279 | /**
|
280 | Manually render a new frame.
|
281 |
|
282 | @returns The spinner instance.
|
283 | */
|
284 | render(): this;
|
285 |
|
286 | /**
|
287 | Get a new frame.
|
288 |
|
289 | @returns The spinner instance text.
|
290 | */
|
291 | frame(): string;
|
292 | }
|
293 |
|
294 | /**
|
295 | Elegant terminal spinner.
|
296 |
|
297 | @param options - If a string is provided, it is treated as a shortcut for `options.text`.
|
298 |
|
299 | @example
|
300 | ```
|
301 | import ora from 'ora';
|
302 |
|
303 | const spinner = ora('Loading unicorns').start();
|
304 |
|
305 | setTimeout(() => {
|
306 | spinner.color = 'yellow';
|
307 | spinner.text = 'Loading rainbows';
|
308 | }, 1000);
|
309 | ```
|
310 | */
|
311 | export default function ora(options?: string | Options): Ora;
|
312 |
|
313 | /**
|
314 | 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.
|
315 |
|
316 | @param action - The promise to start the spinner for or a promise-returning function.
|
317 | @param options - If a string is provided, it is treated as a shortcut for `options.text`.
|
318 | @returns The given promise.
|
319 |
|
320 | @example
|
321 | ```
|
322 | import {oraPromise} from 'ora';
|
323 |
|
324 | await oraPromise(somePromise);
|
325 | ```
|
326 | */
|
327 | export function oraPromise<T>(
|
328 | action: PromiseLike<T> | ((spinner: Ora) => PromiseLike<T>),
|
329 | options?: string | PromiseOptions<T>
|
330 | ): Promise<T>;
|
331 |
|
332 | export {default as spinners} from 'cli-spinners';
|
333 |
|
\ | No newline at end of file |