"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TerminalSpinnerService = void 0;
const ora = require("ora");
const yok_1 = require("../common/yok");
class TerminalSpinnerService {
    createSpinner(spinnerOptions = {}) {
        spinnerOptions.stream = spinnerOptions.stream || process.stdout;
        return ora(spinnerOptions);
    }
    async execute(spinnerOptions, action) {
        const spinner = this.createSpinner(spinnerOptions);
        spinner.start();
        let result = null;
        try {
            result = await action();
        }
        catch (err) {
            spinner.fail();
            return null;
        }
        spinner.succeed();
        return result;
    }
}
exports.TerminalSpinnerService = TerminalSpinnerService;
yok_1.injector.register("terminalSpinnerService", TerminalSpinnerService);
