index.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /// <reference types="node"/>
  2. import {SpinnerName} from 'cli-spinners';
  3. declare namespace ora {
  4. interface Spinner {
  5. readonly interval?: number;
  6. readonly frames: string[];
  7. }
  8. type Color =
  9. | 'black'
  10. | 'red'
  11. | 'green'
  12. | 'yellow'
  13. | 'blue'
  14. | 'magenta'
  15. | 'cyan'
  16. | 'white'
  17. | 'gray';
  18. interface Options {
  19. /**
  20. Text to display after the spinner.
  21. */
  22. readonly text?: string;
  23. /**
  24. Text to display before the spinner. No prefix text will be displayed if set to an empty string.
  25. */
  26. readonly prefixText?: string;
  27. /**
  28. Name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/master/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. 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.
  74. @default true
  75. */
  76. readonly discardStdin?: boolean;
  77. }
  78. interface PersistOptions {
  79. /**
  80. Symbol to replace the spinner with.
  81. @default ' '
  82. */
  83. readonly symbol?: string;
  84. /**
  85. Text to be persisted after the symbol.
  86. Default: Current `text`.
  87. */
  88. readonly text?: string;
  89. /**
  90. Text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
  91. Default: Current `prefixText`.
  92. */
  93. readonly prefixText?: string;
  94. }
  95. interface Ora {
  96. /**
  97. A boolean of whether the instance is currently spinning.
  98. */
  99. readonly isSpinning: boolean;
  100. /**
  101. Change the text after the spinner.
  102. */
  103. text: string;
  104. /**
  105. Change the text before the spinner. No prefix text will be displayed if set to an empty string.
  106. */
  107. prefixText: string;
  108. /**
  109. Change the spinner color.
  110. */
  111. color: Color;
  112. /**
  113. Change the spinner.
  114. */
  115. spinner: SpinnerName | Spinner;
  116. /**
  117. Change the spinner indent.
  118. */
  119. indent: number;
  120. /**
  121. Start the spinner.
  122. @param text - Set the current text.
  123. @returns The spinner instance.
  124. */
  125. start(text?: string): Ora;
  126. /**
  127. Stop and clear the spinner.
  128. @returns The spinner instance.
  129. */
  130. stop(): Ora;
  131. /**
  132. Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
  133. @param text - Will persist text if provided.
  134. @returns The spinner instance.
  135. */
  136. succeed(text?: string): Ora;
  137. /**
  138. Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
  139. @param text - Will persist text if provided.
  140. @returns The spinner instance.
  141. */
  142. fail(text?: string): Ora;
  143. /**
  144. Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
  145. @param text - Will persist text if provided.
  146. @returns The spinner instance.
  147. */
  148. warn(text?: string): Ora;
  149. /**
  150. Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
  151. @param text - Will persist text if provided.
  152. @returns The spinner instance.
  153. */
  154. info(text?: string): Ora;
  155. /**
  156. Stop the spinner and change the symbol or text.
  157. @returns The spinner instance.
  158. */
  159. stopAndPersist(options?: PersistOptions): Ora;
  160. /**
  161. Clear the spinner.
  162. @returns The spinner instance.
  163. */
  164. clear(): Ora;
  165. /**
  166. Manually render a new frame.
  167. @returns The spinner instance.
  168. */
  169. render(): Ora;
  170. /**
  171. Get a new frame.
  172. @returns The spinner instance text.
  173. */
  174. frame(): string;
  175. }
  176. }
  177. declare const ora: {
  178. /**
  179. Elegant terminal spinner.
  180. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  181. @example
  182. ```
  183. import ora = require('ora');
  184. const spinner = ora('Loading unicorns').start();
  185. setTimeout(() => {
  186. spinner.color = 'yellow';
  187. spinner.text = 'Loading rainbows';
  188. }, 1000);
  189. ```
  190. */
  191. (options?: ora.Options | string): ora.Ora;
  192. /**
  193. Starts a spinner for a promise. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
  194. @param action - The promise to start the spinner for.
  195. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  196. @returns The spinner instance.
  197. */
  198. promise(
  199. action: PromiseLike<unknown>,
  200. options?: ora.Options | string
  201. ): ora.Ora;
  202. };
  203. export = ora;