source: trip-planner-front/node_modules/ora/readme.md@ 1ad8e64

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

initial commit

  • Property mode set to 100644
File size: 6.3 KB
Line 
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```
14$ npm install ora
15```
16
17## Usage
18
19```js
20const ora = require('ora');
21
22const spinner = ora('Loading unicorns').start();
23
24setTimeout(() => {
25 spinner.color = 'yellow';
26 spinner.text = 'Loading rainbows';
27}, 1000);
28```
29
30## API
31
32### ora(text)
33### ora(options)
34
35If a string is provided, it is treated as a shortcut for [`options.text`](#text).
36
37#### options
38
39Type: `object`
40
41##### text
42
43Type: `string`
44
45Text to display after the spinner.
46
47##### prefixText
48
49Type: `string | () => string`
50
51Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
52
53##### spinner
54
55Type: `string | object`\
56Default: `'dots'` <img src="screenshot-spinner.gif" width="14">
57
58Name of one of the [provided spinners](https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json). See `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.
59
60Or an object like:
61
62```js
63{
64 interval: 80, // Optional
65 frames: ['-', '+', '-']
66}
67```
68
69##### color
70
71Type: `string`\
72Default: `'cyan'`\
73Values: `'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray'`
74
75Color of the spinner.
76
77##### hideCursor
78
79Type: `boolean`\
80Default: `true`
81
82Set to `false` to stop Ora from hiding the cursor.
83
84##### indent
85
86Type: `number`\
87Default: `0`
88
89Indent the spinner with the given number of spaces.
90
91##### interval
92
93Type: `number`\
94Default: Provided by the spinner or `100`
95
96Interval between each frame.
97
98Spinners provide their own recommended interval, so you don't really need to specify this.
99
100##### stream
101
102Type: `stream.Writable`\
103Default: `process.stderr`
104
105Stream to write the output.
106
107You could for example set this to `process.stdout` instead.
108
109##### isEnabled
110
111Type: `boolean`
112
113Force 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.
114
115Note 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.
116
117##### isSilent
118
119Type: `boolean`\
120Default: `false`
121
122Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
123
124##### discardStdin
125
126Type: `boolean`\
127Default: `true`
128
129Discard 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.
130
131This has no effect on Windows as there's no good way to implement discarding stdin properly there.
132
133### Instance
134
135#### .start(text?)
136
137Start the spinner. Returns the instance. Set the current text if `text` is provided.
138
139#### .stop()
140
141Stop and clear the spinner. Returns the instance.
142
143#### .succeed(text?)
144
145Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
146
147#### .fail(text?)
148
149Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
150
151#### .warn(text?)
152
153Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided. Returns the instance.
154
155#### .info(text?)
156
157Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided. Returns the instance.
158
159#### .isSpinning
160
161A boolean of whether the instance is currently spinning.
162
163#### .stopAndPersist(options?)
164
165Stop the spinner and change the symbol or text. Returns the instance. See the GIF below.
166
167##### options
168
169Type: `object`
170
171###### symbol
172
173Type: `string`\
174Default: `' '`
175
176Symbol to replace the spinner with.
177
178###### text
179
180Type: `string`\
181Default: Current `'text'`
182
183Text to be persisted after the symbol
184
185###### prefixText
186
187Type: `string`\
188Default: Current `prefixText`
189
190Text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
191
192<img src="screenshot-2.gif" width="480">
193
194#### .clear()
195
196Clear the spinner. Returns the instance.
197
198#### .render()
199
200Manually render a new frame. Returns the instance.
201
202#### .frame()
203
204Get a new frame.
205
206#### .text
207
208Change the text after the spinner.
209
210#### .prefixText
211
212Change the text before the spinner. No prefix text will be displayed if set to an empty string.
213
214#### .color
215
216Change the spinner color.
217
218#### .spinner
219
220Change the spinner.
221
222#### .indent
223
224Change the spinner indent.
225
226### ora.promise(action, text)
227### ora.promise(action, options)
228
229Starts a spinner for a promise. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects. Returns the spinner instance.
230
231#### action
232
233Type: `Promise`
234
235## FAQ
236
237### How do I change the color of the text?
238
239Use [Chalk](https://github.com/chalk/chalk):
240
241```js
242const ora = require('ora');
243const chalk = require('chalk');
244
245const spinner = ora(`Loading ${chalk.red('unicorns')}`).start();
246```
247
248### Why does the spinner freeze?
249
250JavaScript is single-threaded, so synchronous operations blocks the thread, including the spinner animation. Prefer asynchronous operations whenever possible.
251
252## Related
253
254- [cli-spinners](https://github.com/sindresorhus/cli-spinners) - Spinners for use in the terminal
255- [listr](https://github.com/SamVerschueren/listr) - Terminal task list
256- [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinner library for Swift
257- [halo](https://github.com/ManrajGrover/halo) - Python port
258- [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust
259- [marquee-ora](https://github.com/joeycozza/marquee-ora) - Scrolling marquee spinner for Ora
260- [briandowns/spinner](https://github.com/briandowns/spinner) - Terminal spinner/progress indicator for Go
261- [tj/go-spin](https://github.com/tj/go-spin) - Terminal spinner package for Go
262- [observablehq.com/@victordidenko/ora](https://observablehq.com/@victordidenko/ora) - Ora port to Observable notebooks
263- [spinnies](https://github.com/jcarpanelli/spinnies) - Terminal multi-spinner library for Node.js
264- [kia](https://github.com/HarryPeach/kia) - Simple terminal spinners for Deno 🦕
Note: See TracBrowser for help on using the repository browser.