} `}}}).prompt()},fe=t=>{const n=(s,r)=>{const i=s.label??String(s.value);return r==="active"?`${e.cyan(A)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:r==="selected"?`${e.green(T)} ${e.dim(i)}`:r==="cancelled"?`${e.strikethrough(e.dim(i))}`:r==="active-selected"?`${e.green(T)} ${i} ${s.hint?e.dim(`(${s.hint})`):""}`:r==="submitted"?`${e.dim(i)}`:`${e.dim(F)} ${e.dim(i)}`};return new wD({options:t.options,initialValues:t.initialValues,required:t.required??true,cursorAt:t.cursorAt,validate(s){if(this.required&&s.length===0)return `Please select at least one option. ${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`},render(){const s=`${e.gray(o)} ${w(this.state)} ${t.message} `,r=(i,a)=>{const c=this.value.includes(i.value);return a&&c?n(i,"active-selected"):c?n(i,"selected"):n(i,a?"active":"inactive")};switch(this.state){case "submit":return `${s}${e.gray(o)} ${this.options.filter(({value:i})=>this.value.includes(i)).map(i=>n(i,"submitted")).join(e.dim(", "))||e.dim("none")}`;case "cancel":{const i=this.options.filter(({value:a})=>this.value.includes(a)).map(a=>n(a,"cancelled")).join(e.dim(", "));return `${s}${e.gray(o)} ${i.trim()?`${i} ${e.gray(o)}`:""}`}case "error":{const i=this.error.split(` `).map((a,c)=>c===0?`${e.yellow(d)} ${e.yellow(a)}`:` ${a}`).join(` `);return `${s+e.yellow(o)} ${B({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:r}).join(` ${e.yellow(o)} `)} ${i} `}default:return `${s}${e.cyan(o)} ${B({options:this.options,cursor:this.cursor,maxItems:t.maxItems,style:r}).join(` ${e.cyan(o)} `)} ${e.cyan(d)} `}}}).prompt()};`${e.gray(o)} `; const kCancel = Symbol.for("cancel"); async function prompt(message, opts = {}) { const handleCancel = (value) => { if (typeof value !== "symbol" || value.toString() !== "Symbol(clack:cancel)") { return value; } switch (opts.cancel) { case "reject": { const error = new Error("Prompt cancelled."); error.name = "ConsolaPromptCancelledError"; if (Error.captureStackTrace) { Error.captureStackTrace(error, prompt); } throw error; } case "undefined": { return void 0; } case "null": { return null; } case "symbol": { return kCancel; } default: case "default": { return opts.default ?? opts.initial; } } }; if (!opts.type || opts.type === "text") { return await he({ message, defaultValue: opts.default, placeholder: opts.placeholder, initialValue: opts.initial }).then(handleCancel); } if (opts.type === "confirm") { return await ye({ message, initialValue: opts.initial }).then(handleCancel); } if (opts.type === "select") { return await ve({ message, options: opts.options.map( (o) => typeof o === "string" ? { value: o, label: o } : o ), initialValue: opts.initial }).then(handleCancel); } if (opts.type === "multiselect") { return await fe({ message, options: opts.options.map( (o) => typeof o === "string" ? { value: o, label: o } : o ), required: opts.required, initialValues: opts.initial }).then(handleCancel); } throw new Error(`Unknown prompt type: ${opts.type}`); } exports.kCancel = kCancel; exports.prompt = prompt;