* Animates asynchronous work using a spinner. * * Basic logs are supported within the worker function, they will be printed with indentation once the spinner completes. * * In CI environments, the spinner animation is disabled, and inner logs are printed immediately. * * Spinners m
(
title: string,
worker: () => Promise<string | { message: string; result: T }>,
)
| 203 | * @param worker Asynchronous implementation. Returned promise determines spinner status and final message. Support for inner logs has some limitations (described above). |
| 204 | */ |
| 205 | async task<T = undefined>( |
| 206 | title: string, |
| 207 | worker: () => Promise<string | { message: string; result: T }>, |
| 208 | ): Promise<T> { |
| 209 | const result = await this.#spinner(worker, { |
| 210 | pending: title, |
| 211 | success: value => (typeof value === 'string' ? value : value.message), |
| 212 | failure: error => `${title} → ${ansis.red(String(error))}`, |
| 213 | }); |
| 214 | return typeof result === 'object' ? result.result : (undefined as T); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Similar to {@link task}, but spinner texts are formatted as shell commands. |
no test coverage detected