// cli/interactive.ts — Interactive prompts via node:readline (SPEC-124)
import { createInterface } from 'node:readline';
function createRl() {
    return createInterface({ input: process.stdin, output: process.stdout });
}
/**
 * Ask a free-text question and return the answer.
 */
export function ask(question) {
    return new Promise((resolve) => {
        const rl = createRl();
        rl.question(`${question} `, (answer) => {
            rl.close();
            resolve(answer.trim());
        });
    });
}
/**
 * Ask a yes/no confirmation question.
 */
export async function confirm(question, defaultYes = true) {
    const hint = defaultYes ? '[Y/n]' : '[y/N]';
    const answer = await ask(`${question} ${hint}`);
    if (answer === '') {
        return defaultYes;
    }
    return answer.toLowerCase().startsWith('y');
}
/**
 * Present a numbered list and let the user pick one option.
 */
export async function select(question, options) {
    const lines = options.map((opt, i) => `  ${String(i + 1)}. ${opt}`);
    const prompt = `${question}\n${lines.join('\n')}\nChoice: `;
    const answer = await ask(prompt);
    const idx = parseInt(answer, 10) - 1;
    if (idx >= 0 && idx < options.length) {
        return options[idx];
    }
    return options[0];
}
//# sourceMappingURL=interactive.js.map