You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import {SpinnerName} from 'cli-spinners';
  2. declare namespace ora {
  3. interface Spinner {
  4. readonly interval?: number;
  5. readonly frames: string[];
  6. }
  7. type Color =
  8. | 'black'
  9. | 'red'
  10. | 'green'
  11. | 'yellow'
  12. | 'blue'
  13. | 'magenta'
  14. | 'cyan'
  15. | 'white'
  16. | 'gray';
  17. type PrefixTextGenerator = () => string;
  18. interface Options {
  19. /**
  20. Text to display after the spinner.
  21. */
  22. readonly text?: string;
  23. /**
  24. Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
  25. */
  26. readonly prefixText?: string | PrefixTextGenerator;
  27. /**
  28. 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.
  29. @default 'dots'
  30. Or an object like:
  31. @example
  32. ```
  33. {
  34. interval: 80, // Optional
  35. frames: ['-', '+', '-']
  36. }
  37. ```
  38. */
  39. readonly spinner?: SpinnerName | Spinner;
  40. /**
  41. Color of the spinner.
  42. @default 'cyan'
  43. */
  44. readonly color?: Color;
  45. /**
  46. Set to `false` to stop Ora from hiding the cursor.
  47. @default true
  48. */
  49. readonly hideCursor?: boolean;
  50. /**
  51. Indent the spinner with the given number of spaces.
  52. @default 0
  53. */
  54. readonly indent?: number;
  55. /**
  56. Interval between each frame.
  57. Spinners provide their own recommended interval, so you don't really need to specify this.
  58. Default: Provided by the spinner or `100`.
  59. */
  60. readonly interval?: number;
  61. /**
  62. Stream to write the output.
  63. You could for example set this to `process.stdout` instead.
  64. @default process.stderr
  65. */
  66. readonly stream?: NodeJS.WritableStream;
  67. /**
  68. 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.
  69. 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.
  70. */
  71. readonly isEnabled?: boolean;
  72. /**
  73. Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
  74. @default false
  75. */
  76. readonly isSilent?: boolean;
  77. /**
  78. 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.
  79. This has no effect on Windows as there's no good way to implement discarding stdin properly there.
  80. @default true
  81. */
  82. readonly discardStdin?: boolean;
  83. }
  84. interface PersistOptions {
  85. /**
  86. Symbol to replace the spinner with.
  87. @default ' '
  88. */
  89. readonly symbol?: string;
  90. /**
  91. Text to be persisted after the symbol.
  92. Default: Current `text`.
  93. */
  94. readonly text?: string;
  95. /**
  96. 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.
  97. Default: Current `prefixText`.
  98. */
  99. readonly prefixText?: string | PrefixTextGenerator;
  100. }
  101. interface Ora {
  102. /**
  103. A boolean of whether the instance is currently spinning.
  104. */
  105. readonly isSpinning: boolean;
  106. /**
  107. Change the text after the spinner.
  108. */
  109. text: string;
  110. /**
  111. Change the text or function that returns text before the spinner. No prefix text will be displayed if set to an empty string.
  112. */
  113. prefixText: string | PrefixTextGenerator;
  114. /**
  115. Change the spinner color.
  116. */
  117. color: Color;
  118. /**
  119. Change the spinner.
  120. */
  121. spinner: SpinnerName | Spinner;
  122. /**
  123. Change the spinner indent.
  124. */
  125. indent: number;
  126. /**
  127. Start the spinner.
  128. @param text - Set the current text.
  129. @returns The spinner instance.
  130. */
  131. start(text?: string): Ora;
  132. /**
  133. Stop and clear the spinner.
  134. @returns The spinner instance.
  135. */
  136. stop(): Ora;
  137. /**
  138. Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
  139. @param text - Will persist text if provided.
  140. @returns The spinner instance.
  141. */
  142. succeed(text?: string): Ora;
  143. /**
  144. Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
  145. @param text - Will persist text if provided.
  146. @returns The spinner instance.
  147. */
  148. fail(text?: string): Ora;
  149. /**
  150. Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
  151. @param text - Will persist text if provided.
  152. @returns The spinner instance.
  153. */
  154. warn(text?: string): Ora;
  155. /**
  156. Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
  157. @param text - Will persist text if provided.
  158. @returns The spinner instance.
  159. */
  160. info(text?: string): Ora;
  161. /**
  162. Stop the spinner and change the symbol or text.
  163. @returns The spinner instance.
  164. */
  165. stopAndPersist(options?: PersistOptions): Ora;
  166. /**
  167. Clear the spinner.
  168. @returns The spinner instance.
  169. */
  170. clear(): Ora;
  171. /**
  172. Manually render a new frame.
  173. @returns The spinner instance.
  174. */
  175. render(): Ora;
  176. /**
  177. Get a new frame.
  178. @returns The spinner instance text.
  179. */
  180. frame(): string;
  181. }
  182. }
  183. declare const ora: {
  184. /**
  185. Elegant terminal spinner.
  186. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  187. @example
  188. ```
  189. import ora = require('ora');
  190. const spinner = ora('Loading unicorns').start();
  191. setTimeout(() => {
  192. spinner.color = 'yellow';
  193. spinner.text = 'Loading rainbows';
  194. }, 1000);
  195. ```
  196. */
  197. (options?: ora.Options | string): ora.Ora;
  198. /**
  199. Starts a spinner for a promise. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
  200. @param action - The promise to start the spinner for.
  201. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  202. @returns The spinner instance.
  203. */
  204. promise(
  205. action: PromiseLike<unknown>,
  206. options?: ora.Options | string
  207. ): ora.Ora;
  208. };
  209. export = ora;