| 24 | * @returns |
| 25 | */ |
| 26 | export function createSpinner(enableOutput = true, oraOptions: Partial<OraOptions> = {}) { |
| 27 | const actualOptions = { ...defaultOraOptions, ...oraOptions } |
| 28 | |
| 29 | return (text: string): SpinnerStarted => { |
| 30 | if (!enableOutput) { |
| 31 | return { |
| 32 | success: () => {}, |
| 33 | failure: () => {}, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | actualOptions.stream?.write('\n') |
| 38 | const spinner = ora(actualOptions) |
| 39 | spinner.start(text) |
| 40 | |
| 41 | return { |
| 42 | /** |
| 43 | * Stop the spinner, change it to a green ✔ and persist the current text, or text if provided. |
| 44 | * @param textSuccess Will persist text if provided. |
| 45 | */ |
| 46 | success: (textSuccess) => { |
| 47 | spinner.succeed(textSuccess) |
| 48 | }, |
| 49 | |
| 50 | /** |
| 51 | * Stop the spinner, change it to a red ✖ and persist the current text, or text if provided. |
| 52 | * @param textFailure Will persist text if provided. |
| 53 | */ |
| 54 | failure: (textFailure) => { |
| 55 | spinner.fail(textFailure) |
| 56 | }, |
| 57 | } |
| 58 | } |
| 59 | } |