UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 1.38 kB
import{visibleLine}from"./line-editor.js";import{clipVisible,renderInputWithBlockCursor,wrapVisibleLine}from"#cli/ui/terminal-text.js";function selectedRow(e,t){let n=t.colors;return`${n.inverse(n.blue(` ${t.glyph.selectedPointer} ${e} `))} ${n.dim(`↵`)}`}function renderQuestionPanel(e,t,n){let r=t.colors,i=t.glyph,a=[r.dim(i.hrule.repeat(Math.max(1,n)))];for(let t of e.prompt.split(/\r?\n/u))for(let e of wrapVisibleLine(t,Math.max(8,n-2)))a.push(` ${r.bold(e)}`);a.push(``);for(let[n,r]of e.options.entries())a.push(...optionRows(r.label,r.description,n,e,t));if(e.allowFreeform){let o=e.options.length,s=e.cursor===o;a.push(...optionRows(`Type your own answer`,void 0,o,e,t)),(s||e.editor.text.length>0)&&a.push(` ${r.dim(i.elbow)} ${freeformEditorBody(e,s,t,n)}`)}return a.push(``,` ${r.dim(`Esc to dismiss`)}`),a.map(e=>clipVisible(e,n))}function optionRows(e,t,n,r,i){let a=i.colors,o=`${n+1}. ${e}`,s=[r.cursor===n?` ${selectedRow(o,i)}`:` ${a.dim(`${n+1}.`)} ${e}`];return t!==void 0&&t.length>0&&s.push(` ${a.dim(t)}`),s}function freeformEditorBody(e,t,n,r){let i=n.colors,a=Math.max(4,r-12);if(!t){let t=visibleLine(e.editor,a,n.glyph.ellipsis);return i.dim(`${t.before}${t.under}${t.after}`)}return renderInputWithBlockCursor({...visibleLine(e.editor,a,n.glyph.ellipsis),visible:e.caretVisible,inverse:i.inverse})}export{renderQuestionPanel};