index.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.
  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. Default value: Provided by the spinner or `100`.
  58. */
  59. readonly interval?: number;
  60. /**
  61. Stream to write the output.
  62. You could for example set this to `process.stdout` instead.
  63. @default process.stderr
  64. */
  65. readonly stream?: NodeJS.WritableStream;
  66. /**
  67. 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.
  68. 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.
  69. */
  70. readonly isEnabled?: boolean;
  71. }
  72. interface PersistOptions {
  73. /**
  74. Symbol to replace the spinner with.
  75. @default ' '
  76. */
  77. readonly symbol?: string;
  78. /**
  79. Text to be persisted after the symbol. Default: Current `text`.
  80. */
  81. readonly text?: string;
  82. /**
  83. Text to be persisted before the symbol. Default: Current `prefixText`.
  84. */
  85. readonly prefixText?: string;
  86. }
  87. interface Ora {
  88. /**
  89. A boolean of whether the instance is currently spinning.
  90. */
  91. readonly isSpinning: boolean;
  92. /**
  93. Change the text after the spinner.
  94. */
  95. text: string;
  96. /**
  97. Change the text before the spinner.
  98. */
  99. prefixText: string;
  100. /**
  101. Change the spinner color.
  102. */
  103. color: Color;
  104. /**
  105. Change the spinner.
  106. */
  107. spinner: SpinnerName | Spinner;
  108. /**
  109. Change the spinner indent.
  110. */
  111. indent: number;
  112. /**
  113. Start the spinner.
  114. @param text - Set the current text.
  115. @returns The spinner instance.
  116. */
  117. start(text?: string): Ora;
  118. /**
  119. Stop and clear the spinner.
  120. @returns The spinner instance.
  121. */
  122. stop(): Ora;
  123. /**
  124. Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
  125. @param text - Will persist text if provided.
  126. @returns The spinner instance.
  127. */
  128. succeed(text?: string): Ora;
  129. /**
  130. Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
  131. @param text - Will persist text if provided.
  132. @returns The spinner instance.
  133. */
  134. fail(text?: string): Ora;
  135. /**
  136. Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
  137. @param text - Will persist text if provided.
  138. @returns The spinner instance.
  139. */
  140. warn(text?: string): Ora;
  141. /**
  142. Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
  143. @param text - Will persist text if provided.
  144. @returns The spinner instance.
  145. */
  146. info(text?: string): Ora;
  147. /**
  148. Stop the spinner and change the symbol or text.
  149. @returns The spinner instance.
  150. */
  151. stopAndPersist(options?: PersistOptions): Ora;
  152. /**
  153. Clear the spinner.
  154. @returns The spinner instance.
  155. */
  156. clear(): Ora;
  157. /**
  158. Manually render a new frame.
  159. @returns The spinner instance.
  160. */
  161. render(): Ora;
  162. /**
  163. Get a new frame.
  164. @returns The spinner instance.
  165. */
  166. frame(): Ora;
  167. }
  168. }
  169. declare const ora: {
  170. /**
  171. Elegant terminal spinner.
  172. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  173. @example
  174. ```
  175. import ora = require('ora');
  176. const spinner = ora('Loading unicorns').start();
  177. setTimeout(() => {
  178. spinner.color = 'yellow';
  179. spinner.text = 'Loading rainbows';
  180. }, 1000);
  181. ```
  182. */
  183. (options?: ora.Options | string): ora.Ora;
  184. /**
  185. Starts a spinner for a promise. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
  186. @param action - The promise to start the spinner for.
  187. @param options - If a string is provided, it is treated as a shortcut for `options.text`.
  188. @returns The spinner instance.
  189. */
  190. promise(
  191. action: PromiseLike<unknown>,
  192. options?: ora.Options | string
  193. ): ora.Ora;
  194. // TODO: Remove this for the next major release
  195. default: typeof ora;
  196. };
  197. export = ora;