/** * @file Lifecycle wrappers around `Spinner` — `withSpinner` (async, push-pop * options + auto-stop), `withSpinnerRestore` (conditionally restart a * previously-spinning instance), and `withSpinnerSync` (sync sibling of * `withSpinner`). Each wrapper guarantees `spinner.stop()` runs via * `try/finally` even when the inner operation throws, then re-throws the * original error so callers see the same failure surface as a plain `await`. */ import type { ColorInherit, ColorValue } from '../term/colors/types.js'; import type { Palette, RGB } from '../term/effects/shimmer.js'; import type { WithSpinnerOptions, WithSpinnerRestoreOptions, WithSpinnerSyncOptions } from './types.js'; /** * Narrow a saved shimmer color (`'inherit' | ColorName | ColorRgb | Palette`) * down to the `RGB | Palette | undefined` shape `ShimmerConfig.color` accepts. * `'inherit'` becomes `undefined` so `setShimmer` falls back to its inherit * default; named colors resolve to an RGB tuple; tuples and palettes pass * through unchanged. */ export declare function toShimmerColor(color: ColorInherit | ColorValue | Palette): RGB | Palette | undefined; /** * Execute an async operation with spinner lifecycle management. * `spinner.stop()` always runs via try/finally, even when the operation * throws, and the error is re-thrown once the spinner has stopped. * * Omitting `spinner` is valid rather than an error: the operation still runs, * just with no spinner output. * * @template T - Return type of the operation. * * @param options.message - Message to display while the spinner runs. * @param options.operation - Async function to execute. * @param options.spinner - Optional; omit it for no spinner. * * @returns Result of the operation. * * @throws Re-throws any error from operation after stopping the spinner. */ export declare function withSpinner(options: WithSpinnerOptions): Promise; /** * Execute an async operation with conditional spinner restart. Useful when you * need to temporarily stop a spinner for an operation, then restore it to its * previous state if it was spinning. * * @example * ;```ts * import { getDefaultSpinner } from '@socketsecurity/lib/spinner/default' * import { withSpinnerRestore } from '@socketsecurity/lib/spinner/with' * * const spinner = getDefaultSpinner() * const wasSpinning = spinner.isSpinning * spinner.stop() * * const result = await withSpinnerRestore({ * operation: async () => { * // Do work without spinner * return await someOperation() * }, * spinner, * wasSpinning, * }) * // Spinner is automatically restarted if wasSpinning was true * ``` * * @template T - Return type of the operation. * * @param options - Configuration object. * @param options.operation - Async function to execute. * @param options.spinner - Optional spinner instance to manage. * @param options.wasSpinning - Whether spinner was spinning before the * operation. * * @returns Result of the operation * * @throws Re-throws any error from operation after restoring spinner state */ export declare function withSpinnerRestore(options: WithSpinnerRestoreOptions): Promise; /** * Execute a synchronous operation with spinner lifecycle management. Ensures * `spinner.stop()` is always called via try/finally, even if the operation * throws. Provides safe cleanup and consistent spinner behavior for sync * operations. * * @example * ;```ts * import { Spinner } from '@socketsecurity/lib/spinner/spinner' * import { withSpinnerSync } from '@socketsecurity/lib/spinner/with' * * const spinner = Spinner() * * const result = withSpinnerSync({ * message: 'Processing…', * operation: () => { * return processDataSync() * }, * spinner, * }) * ``` * * @template T - Return type of the operation. * * @param options - Configuration object. * @param options.message - Message to display while spinner is running. * @param options.operation - Synchronous function to execute. * @param options.spinner - Optional spinner instance (if not provided, no * spinner is used) * * @returns Result of the operation * * @throws Re-throws any error from operation after stopping spinner */ export declare function withSpinnerSync(options: WithSpinnerSyncOptions): T;