eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
5 lines • 6.58 kB
JavaScript
import{W}from"../../node_modules/.pnpm/@clack_core@1.3.1/node_modules/@clack/core/dist/index.js";import{UNICODE_ROW_GLYPHS,renderCursorRow,renderOptionRow,renderOptionRowContinuation,resolveOptionRowState}from"./option-row.js";const RAIL=`│`,CORNER=`└`;function bulletFor(e,t){switch(e){case`initial`:case`active`:return t.green(`△`);case`submit`:return t.green(`▲`);case`cancel`:return t.gray(`▲`);case`error`:return t.red(`▲`)}}function railFor(e,t){switch(e){case`initial`:case`active`:return t.white(`│`);case`submit`:return t.green(`│`);case`cancel`:return t.gray(`│`);case`error`:return t.red(`│`)}}function cornerFor(e,t){switch(e){case`initial`:case`active`:return t.white(`└`);case`submit`:return t.green(`└`);case`cancel`:return t.gray(`└`);case`error`:return t.red(`└`)}}function formatPromptHeader(e,t,n){return`${n.leadingRail===`green`?n.colors.green(`│`):n.colors.white(`│`)}\n${bulletFor(e,n.colors)} ${t}\n`}function formatPromptSubmission(e,t,n,r){let i=r.leadingRail===`green`?r.colors.green(`│`):r.colors.white(`│`),a=n===``?``:` ${n}`;return`${i}\n${bulletFor(e,r.colors)} ${r.colors.dim(t)}${a}`}function formatPromptOpener(e,t,n){return`\n${n.bold(n.white(`▲`))} ${n.bold(e)}\n ${n.dim(t)}\n${n.white(`│`)}\n`}function formatPromptOutro(e,t){let n=e.replace(/\n/g,`
`);return`${t.green(`│`)}\n${t.green(`●`)} ${n}\n`}function formatPromptCancellation(e,t){let n=e.replace(/\n/g,`
`);return`${t.red(`│`)}\n${t.red(`●`)} ${t.red(n)}\n`}function formatRailLine(t,n,r){if(t===``)return`${n.green(`│`)}\n`;let i=`${n.green(`│`)} `;return`${t.split(`
`).map(t=>t===``?n.green(`│`):W(r,t,i)).join(`
`)}\n`}function renderMultiselectPrompt(e){let t=railFor(e.state,e.colors),n=formatPromptHeader(e.state,e.message,{colors:e.colors,leadingRail:e.leadingRail}),r=new Set(e.selectedValues),i=e.options.some(e=>!e.disabled)?``:`\n${t}\n${t} ${e.colors.dim(`(no channels available to add)`)}`;switch(e.state){case`submit`:{let t=r.size===0?e.colors.dim(`(none selected)`):e.options.filter(e=>r.has(e.value)).map(e=>e.label).join(`, `);return formatPromptSubmission(e.state,e.message,t,{colors:e.colors,leadingRail:e.leadingRail})}case`cancel`:return`${n}${t} ${e.colors.strikethrough(e.colors.dim(`cancelled`))}\n${t}`;case`error`:{let r=renderMultiselectRows({...e,rail:t});return`${n.trim()}\n${t} ${r}${i}\n${cornerFor(e.state,e.colors)} ${e.colors.red(e.error??``)}\n`}case`initial`:case`active`:return`${n}${t} ${renderMultiselectRows({...e,rail:t})}${i}\n${cornerWithNote(cornerFor(e.state,e.colors),e.footerNote)}\n`}}function cornerWithNote(e,t){return t?`${e} ${t}`:e}function renderSelectPrompt(e){let t=railFor(e.state,e.colors),n=formatPromptHeader(e.state,e.message,{colors:e.colors,leadingRail:e.leadingRail}),r=e.options[e.cursor];switch(e.state){case`submit`:{let t=r?r.label:``;return formatPromptSubmission(e.state,e.message,t,{colors:e.colors,leadingRail:e.leadingRail})}case`cancel`:return`${n}${t} ${r?e.colors.strikethrough(e.colors.dim(r.label)):``}\n${t}`;case`initial`:case`active`:case`error`:{let r=labelColumnWidth(e.options);return`${n}${t} ${e.options.map((n,i)=>{let a=i===e.cursor;return`${optionRow(n,{colors:e.colors,isCursor:a,isChecked:!1,placeholder:!1,hintPadding:r-n.label.length})}${descriptionLine(n,a,t,e.colors)}`}).join(`\n${t} `)}\n${cornerWithNote(cornerFor(e.state,e.colors),e.footerNote)}\n`}}}function labelColumnWidth(e){return e.reduce((e,t)=>Math.max(e,t.label.length),0)}function optionRow(e,n){return renderOptionRow({colors:n.colors,glyphs:UNICODE_ROW_GLYPHS,label:e.label,hint:e.hint,focusHint:e.focusHint,accent:e.accent,isCursor:n.isCursor,state:resolveOptionRowState(e,n.isChecked),placeholder:n.placeholder,hintPadding:n.hintPadding})}function descriptionLine(e,t,n,r){return t&&e.description&&!e.disabled?`\n${n} ${renderOptionRowContinuation(r.dim(e.description))}`:``}function renderSubmitRow(e,r,i=`Submit`){let a=r.bold(i),o=e?`${UNICODE_ROW_GLYPHS.selectedPointer} ${a}`:` ${r.dim(a)}`,s=e?``:` `;return`${renderCursorRow(o,e,r)}${s}${r.green(UNICODE_ROW_GLYPHS.success)}`}function renderMultiselectRows(e){let t=new Set(e.selectedValues),n=labelColumnWidth(e.options),r=e.options.map((r,i)=>{let a=i===e.cursor;return`${optionRow(r,{colors:e.colors,isCursor:a,isChecked:t.has(r.value),placeholder:!0,hintPadding:n-r.label.length})}${descriptionLine(r,a,e.rail,e.colors)}`}).join(`\n${e.rail} `),i=renderSubmitRow(e.cursor===e.options.length,e.colors,e.submitLabel);return`${r}\n${e.rail}\n${e.rail} ${i}`}function searchableHelpLine(e,t,n){let r=(n?[[t.cyan(`type`),`to filter`]]:[[t.cyan(`type`),`to filter`],[t.cyan(`enter`),`to select`]]).map(([e,n])=>`${e}${t.dim(` ${n}`)}`).join(t.dim(` · `));return`\n${e} ${t.dim(`(`)}${r}${t.dim(`)`)}`}function renderSearchableSelect(e){let{colors:t}=e,n=railFor(e.state,t),r=formatPromptHeader(e.state,e.message,{colors:t,leadingRail:e.leadingRail});if(e.state===`submit`)return formatPromptSubmission(e.state,e.message,e.submitDisplay,{colors:t,leadingRail:e.leadingRail});if(e.state===`cancel`)return`${r}${n} ${t.strikethrough(t.dim(e.filter))}${e.filter.trim()?`\n${n}`:``}`;let i=new Set(e.selectedValues),a=0;for(;e.options[a]?.featured;)a+=1;let o=e.viewSize??8,s=e.filter===``&&a>0?Math.min(a,o):o,c=e.multiple&&e.cursor>=e.options.length,l=!c&&e.cursor>=e.options.length?0:e.cursor,u=t.inverse(` `);e.filter.length>0?u=e.filter+t.inverse(` `):e.placeholder&&(u=t.dim(e.placeholder));let d=Math.max(0,Math.min(l-Math.floor(s/2),Math.max(0,e.options.length-s))),f=Math.min(d+s,e.options.length),p=e.options.slice(d,f),m=labelColumnWidth(p),h=p.length===0?t.dim(`(no matches)`):p.map((r,a)=>{let o=!c&&a+d===l;return`${optionRow(r,{colors:t,isCursor:o,isChecked:e.multiple&&i.has(r.value),placeholder:!1,hintPadding:m-r.label.length})}${descriptionLine(r,o,n,t)}`}).join(`\n${n} `),g=e.multiple?`\n${n}\n${n} ${renderSubmitRow(c,t,e.submitLabel)}`:``,_=e.options.length>p.length?`\n${n} ${t.dim(`↑↓ ${e.options.length} options, showing ${d+1}–${f}`)}`:``,v=searchableHelpLine(n,t,e.multiple),y=`${n} ${t.dim(` `)} ${u}\n${n} ${h}${g}${_}${v}`;return e.state===`error`?`${r.trim()}\n${y}\n${cornerFor(e.state,t)} ${t.red(e.error??``)}\n`:`${r}${y}\n${cornerWithNote(cornerFor(e.state,t),e.footerNote)}\n`}export{CORNER,RAIL,bulletFor,cornerFor,formatPromptCancellation,formatPromptHeader,formatPromptOpener,formatPromptOutro,formatPromptSubmission,formatRailLine,railFor,renderMultiselectPrompt,renderSearchableSelect,renderSelectPrompt,renderSubmitRow};