6e108538b2e387a355026907f6895d51b124c193d9427e41b08c0e347c27b6c1f467b31d662d82c26274b80e75875078591253b2400764a7361d4174049bb1 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # ora [![Build Status](https://travis-ci.org/sindresorhus/ora.svg?branch=master)](https://travis-ci.org/sindresorhus/ora)
  2. > Elegant terminal spinner
  3. <p align="center">
  4. <br>
  5. <img src="screenshot.svg" width="500">
  6. <br>
  7. </p>
  8. ## Install
  9. ```
  10. $ npm install ora
  11. ```
  12. <a href="https://www.patreon.com/sindresorhus">
  13. <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
  14. </a>
  15. ## Usage
  16. ```js
  17. const ora = require('ora');
  18. const spinner = ora('Loading unicorns').start();
  19. setTimeout(() => {
  20. spinner.color = 'yellow';
  21. spinner.text = 'Loading rainbows';
  22. }, 1000);
  23. ```
  24. ## API
  25. ### ora([options|text])
  26. If a string is provided, it is treated as a shortcut for [`options.text`](#text).
  27. #### options
  28. Type: `Object`
  29. ##### text
  30. Type: `string`
  31. Text to display after the spinner.
  32. ##### prefixText
  33. Type: `string`
  34. Text to display before the spinner.
  35. ##### spinner
  36. Type: `string` `Object`<br>
  37. Default: `dots` <img src="screenshot-spinner.gif" width="14">
  38. Name of one of the [provided spinners](https://github.com/sindresorhus/cli-spinners/blob/master/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.
  39. Or an object like:
  40. ```js
  41. {
  42. interval: 80, // Optional
  43. frames: ['-', '+', '-']
  44. }
  45. ```
  46. ##### color
  47. Type: `string`<br>
  48. Default: `cyan`<br>
  49. Values: `black` `red` `green` `yellow` `blue` `magenta` `cyan` `white` `gray`
  50. Color of the spinner.
  51. ##### hideCursor
  52. Type: `boolean`<br>
  53. Default: `true`
  54. Set to `false` to stop Ora from hiding the cursor.
  55. ##### indent
  56. Type: `number`<br>
  57. Default: `0`
  58. Indent the spinner with the given number of spaces.
  59. ##### interval
  60. Type: `number`<br>
  61. Default: Provided by the spinner or `100`
  62. Interval between each frame.
  63. Spinners provide their own recommended interval, so you don't really need to specify this.
  64. ##### stream
  65. Type: `stream.Writable`<br>
  66. Default: `process.stderr`
  67. Stream to write the output.
  68. You could for example set this to `process.stdout` instead.
  69. ##### isEnabled
  70. Type: `boolean`
  71. 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.
  72. 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.
  73. ### Instance
  74. #### .start([text])
  75. Start the spinner. Returns the instance. Set the current text if `text` is provided.
  76. #### .stop()
  77. Stop and clear the spinner. Returns the instance.
  78. #### .succeed([text])
  79. Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
  80. #### .fail([text])
  81. Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
  82. #### .warn([text])
  83. Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided. Returns the instance.
  84. #### .info([text])
  85. Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided. Returns the instance.
  86. #### .isSpinning
  87. A boolean of whether the instance is currently spinning.
  88. #### .stopAndPersist([options])
  89. Stop the spinner and change the symbol or text. Returns the instance. See the GIF below.
  90. ##### options
  91. Type: `Object`
  92. ###### symbol
  93. Type: `string`<br>
  94. Default: `' '`
  95. Symbol to replace the spinner with.
  96. ###### text
  97. Type: `string`<br>
  98. Default: Current `text`
  99. Text to be persisted after the symbol
  100. ###### prefixText
  101. Type: `string`<br>
  102. Default: Current `prefixText`
  103. Text to be persisted before the symbol.
  104. <img src="screenshot-2.gif" width="480">
  105. #### .clear()
  106. Clear the spinner. Returns the instance.
  107. #### .render()
  108. Manually render a new frame. Returns the instance.
  109. #### .frame()
  110. Get a new frame.
  111. #### .text
  112. Change the text after the spinner.
  113. #### .prefixText
  114. Change the text before the spinner.
  115. #### .color
  116. Change the spinner color.
  117. #### .spinner
  118. Change the spinner.
  119. #### .indent
  120. Change the spinner indent.
  121. ### ora.promise(action, [options|text])
  122. Starts 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.
  123. #### action
  124. Type: `Promise`
  125. ## Related
  126. - [cli-spinners](https://github.com/sindresorhus/cli-spinners) - Spinners for use in the terminal
  127. - [listr](https://github.com/SamVerschueren/listr) - Terminal task list
  128. - [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinner library for Swift
  129. - [halo](https://github.com/ManrajGrover/halo) - Python port
  130. - [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust
  131. - [marquee-ora](https://github.com/joeycozza/marquee-ora) - Scrolling marquee spinner for Ora
  132. - [briandowns/spinner](https://github.com/briandowns/spinner) - Terminal spinner/progress indicator for Go
  133. - [tj/go-spin](https://github.com/tj/go-spin) - Terminal spinner package for Go
  134. ## License
  135. MIT © [Sindre Sorhus](https://sindresorhus.com)