import { shouldUseInteractiveDashboard } from "toolcraft-design";
export { shouldUseInteractiveDashboard };
export function formatDashboardDuration(ms) {
    const totalSeconds = Math.round(ms / 1000);
    const minutes = Math.floor(totalSeconds / 60);
    const seconds = totalSeconds % 60;
    return minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`;
}
export function formatDashboardTimestamp(timestamp) {
    const date = new Date(timestamp);
    const hours = String(date.getHours()).padStart(2, "0");
    const minutes = String(date.getMinutes()).padStart(2, "0");
    const seconds = String(date.getSeconds()).padStart(2, "0");
    return `[${hours}:${minutes}:${seconds}]`;
}
export function createDashboardLineBuffer(emit) {
    let pending = "";
    return {
        push(chunk) {
            pending += chunk;
            let newlineIndex = pending.indexOf("\n");
            while (newlineIndex !== -1) {
                const raw = pending.slice(0, newlineIndex);
                const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
                emit(line);
                pending = pending.slice(newlineIndex + 1);
                newlineIndex = pending.indexOf("\n");
            }
        },
        flush() {
            if (pending.length === 0) {
                return;
            }
            const line = pending.endsWith("\r") ? pending.slice(0, -1) : pending;
            emit(line);
            pending = "";
        }
    };
}
export function registerDashboardQuitCommands(options) {
    options.dashboard.onCommand((command) => {
        if (command === "quit") {
            options.requestCancellation();
            return;
        }
        if (command !== "forceQuit") {
            return;
        }
        options.abortController.abort();
        options.dashboard.stop();
        options.dashboard.destroy();
        process.exit(130);
    });
}
//# sourceMappingURL=dashboard-loop-shared.js.map