/**
 * Terminal spinner for async operations.
 *
 * Displays an animated spinner with a message while background work is in progress.
 */
import chalk from 'chalk';
/** Spinner for async operations */
export class Spinner {
    intervalId;
    frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
    currentFrame = 0;
    message;
    constructor(message) {
        this.message = message;
    }
    start() {
        this.intervalId = setInterval(() => {
            process.stdout.write(`\r${chalk.cyan(this.frames[this.currentFrame])} ${this.message}`);
            this.currentFrame = (this.currentFrame + 1) % this.frames.length;
        }, 80);
    }
    stop(finalMessage) {
        if (this.intervalId) {
            clearInterval(this.intervalId);
            this.intervalId = undefined;
        }
        process.stdout.write('\r' + ' '.repeat(this.message.length + 10) + '\r');
        if (finalMessage) {
            console.log(finalMessage);
        }
    }
    update(message) {
        this.message = message;
    }
}
//# sourceMappingURL=Spinner.js.map