source: trip-planner-front/node_modules/ora/index.d.ts@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.0 KB
Line 
1import {SpinnerName} from 'cli-spinners';
2
3declare namespace ora {
4 interface Spinner {
5 readonly interval?: number;
6 readonly frames: string[];
7 }
8
9 type Color =
10 | 'black'
11 | 'red'
12 | 'green'
13 | 'yellow'
14 | 'blue'
15 | 'magenta'
16 | 'cyan'
17 | 'white'
18 | 'gray';
19
20 type PrefixTextGenerator = () => string;
21
22 interface Options {
23 /**
24 Text to display after the spinner.
25 */
26 readonly text?: string;
27
28 /**
29 Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
30 */
31 readonly prefixText?: string | PrefixTextGenerator;
32
33 /**
34 Name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/main/example.js) in this repo if you want to test out different spinners. On Windows, it will always use the line spinner as the Windows command-line doesn't have proper Unicode support.
35
36 @default 'dots'
37
38 Or an object like:
39
40 @example
41 ```
42 {
43 interval: 80, // Optional
44 frames: ['-', '+', '-']
45 }
46 ```
47 */
48 readonly spinner?: SpinnerName | Spinner;
49
50 /**
51 Color of the spinner.
52
53 @default 'cyan'
54 */
55 readonly color?: Color;
56
57 /**
58 Set to `false` to stop Ora from hiding the cursor.
59
60 @default true
61 */
62 readonly hideCursor?: boolean;
63
64 /**
65 Indent the spinner with the given number of spaces.
66
67 @default 0
68 */
69 readonly indent?: number;
70
71 /**
72 Interval between each frame.
73
74 Spinners provide their own recommended interval, so you don't really need to specify this.
75
76 Default: Provided by the spinner or `100`.
77 */
78 readonly interval?: number;
79
80 /**
81 Stream to write the output.
82
83 You could for example set this to `process.stdout` instead.
84
85 @default process.stderr
86 */
87 readonly stream?: NodeJS.WritableStream;
88
89 /**
90 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.
91
92 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.
93 */
94 readonly isEnabled?: boolean;
95
96 /**
97 Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
98
99 @default false
100 */
101 readonly isSilent?: boolean;
102
103 /**
104 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.
105
106 This has no effect on Windows as there's no good way to implement discarding stdin properly there.
107
108 @default true
109 */
110 readonly discardStdin?: boolean;
111 }
112
113 interface PersistOptions {
114 /**
115 Symbol to replace the spinner with.
116
117 @default ' '
118 */
119 readonly symbol?: string;
120
121 /**
122 Text to be persisted after the symbol.
123
124 Default: Current `text`.
125 */
126 readonly text?: string;
127
128 /**
129 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.
130
131 Default: Current `prefixText`.
132 */
133 readonly prefixText?: string | PrefixTextGenerator;
134 }
135
136 interface Ora {
137 /**
138 A boolean of whether the instance is currently spinning.
139 */
140 readonly isSpinning: boolean;
141
142 /**
143 Change the text after the spinner.
144 */
145 text: string;
146
147 /**
148 Change the text or function that returns text before the spinner. No prefix text will be displayed if set to an empty string.
149 */
150 prefixText: string | PrefixTextGenerator;
151
152 /**
153 Change the spinner color.
154 */
155 color: Color;
156
157 /**
158 Change the spinner.
159 */
160 spinner: SpinnerName | Spinner;
161
162 /**
163 Change the spinner indent.
164 */
165 indent: number;
166
167 /**
168 Start the spinner.
169
170 @param text - Set the current text.
171 @returns The spinner instance.
172 */
173 start(text?: string): Ora;
174
175 /**
176 Stop and clear the spinner.
177
178 @returns The spinner instance.
179 */
180 stop(): Ora;
181
182 /**
183 Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
184
185 @param text - Will persist text if provided.
186 @returns The spinner instance.
187 */
188 succeed(text?: string): Ora;
189
190 /**
191 Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
192
193 @param text - Will persist text if provided.
194 @returns The spinner instance.
195 */
196 fail(text?: string): Ora;
197
198 /**
199 Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
200
201 @param text - Will persist text if provided.
202 @returns The spinner instance.
203 */
204 warn(text?: string): Ora;
205
206 /**
207 Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
208
209 @param text - Will persist text if provided.
210 @returns The spinner instance.
211 */
212 info(text?: string): Ora;
213
214 /**
215 Stop the spinner and change the symbol or text.
216
217 @returns The spinner instance.
218 */
219 stopAndPersist(options?: PersistOptions): Ora;
220
221 /**
222 Clear the spinner.
223
224 @returns The spinner instance.
225 */
226 clear(): Ora;
227
228 /**
229 Manually render a new frame.
230
231 @returns The spinner instance.
232 */
233 render(): Ora;
234
235 /**
236 Get a new frame.
237
238 @returns The spinner instance text.
239 */
240 frame(): string;
241 }
242}
243
244declare const ora: {
245 /**
246 Elegant terminal spinner.
247
248 @param options - If a string is provided, it is treated as a shortcut for `options.text`.
249
250 @example
251 ```
252 import ora = require('ora');
253
254 const spinner = ora('Loading unicorns').start();
255
256 setTimeout(() => {
257 spinner.color = 'yellow';
258 spinner.text = 'Loading rainbows';
259 }, 1000);
260 ```
261 */
262 (options?: ora.Options | string): ora.Ora;
263
264 /**
265 Starts a spinner for a promise. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
266
267 @param action - The promise to start the spinner for.
268 @param options - If a string is provided, it is treated as a shortcut for `options.text`.
269 @returns The spinner instance.
270 */
271 promise(
272 action: PromiseLike<unknown>,
273 options?: ora.Options | string
274 ): ora.Ora;
275};
276
277export = ora;
Note: See TracBrowser for help on using the repository browser.