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