import process from "node:process";
import { showUsage } from "citty";
import { styleText } from "node:util";
import * as prompts from "@clack/prompts";
//#region src/lib/cli.ts
var AnvilUx = class {
	log = prompts.log;
	c = styleText;
	intro(title, opts) {
		const final = typeof title === "string" ? styleText(["green", "bold"], title) : title;
		return prompts.intro(final, opts);
	}
	outro(message = "Done.", opts) {
		const final = typeof message === "string" ? styleText(["green", "bold"], message) : message;
		return prompts.outro(final, opts);
	}
	note(...args) {
		return prompts.note(...args);
	}
	box(...args) {
		return prompts.box(...args);
	}
	progress(...args) {
		return prompts.progress(...args);
	}
	feed = prompts.stream;
	confirm(...args) {
		return prompts.confirm(...args);
	}
	select(...args) {
		return prompts.select(...args);
	}
	multiselect(...args) {
		return prompts.multiselect(...args);
	}
	text(...args) {
		return prompts.text(...args);
	}
	isCancel(value) {
		return prompts.isCancel(value);
	}
	formatError(error) {
		if (!(error instanceof Error)) return "Unknown error";
		const lines = [error.message];
		let cause = error.cause;
		while (cause instanceof Error) {
			lines.push(`Cause: ${cause.message}`);
			cause = cause.cause;
		}
		return lines.join("\n");
	}
	handleCancel(value, message = "Cancelled.") {
		if (!this.isCancel(value)) return false;
		prompts.cancel(message);
		return true;
	}
	handleError(error) {
		process.exitCode = 1;
		this.log.error(this.formatError(error));
	}
	async running(label, task, options = {}) {
		if (options.quiet) return await task(this);
		if (!supportsAnimatedSpinner()) {
			this.log.step(label);
			try {
				const result = await task(this);
				this.log.success(label);
				return result;
			} catch (error) {
				this.log.error("Failed.");
				throw error;
			}
		}
		const progress = prompts.spinner();
		progress.start(label);
		try {
			const result = await task(this);
			progress.stop(label);
			return result;
		} catch (error) {
			progress.stop("Failed.");
			throw error;
		}
	}
};
const ux = new AnvilUx();
function isInteractiveCli() {
	return Boolean(process.stdin.isTTY);
}
function supportsAnimatedSpinner() {
	const term = process.env.TERM?.trim().toLowerCase();
	if (!process.stdout.isTTY || !process.stderr.isTTY) return false;
	if (!term || term === "dumb") return false;
	return true;
}
async function showCommandHelp(command) {
	await showUsage(command);
}
//#endregion
export { showCommandHelp as n, ux as r, isInteractiveCli as t };

//# sourceMappingURL=cli-B86kvKcR.mjs.map