import { cancel as clackCancel, confirm as clackConfirm, intro as clackIntro, isCancel as clackIsCancel, log as clackLog, multiselect as clackMultiselect, outro as clackOutro, select as clackSelect, text as clackText, } from "@clack/prompts"; import { PromptAdapter } from "../PromptAdapter"; import { Confirm, Log, MultiSelect, MultiText, Select, SelectOption, Text, } from "../types"; export class ClackPromptAdapter implements PromptAdapter { public log: Log = { info: (message: string) => clackLog.info(message), warn: (message: string) => clackLog.warn(message), error: (message: string) => clackLog.error(message), success: (message: string) => clackLog.success(message), }; public async confirm({ message, defaultValue, abortMessage, }: Confirm): Promise { return this.prompt( async () => await clackConfirm({ message, initialValue: defaultValue, }), abortMessage ); } public async text({ message, placeholder, defaultValue, abortMessage, validate, }: Text): Promise { const result = await this.prompt( async () => await clackText({ message, initialValue: defaultValue, placeholder, validate, }), abortMessage ); return result?.trim(); } public async multiText({ text, confirm }: MultiText): Promise { const lines: Array = []; let keepGoing = true; while (keepGoing) { const result = await this.text(text); if (result !== "") { lines.push(result); } const isContinue = await this.confirm(confirm); if (!isContinue) { keepGoing = false; } } return lines; } public async select