@easbot/terminal 0.3.13 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +197 -32
- package/README.md +182 -27
- package/dist/index.cjs +25 -24
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.mjs +25 -24
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import pe,{Chalk}from'chalk';import me from'os';import we from'path';import {Filesystem}from'@easbot/utils';import*as G from'@clack/prompts';import {note,select}from'@clack/prompts';import*as ge from'readline';import {stripVTControlCharacters}from'util';import {Writable}from'stream';import xe from'process';var
|
|
2
|
-
`).
|
|
3
|
-
`)
|
|
4
|
-
`)}function fn(e,t){let
|
|
5
|
-
`)
|
|
6
|
-
`)
|
|
7
|
-
|
|
1
|
+
import pe,{Chalk}from'chalk';import me from'os';import we from'path';import {Filesystem}from'@easbot/utils';import*as G from'@clack/prompts';import {note,select}from'@clack/prompts';import*as ge from'readline';import {stripVTControlCharacters}from'util';import {Writable}from'stream';import xe from'process';var Rt="\\x1b\\[[0-9;]*m",It="\\x1b\\]8;;.*?\\x1b\\\\|\\x1b\\]8;;\\x1b\\\\",Lt=new RegExp(Rt,"g"),Ot=new RegExp(It,"g");function ee(e){return e?e.replace(Ot,"").replace(Lt,""):""}function j(e){return e?Array.from(ee(e)).length:0}var K={accent:"#FF5A2D",accentBright:"#FF7A3D",accentDim:"#D14A22",info:"#FF8A5B",success:"#2FBF71",warn:"#FFB020",error:"#E23D2D",muted:"#8B7F77"};var Wt=typeof process.env.FORCE_COLOR=="string"&&process.env.FORCE_COLOR.trim().length>0&&process.env.FORCE_COLOR.trim()!=="0",Te=process.env.NO_COLOR&&!Wt?new Chalk({level:0}):pe,z=e=>Te.hex(e),u={accent:z(K.accent),accentBright:z(K.accentBright),accentDim:z(K.accentDim),info:z(K.info),success:z(K.success),warn:z(K.warn),error:z(K.error),muted:z(K.muted),heading:Te.bold.hex(K.accent),command:z(K.accentBright),option:z(K.warn)},k=()=>Te.level>0,S=(e,t,n)=>e?t(n):n;var F;(d=>{d.icons={success:"\u2713",error:"\u2717",warning:"\u26A0",info:"\u2139",accent:"\u25C6",muted:"\u25CB",heading:"\u25C6",active:"\u25C6",submit:"\u25C7",cancel:"\u25A0",locked:"\u2713",pending:"\u25CB",radioActive:"\u25CF",radioInactive:"\u25CB",skipped:"\u21A1",blocked:"\u2298",cursor:"\u276F"},d.bar={vertical:"\u2502",horizontal:"\u2500",cornerBottom:"\u2514",cornerBottomRight:"\u2518",teeRight:"\u251C",stepActive:"\u25C6",bullet:"\u2022"};function n(l,f){let b=Ft(f);return S(k(),b,l)}d.colorize=n;function s(l){return n(d.icons[l],l)}d.statusIcon=s;function a(l,f){return `${s(l)} ${f}`}d.prefixed=a;})(F||(F={}));function Ft(e){switch(e){case "success":case "locked":case "submit":return u.success;case "error":case "cancel":return u.error;case "warning":return u.warn;case "info":return u.info;case "accent":case "active":case "radioActive":return u.accent;case "muted":case "pending":case "radioInactive":return u.muted;case "skipped":return u.muted;case "blocked":return u.error;case "heading":return u.heading;case "cursor":return u.accentBright}}function Ht(e){return F.prefixed("success",e)}function At(e){return F.prefixed("error",e)}function Nt(e){return F.prefixed("warning",e)}function _t(e){return F.prefixed("info",e)}function Bt(e){return S(k(),u.heading,e)}function Jt(e,t,n=15){if(typeof e=="string"){let l=e.padEnd(n);return `${S(k(),u.muted,l)} ${t??""}`}let s=Object.keys(e);if(s.length===0)return "";let a=Math.max(...s.map(l=>l.length));return s.map(l=>{let f=l.padEnd(a),b=e[l];return `${S(k(),u.muted,f)} ${b==null?"\u2205":String(b)}`}).join(`
|
|
2
|
+
`)}function Vt(e,t){let n=k(),s=S(n,u.command,e);if(!t)return ` ${s}`;let a=S(n,u.muted,`# ${t}`);return ` ${s} ${a}`}function Kt(e,t,n){let s=k(),a=F.colorize(e,"info"),d=S(s,u.command,t),l=n?` ${S(s,u.muted,n)}`:"";return `${a} ${d}${l}`}var Dt={pending:"pending",running:"active",success:"success",error:"error",skipped:"skipped"};function jt(e,t){return F.prefixed(Dt[e],t)}function zt(e=80,t="\u2500"){return S(k(),u.muted,t.repeat(e))}function Yt(e){return S(k(),u.muted,e)}function Gt(e,t,n){let s=e===1?t:n||`${t}s`;return `${S(k(),u.accent,String(e))} ${s}`}function Y(e){let t=e?.trim();return t?Filesystem.toUnixPath(t):void 0}function De(e){try{return Y(e())}catch{return}}function Ut(e,t){let n=Y(e.EASBOT_TEST_HOME);if(n)return n;let s=Y(e.EASBOT_HOME);if(s){if(s==="~"||s.startsWith("~/")||s.startsWith("~\\")){let l=Y(e.HOME)??Y(e.USERPROFILE)??De(t);return l?s.replace(/^~(?=$|[\\/])/,l):void 0}return s}let a=Y(e.HOME);if(a)return a;let d=Y(e.USERPROFILE);return d||De(t)}function ne(e=process.env,t=me.homedir){let n=Ut(e,t);if(n)return n}function $e(e=process.env,t=me.homedir){return ne(e,t)??Filesystem.resolve(process.cwd())}function ye(e,t){if(!e.startsWith("~"))return Y(e);let n=process.env.EASBOT_TEST_HOME?.trim();return n||(n=Y(t?.home)??ne(t?.env??process.env,t?.homedir??me.homedir)),n?e.replace(/^~(?=$|[\\/])/,n):Y(e)}function ze(e){if(!e)return "";let t=e.trim();if(!t)return t;if(t.startsWith("~")){let n=ye(t,{home:$e(process.env,me.homedir),env:process.env,homedir:me.homedir});return we.resolve(n)}return we.resolve(t)}function qt(e=process.env,t=me.homedir){let n=e.EASBOT_STATE_DIR?.trim();if(n)return ze(n);let a=ne(e,t)??process.cwd();return we.join(a,".config","easbot")}function Ye(){return ne(process.env,me.homedir)}function Ge(){let e=Ye();return e?process.env.EASBOT_TEST_HOME?.trim()?{home:e,prefix:"~"}:process.env.EASBOT_HOME?.trim()?{home:e,prefix:"$EASBOT_HOME"}:{home:e,prefix:"~"}:void 0}function Ue(e){if(!e)return e;let t=Ge();if(!t)return e;let{home:n,prefix:s}=t;return e===n?s:e.startsWith(`${n}/`)||e.startsWith(`${n}\\`)?`${s}${e.slice(n.length)}`:e}function qe(e){if(!e)return e;let t=Ge();return t?e.split(t.home).join(t.prefix):e}function Qt(e){return Ue(e)}function Ce(e){return qe(e)}function Xt(e,t){return e?.force===true?true:e?.force===false?false:!!(t??process.stdout?.isTTY)}function ce(e,t,n,s){let a=ee(e??""),d=ee(t??"");return Xt(n,s)?`\x1B]8;;${d}\x07${a}\x1B]8;;\x07`:n?.fallback??`${a} (${d})`}function Zt(e,t,n,s,a){let d=t.trim();if(!e)return ce(n??d,d,s,a);let l=/^[a-z]+:\/\//i.test(d)?d:`${e}${d.startsWith("/")?d:`/${d}`}`;return ce(n??l,l,s,a)}function en(e,t,n){return ce(t??e,e,void 0,n)}function Qe(e,t,n=true){return t===void 0?{ok:n,data:e}:{ok:n,data:e,meta:t}}function tn(e,t){return Qe(e,t,false)}function Xe(e,t=2){console.log(JSON.stringify(e,null,t));}function nn(e){Xe(e);}function rn(e,t){let n={ok:true,data:e};t!==void 0&&(n.meta=t),console.log(JSON.stringify(n,null,2));}function on(e,t){console.log(JSON.stringify({ok:false,error:{code:e,message:t}},null,2));}var ke=e=>k()?u.accent(e):e,Ee=e=>e&&k()?u.heading(e):e,Re=e=>e&&k()?u.muted(e):e;var cn=/^(https?:\/\/|file:\/\/)/i,an=/^[a-zA-Z]:[\\/]/,ln=/^[a-zA-Z0-9._-]+$/;function Ze(e,t){if(t<=0)return [e];let n=Array.from(e),s=[];for(let a=0;a<n.length;a+=t)s.push(n.slice(a,a+t).join(""));return s.length>0?s:[e]}function et(e){return e?cn.test(e)||e.startsWith("/")||e.startsWith("~/")||e.startsWith("./")||e.startsWith("../")||an.test(e)||e.startsWith("\\\\")||e.includes("/")||e.includes("\\")?true:e.includes("_")&&ln.test(e):false}function un(e,t){if(e.trim().length===0)return [e];if(t<=0)return [e];let n=e.match(/^(\s*)([-*\u2022]\s+)?(.*)$/),s=n?.[1]??"",a=n?.[2]??"",d=n?.[3]??"",l=`${s}${a}`,f=`${s}${a?" ".repeat(a.length):""}`,b=Math.max(10,t-j(l)),w=Math.max(10,t-j(f)),E=d.split(/\s+/).filter(Boolean),O=[],y="",c=l,o=b;for(let x of E){if(!y){if(j(x)>o){if(et(x)){y=x;continue}let $=Ze(x,o),v=$.shift()??"";O.push(c+v),c=f,o=w;for(let g of $)O.push(c+g);continue}y=x;continue}let r=`${y} ${x}`;if(j(r)<=o){y=r;continue}if(O.push(c+y),c=f,o=w,j(x)>o){if(et(x)){y=x;continue}let $=Ze(x,o),v=$.shift()??"";O.push(c+v);for(let g of $)O.push(c+g);y="";continue}y=x;}return (y||E.length===0)&&O.push(c+y),O}function tt(e,t={}){let n=process.stdout?.columns??80,s=t.columns??n,a=t.maxWidth??Math.max(40,Math.min(88,s-10));return e.split(`
|
|
3
|
+
`).flatMap(d=>un(d,a)).join(`
|
|
4
|
+
`)}function ae(e,t,n={}){let s=n.columns??process.stdout?.columns,a=tt(e,{columns:s,maxWidth:n.maxWidth});note(a,Ee(t));}function fn(e,t={}){let n=nt(e,t);if(t.stream==="stderr"){console.error(n);return}if(t.boxed===true){dn(e,t);return}console.log(n);}function nt(e,t={}){let n=k(),s=t.tone==="error"?"error":"success",a=e.length>0,d=a?e:[t.empty??"No results."],l=a?t.title:t.emptyTitle??t.title,f=[];l&&f.push(S(n,s==="error"?u.error:u.heading,l));for(let b of d)f.push(` ${b}`);if(!t.skipOutro){let b=t.outro!==void 0?t.outro:"Done!";b&&f.push(S(n,s==="error"?u.error:u.success,b));}return f.join(`
|
|
5
|
+
`)}function dn(e,t){let n=k(),s=t.tone==="error"?"error":"success",a=e.length>0,d=a?e.join(`
|
|
6
|
+
`):t.empty??"No results.",l=a?t.title:t.emptyTitle??t.title;if(l?ae(d,l):console.log(d),!t.skipOutro){let f=t.outro!==void 0?t.outro:"Done!";f&&console.log(S(n,s==="error"?u.error:u.success,f));}}function rt(e){let t=k(),n=[];if(n.push(S(t,u.heading,e.title)),e.flat&&e.flat.length>0)for(let s of e.flat)n.push(` ${s}`);if(e.groups&&e.groups.length>0)for(let s of e.groups){if(s.key){let a=s.detail?` ${S(t,u.muted,s.detail)}`:"";n.push(S(t,u.heading,s.key)+a);}for(let a of s.rows)n.push(` ${a}`);}if(e.footer&&e.footer.length>0)for(let s of e.footer)n.push(S(t,u.muted,s));return n.join(`
|
|
7
|
+
`)}function mn(e){console.log(rt(e));}function ot(e,t=5){if(e.length<=t)return e.join(", ");let n=e.slice(0,t).join(", "),s=e.length-t;return `${n} +${s} more`}var pn=ot;var it=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],st=80,le;(t=>{function e(n={}){let s=[...it],a=st,d=0,l=null,f=n.message??"Loading...",b=n.spinnerColor??(c=>S(k(),u.accent,c)),w=n.messageColor??(c=>S(k(),u.muted,c)),E=c=>{s=c.frames!==void 0?[...c.frames]:[...it],a=c.intervalMs!==void 0&&c.intervalMs>0?c.intervalMs:st,d=0;};n.indicator&&E(n.indicator);function O(){y(),!(s.length<=1)&&(l=setInterval(()=>{d=(d+1)%s.length;},a));}function y(){l!==null&&(clearInterval(l),l=null);}return {start:O,stop:y,isRunning(){return l!==null},line(){let c=s[d]??"";return `${(c.length>0?ee(b(c)).length:0)>0?`${b(c)} `:""}${w(f)}`},setMessage(c){f=c;},setIndicator(c){E(c??{}),O();}}}t.create=e;})(le||(le={}));var xn=new Writable({write(e,t,n){n();}}),Q;(y=>{y.cancelSymbol=Symbol("Search.cancel");function t(c){let o=0;for(let x of c){let r=x.codePointAt(0);if(r===void 0||r===0)continue;let $=r>=4352&&r<=4447||r>=8986&&r<=8987||r>=9001&&r<=9002||r>=9193&&r<=9196||r===9200||r===9203||r>=9725&&r<=9726||r>=9748&&r<=9749||r>=9800&&r<=9811||r===9855||r===9875||r===9889||r>=9898&&r<=9899||r>=9917&&r<=9918||r>=9924&&r<=9925||r===9934||r===9940||r===9962||r>=9970&&r<=9971||r===9973||r===9978||r===9981||r===9989||r>=9994&&r<=9995||r===10024||r===10060||r===10062||r>=10067&&r<=10069||r===10071||r>=10133&&r<=10135||r===10160||r===10175||r>=11035&&r<=11036||r===11088||r===11093||r>=11904&&r<=42191&&r!==12351||r>=43360&&r<=43388||r>=44032&&r<=55203||r>=63744&&r<=64255||r>=65040&&r<=65049||r>=65072&&r<=65135||r>=65280&&r<=65376||r>=65504&&r<=65510||r>=126976&&r<=129535;o+=$?2:1;}return o}y.approxStringWidth=t;function n(c,o){let x=stripVTControlCharacters(c),r=Math.max(1,o),$=t(x);return Math.max(1,Math.ceil($/r))}y.visualRowsForLine=n;function s(c,o){let x=o!==void 0&&o>0?o:process.stdout.columns&&process.stdout.columns>0?process.stdout.columns:80,r=0;for(let $ of c)r+=n($,x);return r}y.countVisualRowsForLines=s;function a(c){let o=new Array(c.length);for(let x=0;x<c.length;x++){let r=c[x],$=r.value===null||r.value===void 0?"":String(r.value);o[x]={...r,searchKey:`${r.label}
|
|
8
|
+
${$}`.toLowerCase()};}return o}function d(c,o){return o===""||c.searchKey.includes(o)}function l(c,o){return o<=0||c<0?0:c>=o?o-1:c}function f(c){if(c?.length!==1)return false;let o=c.codePointAt(0);return !(o===void 0||o<32||o===127||o===27)}function b(){let c=process.stdout.rows;if(!c||c<=0)return 8;let o=Math.floor((c-8)/2);return Math.max(5,Math.min(15,o))}function w(c,o){try{c.write(o);}catch{}}function E(c){if(c&&c.isTTY&&typeof c.setRawMode=="function")try{c.setRawMode(!1);}catch{}}function O(c){let o=c.message,x=a(c.items),r=Math.max(1,c.maxVisible??b()),$=c.initialSelected??[],v=c.required??false,g=c.lockedSection,i=c.isTTY;i??!!process.stdout?.isTTY;return new Promise(m=>{let p=process.stdin,C=process.stdout,B=ge.createInterface({input:p,output:xn,terminal:false});try{(i===!0||i===void 0&&p.isTTY)&&p.setRawMode?.(!0);}catch{}ge.emitKeypressEvents(p,B);let P="",W="",I=0,M=new Set($),J=0,D=false,X=g?g.items.map(R=>R.value):[],at=g?g.items.map(R=>R.label):[],ue=[],Pe=()=>{if(ue.length=0,W==="")for(let R=0;R<x.length;R++){let T=x[R];ue.push(T);}else for(let R=0;R<x.length;R++){let T=x[R];d(T,W)&&ue.push(T);}return ue},lt=()=>{if(J>0){w(C,`\x1B[${J}A`);for(let R=0;R<J;R++)w(C,"\x1B[2K\x1B[1B");w(C,`\x1B[${J}A`);}},We=()=>{let R=at.slice();for(let T=0;T<x.length;T++){let N=x[T];M.has(N.value)&&R.push(N.label);}return R},V=(R="active")=>{lt();let T=[],N=Pe(),U=i===false?false:i===true?true:k(),Be=_=>S(U,u.error,_),de=_=>S(U,u.success,_),L=_=>S(U,u.muted,_),be=_=>S(U,u.heading,_),gt=_=>S(U,pe.bold,_),ht=_=>S(U,pe.underline,_),xt=_=>S(U,pe.inverse,_),bt=_=>S(U,pe.strikethrough,_),vt=L(F.bar.vertical);F.bar.horizontal;de(F.bar.bullet);let Je=R==="active"||R==="error"?F.icons.active:R==="cancel"?F.icons.cancel:F.icons.submit,Tt=R==="cancel"||R==="error"?Be(Je):de(Je);if(T.push(`${Tt} ${gt(o)}`),R==="active"||R==="error"){if(g&&g.items.length>0){T.push(vt);let Z=`${be(g.title)} ${L("\u2500\u2500 always included")}`;T.push(`${L("\u2502")} ${L("\u2500\u2500")} ${Z} ${L("\u2500".repeat(12))}`);for(let ie of g.items)T.push(`${L("\u2502")} ${de("\u2022")} ${be(ie.label)}`);g.hiddenCount&&g.hiddenCount>0&&T.push(`${L("\u2502")} ${L(`...and ${g.hiddenCount} more`)}`),T.push(L("\u2502")),T.push(`${L("\u2502")} ${L("\u2500\u2500")} ${be("Additional agents")} ${L("\u2500".repeat(29))}`);}let _=`${L("\u2502")} ${L("Search:")} ${P}${xt(" ")}`;T.push(_),T.push(`${L("\u2502")} ${L("\u2191\u2193 move \xB7 space select \xB7 enter confirm")}`),T.push(L("\u2502"));let St=Math.max(0,N.length-r),$t=I-Math.floor(r/2),ve=Math.max(0,Math.min($t,St)),Ve=Math.min(N.length,ve+r);if(N.length===0)T.push(`${L("\u2502")} ${L("No matches found")}`);else {for(let q=ve;q<Ve;q++){let se=N[q],yt=M.has(se.value),Ke=q===I,wt=yt?F.statusIcon("radioActive"):F.colorize(F.icons.radioInactive,"radioInactive"),Ct=Ke?ht(se.label):se.label,kt=se.hint?L(` (${se.hint})`):"",Et=Ke?F.colorize(F.icons.cursor,"cursor"):" ";T.push(`${L("\u2502")} ${Et} ${wt} ${Ct}${kt}`);}let Z=ve,ie=N.length-Ve;if(Z>0||ie>0){let q=[];Z>0&&q.push(`\u2191 ${Z} more`),ie>0&&q.push(`\u2193 ${ie} more`),T.push(`${L("\u2502")} ${L(q.join(" "))}`);}}T.push(L("\u2502"));let oe=We();if(oe.length===0)T.push(`${L("\u2502")} ${L("Selected: (none)")}`);else {let Z=oe.length<=3?oe.join(", "):`${oe.slice(0,3).join(", ")} +${oe.length-3} more`;T.push(`${L("\u2502")} ${de("Selected:")} ${Z}`);}R==="error"&&T.push(`${L("\u2502")} ${Be("\u26A0 Please select at least one item before submitting")}`),T.push(`${L("\u2514")}`);}else if(R==="submit"){let _=We();T.push(`${L("\u2502")} ${L(_.join(", "))}`);}else T.push(`${L("\u2502")} ${bt(L("Cancelled"))}`);w(C,`${T.join(`
|
|
8
9
|
`)}
|
|
9
|
-
`);try{J=s(
|
|
10
|
-
`),"\u64CD\u4F5C\u63D0\u793A");}return await Q.multiselect({message:
|
|
11
|
-
${
|
|
12
|
-
`);}
|
|
10
|
+
`);try{J=s(T,C.columns);}catch{J=T.length;}},Fe=false,ut=()=>{if(!Fe){Fe=true;try{p.removeListener("keypress",_e),p.removeListener("end",Ne);}catch{}try{process.removeListener("SIGINT",fe),process.removeListener("SIGTERM",fe);}catch{}E(p);try{B.close();}catch{}}},He=R=>{D||(D=true,ut(),m(R));},ft=()=>{if(v&&M.size===0&&X.length===0){V("error");return}V("submit"),He([...X,...Array.from(M)]);},Ae=()=>{V("cancel"),He(y.cancelSymbol);},Ne=()=>{Ae();},fe=()=>{E(p);},dt=R=>{let T=R[I];T&&(M.has(T.value)?M.delete(T.value):M.add(T.value));},mt=R=>{P+=R,W+=R.toLowerCase();},pt=()=>{P.length!==0&&(P=P.slice(0,-1),W=W.slice(0,-1));},_e=(R,T)=>{if(!T)return;let N=Pe();if(I=l(I,N.length),T.name==="return"){ft();return}if(T.name==="escape"||T.ctrl&&T.name==="c"){Ae();return}if(T.name==="up"||T.name==="left"){N.length>0&&(I=l(I-1,N.length),V());return}if(T.name==="down"||T.name==="right"){N.length>0&&(I=l(I+1,N.length),V());return}if(T.name==="pageup"){N.length>0&&(I=l(I-r,N.length),V());return}if(T.name==="pagedown"){N.length>0&&(I=l(I+r,N.length),V());return}if(T.name==="home"){N.length>0&&(I=0,V());return}if(T.name==="end"){N.length>0&&(I=N.length-1,V());return}if(T.name==="space"){dt(N),V();return}if(T.name==="backspace"){P.length>0&&(pt(),I=0,V());return}!T.ctrl&&!T.meta&&f(T.sequence)&&(mt(T.sequence),I=0,V());};p.on("keypress",_e),p.once("end",Ne),process.on("SIGINT",fe),process.on("SIGTERM",fe),V();})}y.multiselect=O;})(Q||(Q={}));var Ie;(c=>{c.cancelSymbol=Q.cancelSymbol;function t(o){return o===c.cancelSymbol||typeof o=="symbol"}c.isCancel=t;async function n(o){return await G.select({message:o.message,options:o.options,...o.initialValue!==void 0?{initialValue:o.initialValue}:{}})}c.select=n;async function s(o){return await G.groupMultiselect({message:o.message,options:o.options,...o.initialValues!==void 0?{initialValues:o.initialValues}:{},...o.required!==void 0?{required:o.required}:{}})}c.groupMultiselect=s;async function a(o){return await G.text({message:o.message,...o.placeholder!==void 0?{placeholder:o.placeholder}:{},...o.defaultValue!==void 0?{defaultValue:o.defaultValue}:{},...o.validate!==void 0?{validate:o.validate}:{}})}c.text=a;async function d(o){return await G.password({message:o.message,...o.mask!==void 0?{mask:o.mask}:{}})}c.password=d;async function l(o){return await G.confirm({message:o.message,...o.initialValue!==void 0?{initialValue:o.initialValue}:{}})}c.confirm=l;async function f(o){if(o.withGuide===true){let r=o.guideLines??["Use \u2191 / \u2193 to navigate","Press Space to toggle selection","Press a to toggle all","Press i to invert selection","Press Enter to submit"];ae(r.join(`
|
|
11
|
+
`),"\u64CD\u4F5C\u63D0\u793A");}return await Q.multiselect({message:o.message,items:o.options,...o.initialValues!==void 0?{initialSelected:o.initialValues}:{},...o.required!==void 0?{required:o.required}:{},...o.lockedSection!==void 0?{lockedSection:o.lockedSection}:{},...o.maxVisible!==void 0?{maxVisible:o.maxVisible}:{},...o.isTTY!==void 0?{isTTY:o.isTTY}:{}})}c.multiselect=f;function b(o){let x=k(),r=S(x,u.heading,o),$=S(x,u.muted,"\u2500".repeat(Math.max(8,o.length*2)));process.stdout.write(`${r}
|
|
12
|
+
${$}
|
|
13
|
+
`);}c.intro=b;function w(o,x){let r=k(),$=x?.success!==false,v=o??"Done!",g=$?u.success:u.error,i=S(r,g,v),h=S(r,u.muted,"\u2500".repeat(Math.max(8,v.length*2)));process.stdout.write(`${i}
|
|
13
14
|
${h}
|
|
14
|
-
`);}
|
|
15
|
-
${
|
|
16
|
-
`),process.exit(0);}
|
|
17
|
-
`);}h.step=
|
|
18
|
-
`);}h.message=g;function i(m,p,C){let B=k(),P=`${F.statusIcon(m)} ${p}`;if(C){let W
|
|
15
|
+
`);}c.outro=w;function E(o){let x=k(),r=o??"Cancelled.",$=`${F.statusIcon("cancel")} ${r}`,v=S(x,u.muted,"\u2500".repeat(Math.max(8,r.length*2)));process.stdout.write(`${$}
|
|
16
|
+
${v}
|
|
17
|
+
`),process.exit(0);}c.cancel=E;(h=>{function o(m,p){i("info",m,p);}h.info=o;function x(m,p){i("warning",m,p);}h.warn=x;function r(m,p){i("error",m,p);}h.error=r;function $(m){i("success",m);}h.success=$;function v(m){let p=`${F.statusIcon("active")} ${m}`;process.stdout.write(`${p}
|
|
18
|
+
`);}h.step=v;function g(m){process.stdout.write(`${m}
|
|
19
|
+
`);}h.message=g;function i(m,p,C){let B=k(),P=`${F.statusIcon(m)} ${p}`;if(C){let W=S(B,u.muted,C);process.stdout.write(`${P}
|
|
19
20
|
${W}
|
|
20
21
|
`);}else process.stdout.write(`${P}
|
|
21
|
-
`);}})(
|
|
22
|
-
`),g=false;},update(i){
|
|
23
|
-
`);}catch(d){console.error(`[terminal] restore reporting failed${s}: ${String(d)}`);}}function
|
|
24
|
-
`),reset:()=>{t=false,
|
|
22
|
+
`);}})(c.Log||(c.Log={}));function y(o){let x=o?.color??(i=>S(k(),u.accent,i)),r=i=>S(k(),u.muted,i),$=le.create({...o?.frames!==void 0?{message:""}:{},spinnerColor:x,messageColor:r,indicator:{frames:o?.frames??[],intervalMs:80}}),v=null,g=false;return {start(i){i!==void 0&&$.setMessage(i),!g&&(g=true,$.start(),v=setInterval(()=>{process.stdout.write(`\r${$.line()}\x1B[K`);},80));},stop(i){v!==null&&(clearInterval(v),v=null),i!==void 0&&$.setMessage(i),$.stop(),process.stdout.write(`\r${$.line()}\x1B[K
|
|
23
|
+
`),g=false;},update(i){$.setMessage(i);},line(){return $.line()}}}c.spinner=y;})(Ie||(Ie={}));var Le;(d=>{d.icons={help:"\u2753",tip:"\u{1F4A1}",note:"\u{1F4DD}",book:"\u{1F4DA}",lightning:"\u26A1",setting:"\u{1F527}",keyboard:"\u2328",key:"\u2328",mcp:"\u{1F50C}",skill:"\u2726",tool:"\u{1F6E0}",plugin:"\u{1F9E9}",session:"\u{1F4AC}",model:"\u{1F916}",agent:"\u{1F464}",workspace:"\u{1F4C2}"};function t(l,f){let b=bn(f);return S(k(),b,l)}d.colorize=t;function n(l){return t(d.icons[l],l)}d.icon=n;function s(l,f){return `${n(l)} ${f}`}d.prefixed=s;function a(l){return `${n("keyboard")} ${l}`}d.iconForKey=a;})(Le||(Le={}));function bn(e){switch(e){case "help":case "tip":case "note":case "book":case "keyboard":return u.info;case "lightning":case "tool":case "setting":case "mcp":return u.accent;case "skill":case "plugin":case "session":case "model":case "agent":case "workspace":return u.muted;case "key":return u.accentBright}}var re=null;function vn(e,t){try{e.write(t);}catch{}}function Tn(e){e.isTTY&&(re=e);}function Oe(){re?.isTTY&&vn(re,"\r\x1B[2K");}function Sn(e){re&&(e&&re!==e||(re=null));}function yn(e){return select({...e,message:ke(e.message),options:e.options.map(t=>t.hint===void 0?t:{...t,hint:Re(t.hint)})})}var wn="\x1B[0m\x1B[?25h\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?2004l";function he(e,t,n){let s=n?` (${n})`:"",a=`[terminal] restore ${e} failed${s}: ${String(t)}`;try{xe.stderr.write(`${a}
|
|
24
|
+
`);}catch(d){console.error(`[terminal] restore reporting failed${s}: ${String(d)}`);}}function Cn(e,t={}){let n=t.resumeStdinIfPaused??t.resumeStdin??false;try{Oe();}catch(a){he("progress line",a,e);}let s=xe.stdin;if(s?.isTTY&&typeof s.setRawMode=="function"){try{s.setRawMode(!1);}catch(a){he("raw mode",a,e);}if(n&&typeof s.isPaused=="function"&&s.isPaused())try{s.resume();}catch(a){he("stdin resume",a,e);}}if(xe.stdout?.isTTY)try{xe.stdout.write(wn);}catch(a){he("stdout reset",a,e);}}function En(e){let t=e?.code;return t==="EPIPE"||t==="EIO"}function Rn(e={}){let t=false,n=false,s=(f,b)=>{n||(n=true,e.onBrokenPipe?.(f,b));},a=(f,b)=>{if(!En(f))throw f;return t=true,s(f,b),false},d=(f,b)=>{if(t)return false;try{e.beforeWrite?.();}catch(w){return a(w,xe.stderr)}try{return f.write(b),!t}catch(w){return a(w,f)}};return {write:d,writeLine:(f,b)=>d(f,`${b}
|
|
25
|
+
`),reset:()=>{t=false,n=false;},isClosed:()=>t}}function te(e,t){return !Number.isFinite(t)||t<=0?"":e.repeat(t)}function In(e,t,n){let s=j(e);if(s>=t)return e;let a=t-s;if(n==="right")return `${te(" ",a)}${e}`;if(n==="center"){let d=Math.floor(a/2),l=a-d;return `${te(" ",d)}${e}${te(" ",l)}`}return `${e}${te(" ",a)}`}function Ln(e,t){if(!e||e.length===0)return [""];if(!Number.isFinite(t)||t<=0)return [e];let n="\x1B",s=[];for(let i=0;i<e.length;){if(e[i]===n){if(e[i+1]==="["){let p=i+2;for(;p<e.length;){let C=e[p];if(C==="m")break;if(C&&C>="0"&&C<="9"){p+=1;continue}if(C===";"){p+=1;continue}break}if(e[p]==="m"){s.push({kind:"ansi",value:e.slice(i,p+1)}),i=p+1;continue}}if(e[i+1]==="]"&&e.slice(i+2,i+5)==="8;;"){let p=e.indexOf(`${n}\\`,i+5);if(p>=0){s.push({kind:"ansi",value:e.slice(i,p+2)}),i=p+2;continue}}}let h=e.codePointAt(i);if(!h)break;let m=String.fromCodePoint(h);s.push({kind:"char",value:m}),i+=m.length;}let a=s.findIndex(i=>i.kind==="char");if(a<0)return [e];let d=-1;for(let i=s.length-1;i>=0;i-=1){let h=s[i];if(h&&h.kind==="char"){d=i;break}}let l=s.slice(0,a).filter(i=>i.kind==="ansi").map(i=>i.value).join(""),f=s.slice(d+1).filter(i=>i.kind==="ansi").map(i=>i.value).join(""),b=s.slice(a,d+1),w=[],E=i=>i===" "||i===" "||i==="/"||i==="-"||i==="_"||i===".",O=i=>i===" "||i===" ",y=false,c=[],o=0,x=null,r=i=>(i??c).map(h=>h.value).join(""),$=i=>i.reduce((h,m)=>h+(m.kind==="char"?1:0),0),v=i=>{let h=i.replace(/\s+$/,"");h.trim().length!==0&&w.push(h);},g=i=>{if(c.length===0)return;if(i==null||i<=0){v(r()),c.length=0,o=0,x=null;return}let h=c.slice(0,i),m=c.slice(i);for(v(r(h));m.length>0;){let p=m[0];if(p?.kind!=="char"||!O(p.value))break;m.shift();}c.length=0,c.push(...m),o=$(c),x=null;};for(let i of b){if(i.kind==="ansi"){c.push(i);continue}let h=i.value;if(!(y&&(y=false,h===`
|
|
25
26
|
`))){if(h===`
|
|
26
|
-
`||h==="\r"){g(
|
|
27
|
+
`||h==="\r"){g(c.length),h==="\r"&&(y=true);continue}o+1>t&&o>0&&g(x),c.push(i),o+=1,E(h)&&(x=c.length);}}return g(c.length),w.length===0?[""]:!l&&!f?w:w.map(i=>i&&`${l}${i}${f}`)}function On(e){if(e!=null&&!(!Number.isFinite(e)||e<=0))return Math.floor(e)}function Mn(e){let t=e.rows.map(v=>{let g={};for(let[i,h]of Object.entries(v))g[i]=Ce(h);return g}),n=e.border??"unicode";if(n==="none"){let v=e.columns;return `${[v.map(h=>h.header).join(" | "),...t.map(h=>v.map(m=>h[m.key]??"").join(" | "))].join(`
|
|
27
28
|
`)}
|
|
28
|
-
`}let s=Math.max(0,e.padding??1),
|
|
29
|
+
`}let s=Math.max(0,e.padding??1),a=e.columns,d=a.map(v=>{let g=j(v.header),i=Math.max(0,...t.map(h=>j(h[v.key]??"")));return {headerW:g,cellW:i}}),l=a.map((v,g)=>{let i=d[g];if(!i)throw new Error(`Internal error: metrics[${g}] is undefined`);let h=Math.max(i.headerW,i.cellW)+s*2,m=v.maxWidth?Math.min(h,v.maxWidth):h;return Math.max(v.minWidth??3,m)}),f=On(e.width),b=a.length+1,w=l.reduce((v,g)=>v+g,0)+b,E=a.map((v,g)=>{let i=d[g];if(!i)throw new Error(`Internal error: metrics[${g}] is undefined`);return Math.max(v.minWidth??3,i.headerW+s*2,3)}),O=a.map((v,g)=>{let i=d[g];if(!i)throw new Error(`Internal error: metrics[${g}] is undefined`);return Math.max(i.headerW+s*2,3)});if(f&&w>f){let v=w-f,g=a.map((m,p)=>{let C=l[p];if(C===void 0)throw new Error(`Internal error: widths[${p}] is undefined`);return {i:p,w:C}}).filter(({i:m})=>!!a[m]?.flex).toSorted((m,p)=>p.w-m.w).map(m=>m.i),i=a.map((m,p)=>{let C=l[p];if(C===void 0)throw new Error(`Internal error: widths[${p}] is undefined`);return {i:p,w:C}}).filter(({i:m})=>!a[m]?.flex).toSorted((m,p)=>p.w-m.w).map(m=>m.i),h=(m,p)=>{let C=[],B=0;for(let W of m){let I=l[W],M=p[W];if(I===void 0||M===void 0)continue;let J=I-M;J<=0||(C.push({i:W,free:J}),B+=J);}if(C.length===0)return;let P=v;for(let{i:W,free:I}of C){if(P<=0)break;let M=l[W],J=p[W];if(M===void 0||J===void 0)continue;let D=Math.min(I,Math.floor(I*P/B)),X=Math.min(D,P);l[W]=M-X,P-=X;}for(let{i:W}of C){if(P<=0)break;let I=l[W],M=p[W];I===void 0||M===void 0||I<=M||(l[W]=I-1,P-=1);}v=P;};h(g,E),h(g,O),h(i,E),h(i,O);}if(f){let v=a.length+1,g=l.reduce((h,m)=>h+m,0)+v,i=f-g;if(i>0){let h=a.map((m,p)=>({c:m,i:p})).filter(({c:m})=>!!m.flex).map(({i:m})=>m);if(h.length>0){let m=a.map(p=>typeof p.maxWidth=="number"&&p.maxWidth>0?Math.floor(p.maxWidth):Number.POSITIVE_INFINITY);for(;i>0;){let p=false;for(let C of h){let B=l[C],P=m[C];if(!(B===void 0||P===void 0)&&!(B>=P)&&(l[C]=B+1,i-=1,p=true,i<=0))break}if(!p)break}}}}let y=n==="ascii"?{tl:"+",tr:"+",bl:"+",br:"+",h:"-",v:"|",t:"+",ml:"+",m:"+",mr:"+",b:"+"}:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518",h:"\u2500",v:"\u2502",t:"\u252C",ml:"\u251C",m:"\u253C",mr:"\u2524",b:"\u2534"},c=(v,g,i)=>`${v}${l.map(h=>{if(h===void 0)throw new Error("Internal error: width is undefined");return te(y.h,h)}).join(g)}${i}`,o=v=>{let g=l[v];if(g===void 0)throw new Error(`Internal error: widths[${v}] is undefined`);return Math.max(1,g-s*2)},x=te(" ",s),r=(v,g=false)=>{let h=a.map(C=>g?C.header:v[C.key]??"").map((C,B)=>Ln(C,o(B))),m=Math.max(...h.map(C=>C.length)),p=[];for(let C=0;C<m;C+=1){let B=h.map((P,W)=>{let I=P[C],M=a[W];if(!M)throw new Error(`Internal error: columns[${W}] is undefined`);let J=o(W);if(I===void 0)return `${x}${te(" ",J)}${x}`;let D=In(I,J,M.align??"left");return `${x}${D}${x}`});p.push(`${y.v}${B.join(y.v)}${y.v}`);}return p},$=[];$.push(c(y.tl,y.t,y.tr)),$.push(...r({},true)),$.push(c(y.ml,y.m,y.mr));for(let v of t)$.push(...r(v,false));return $.push(c(y.bl,y.b,y.br)),`${$.join(`
|
|
29
30
|
`)}
|
|
30
|
-
`}var
|
|
31
|
+
`}var Pn=[{prefix:"failed",color:u.error},{prefix:"ok",color:u.success},{prefix:"linked",color:u.success},{prefix:"configured",color:u.success},{prefix:"not linked",color:u.warn},{prefix:"not configured",color:u.muted},{prefix:"unknown",color:u.warn}];function Wn(e,t){if(!t)return e;let n=e.indexOf(":");if(n===-1)return e;let s=e.slice(0,n+1),a=e.slice(n+1).trimStart(),d=a.toLowerCase();for(let{prefix:l,color:f}of Pn)if(d.startsWith(l))return `${s} ${f(a.slice(0,l.length))}${a.slice(l.length)}`;return e}var Fn=e=>S(k(),u.accent,e),Hn=e=>S(k(),u.muted,e),Me;(l=>{function e(f){let b=f;typeof b.resume=="function"&&b.resume();}function t(f,b){try{f.write(b);}catch{}}function n(f,b,w){let E=f;for(let O=0;O<b.length;O+=1){let y=b[O],c=y.charCodeAt(0);if(c===3)return {buffer:E,done:true,line:""};if(c===4)return {buffer:E,done:true,line:E};if(c===10||c===13)return {buffer:"",done:true,line:E};if((c===8||c===127)){E=E.slice(0,-1);continue}E+=y;}return {buffer:E,done:false,line:""}}function s(f){return new Promise((b,w)=>{let{message:E,hint:O,defaultValue:y,hidden:c,input:o,output:x,messageColor:r,hintColor:$}=f,v=(r??Fn)(E),g=O?` ${($??Hn)(`(${O})`)}`:"",i=y?` [${y}]`:"",h=c?`${v}${g}: `:`${v}${g}${i}: `,m=o??xe.stdin,p=x??xe.stdout;t(p,h);let C="",B=false,P=M=>{B||(B=true,M(),m.off("data",W),m.off("end",I));},W=M=>{let J=typeof M=="string"?M:M.toString("utf8");if(J.includes("")){P(()=>w(new Error("Input canceled")));return}let D=n(C,J);if(C=D.buffer,!D.done)return;let X=D.line.length===0&&y!==void 0?y:D.line;P(()=>b(X));},I=()=>{if(B)return;let M=C.length===0&&y!==void 0?y:C;P(()=>b(M));};m.on("data",W),m.once("end",I),e(m);})}l.readText=s;async function a(f){let b=f.defaultValue!==false,E=(await s({message:f.message,hint:f.hint??`y/n, default ${b?"y":"n"}`,defaultValue:b?"y":"n",messageColor:f.messageColor,hintColor:f.hintColor,input:f.input,output:f.output})).trim().toLowerCase();return E===""?b:E==="y"||E==="yes"?true:E==="n"||E==="no"?false:a(f)}l.readConfirm=a;function d(f){return s({...f,hidden:true})}l.readPassword=d;})(Me||(Me={}));var An=e=>S(k(),u.heading,e),Nn=e=>S(k(),u.command,e),_n=e=>S(k(),u.muted,e),Bn=e=>S(k(),u.warn,e),Jn=e=>S(k(),u.accent,e);function Vn(e,t,n,s,a,d){let l=e;return l=l.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(f,b,w)=>`${d(b)} (${w})`),l=l.replace(/`([^`]+)`/g,(f,b)=>a(b)),l=l.replace(/\*\*([^*]+)\*\*/g,(f,b)=>n(b)),l=l.replace(/(^|[^*])\*([^*]+)\*(?!\*)/g,(f,b,w)=>`${b}${s(w)}`),l}function Kn(e,t={}){if(!e)return [];let n=t.headingColor??An,s=t.boldColor??Nn,a=t.italicColor??_n,d=t.codeColor??Bn,l=t.linkColor??Jn,f=r=>Vn(r,n,s,a,d,l),b=e.replace(/\r\n/g,`
|
|
31
32
|
`).split(`
|
|
32
|
-
`),w=[],E=false,
|
|
33
|
+
`),w=[],E=false,O=[],y="",c=0,o=true,x=()=>{if(O.length!==0){w.push(d(`\`\`\`${y}`));for(let r of O)w.push(d(r));w.push(d("```")),O=[],y="";}};for(let r of b){let $=r;if($.trim().startsWith("```")){if(!E){x(),E=true,y=$.trim().slice(3).trim(),w.push(d(`\`\`\`${y}`)),o=false;continue}for(let h of O)w.push(d(h));O=[],w.push(d("```")),E=false,y="",o=false;continue}if(E){O.push($);continue}let v=/^(#{1,3})\s+(.+)$/.exec($);if(v){let h=v[1]??"#",m=v[2]??"";w.push(n(`${h} ${f(m)}`)),o=false;continue}if(/^(\s*[-*_])\s*\1\s*\1[-*_\s]*$/.test($)||/^---\s*$/.test($)||/^\*\*\*\s*$/.test($)){w.push(d("\u2500".repeat(40))),o=true;continue}let g=/^\s*[-*]\s+(.+)$/.exec($),i=/^\s*\d+\.\s+(.+)$/.exec($);if(g){let h=g[1]??"";w.push(` \u2022 ${f(h)}`),c=0,o=false;continue}if(i){let h=i[1]??"";c+=1,w.push(` ${c}. ${f(h)}`),o=false;continue}if($.trim()===""){o||w.push(""),o=true,c=0;continue}w.push(f($)),o=false,c=0;}return E&&x(),w}var Oo=Q,Mo=Q.cancelSymbol;export{Le as HelpSymbol,Me as Input,K as LOBSTER_PALETTE,le as Loader,Ie as Prompt,Oo as Search,F as Symbol,Mo as cancelSymbol,Oe as clearActiveProgressLine,S as colorize,Rn as createSafeStreamWriter,Qt as displayPath,Ce as displayString,nn as emitCommandJson,Xe as emitJson,on as emitJsonError,rn as emitJsonOk,ye as expandHomePrefix,Vt as formatCommandExample,Gt as formatCount,Yt as formatEmptyMessage,At as formatError,Bt as formatHeading,_t as formatInfo,Jt as formatKeyValue,pn as formatList,Kt as formatListItem,ot as formatListTruncated,nt as formatPrintHuman,en as formatRootLink,Zt as formatRootedLink,zt as formatSeparator,jt as formatStatus,Ht as formatSuccess,ce as formatTerminalLink,Nt as formatWarning,k as isRich,ae as note,fn as printHuman,mn as printRenderLines,Tn as registerActiveProgressLine,rt as renderLines,Kn as renderMarkdown,Mn as renderTable,qt as resolveConfigDir,ne as resolveEffectiveHomeDir,Ye as resolveHomeDir,$e as resolveRequiredHomeDir,ze as resolveUserPath,Cn as restoreTerminalState,yn as selectStyled,qe as shortenHomeInString,Ue as shortenHomePath,ee as stripAnsi,Wn as styleHealthChannelLine,Re as stylePromptHint,ke as stylePromptMessage,Ee as stylePromptTitle,u as theme,Sn as unregisterActiveProgressLine,j as visibleWidth,tn as wrapError,Qe as wrapJson,tt as wrapNoteMessage};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easbot/terminal",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"description": "Terminal interaction toolkit for the EASBOT ecosystem — themed colors, ANSI utilities, OSC-8 hyperlinks, command formatting, table rendering, styled prompts, safe stream writes, and terminal-state recovery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@clack/prompts": "^1.7.0",
|
|
49
49
|
"chalk": "^6.0.0",
|
|
50
|
-
"@easbot/
|
|
51
|
-
"@easbot/
|
|
50
|
+
"@easbot/types": "0.3.16",
|
|
51
|
+
"@easbot/utils": "0.3.16"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^25.
|
|
54
|
+
"@types/node": "^25.9.5",
|
|
55
55
|
"tsup": "^8.5.1",
|
|
56
56
|
"typescript": "^6.0.3",
|
|
57
57
|
"vitest": "^4.1.5"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
|
-
"node": ">=22.22.
|
|
60
|
+
"node": ">=22.22.2"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|