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,n,i){let a=n.colors,o=n.glyph,s=[a.dim(o.hrule.repeat(Math.max(1,i)))];for(let t of e.prompt.split(/\r?\n/u))for(let e of wrapVisibleLine(t,Math.max(8,i-2)))s.push(` ${a.bold(e)}`);s.push(``);for(let[t,r]of e.options.entries())s.push(...optionRows(r.label,r.description,t,e,n));if(e.allowFreeform){let t=e.options.length,r=e.cursor===t;s.push(...optionRows(`Type your own answer`,void 0,t,e,n)),(r||e.editor.text.length>0)&&s.push(` ${a.dim(o.elbow)} ${freeformEditorBody(e,r,n,i)}`)}return s.push(``,` ${a.dim(`Esc to dismiss`)}`),s.map(e=>clipVisible(e,i))}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(t,r,i,a){let o=i.colors,s=Math.max(4,a-12);if(!r){let n=visibleLine(t.editor,s,i.glyph.ellipsis);return o.dim(`${n.before}${n.under}${n.after}`)}return renderInputWithBlockCursor({...visibleLine(t.editor,s,i.glyph.ellipsis),visible:t.caretVisible,inverse:o.inverse})}export{renderQuestionPanel};