@easbot/tui 0.2.1 → 0.2.3
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/dist/index.cjs +37 -42
- package/dist/index.d.cts +290 -39
- package/dist/index.d.ts +290 -39
- package/dist/index.mjs +37 -42
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
|
-
'use strict';var child_process=require('child_process'),
|
|
2
|
-
`).filter(Boolean),l=[];for(let a of o){let h=a.endsWith("/")?a.slice(0,-1):a;if(h===".git"||h.startsWith(".git/")||h.includes("/.git/"))continue;let u=a.endsWith("/");l.push({path:a,isDirectory:u});}return l}var $e=class{constructor(e=[],t=process.cwd(),s=null){c(this,"commands");c(this,"basePath");c(this,"fdPath");this.commands=e,this.basePath=t,this.fdPath=s;}getSuggestions(e,t,s){let r=(e[t]||"").slice(0,s),o=this.extractAtPrefix(r);if(o){let{rawPrefix:a,isQuotedPrefix:h}=ot(o),u=this.getFuzzyFileSuggestions(a,{isQuotedPrefix:h});return u.length===0?null:{items:u,prefix:o}}if(r.startsWith("/")){let a=r.indexOf(" ");if(a===-1){let h=r.slice(1),u=this.commands.map(p=>({name:"name"in p?p.name:p.value,label:"name"in p?p.name:p.label,description:p.description})),f=ce(u,h,p=>p.name).map(p=>({value:p.name,label:p.label,...p.description&&{description:p.description}}));return f.length===0?null:{items:f,prefix:r}}else {let h=r.slice(1,a),u=r.slice(a+1),f=this.commands.find(d=>("name"in d?d.name:d.value)===h);if(!f||!("getArgumentCompletions"in f)||!f.getArgumentCompletions)return null;let p=f.getArgumentCompletions(u);return !p||p.length===0?null:{items:p,prefix:u}}}let l=this.extractPathPrefix(r,false);if(l!==null){let a=this.getFileSuggestions(l);return a.length===0?null:a.length===1&&a[0]?.value===l&&!l.endsWith("/")?{items:a,prefix:l}:{items:a,prefix:l}}return null}applyCompletion(e,t,s,i,r){let o=e[t]||"",l=o.slice(0,s-r.length),a=o.slice(s),h=r.startsWith('"')||r.startsWith('@"'),u=a.startsWith('"'),f=i.value.endsWith('"'),p=h&&f&&u?a.slice(1):a;if(r.startsWith("/")&&l.trim()===""&&!r.slice(1).includes("/")){let x=`${l}/${i.value} ${p}`,b=[...e];return b[t]=x,{lines:b,cursorLine:t,cursorCol:l.length+i.value.length+2}}if(r.startsWith("@")){let x=i.label.endsWith("/"),b=x?"":" ",P=`${l+i.value}${b}${p}`,B=[...e];B[t]=P;let T=i.value.endsWith('"'),S=x&&T?i.value.length-1:i.value.length;return {lines:B,cursorLine:t,cursorCol:l.length+S+b.length}}let m=o.slice(0,s);if(m.includes("/")&&m.includes(" ")){let x=l+i.value+p,b=[...e];b[t]=x;let P=i.label.endsWith("/"),B=i.value.endsWith('"'),T=P&&B?i.value.length-1:i.value.length;return {lines:b,cursorLine:t,cursorCol:l.length+T}}let g=l+i.value+p,y=[...e];y[t]=g;let L=i.label.endsWith("/"),C=i.value.endsWith('"'),A=L&&C?i.value.length-1:i.value.length;return {lines:y,cursorLine:t,cursorCol:l.length+A}}extractAtPrefix(e){let t=rt(e);if(t?.startsWith('@"'))return t;let s=it(e),i=s===-1?0:s+1;return e[i]==="@"?e.slice(i):null}extractPathPrefix(e,t=false){let s=rt(e);if(s)return s;let i=it(e),r=i===-1?e:e.slice(i+1);return t||r.includes("/")||r.startsWith(".")||r.startsWith("~/")||r===""&&e.endsWith(" ")?r:null}expandHomePath(e){if(e.startsWith("~/")){let t=ae.join(He.homedir(),e.slice(2));return e.endsWith("/")&&!t.endsWith("/")?`${t}/`:t}else if(e==="~")return He.homedir();return e}resolveScopedFuzzyQuery(e){let t=e.lastIndexOf("/");if(t===-1)return null;let s=e.slice(0,t+1),i=e.slice(t+1),r;s.startsWith("~/")?r=this.expandHomePath(s):s.startsWith("/")?r=s:r=ae.join(this.basePath,s);try{if(!J.statSync(r).isDirectory())return null}catch{return null}return {baseDir:r,query:i,displayBase:s}}scopedPathForDisplay(e,t){return e==="/"?`/${t}`:`${e}${t}`}getFileSuggestions(e){try{let t,s,{rawPrefix:i,isAtPrefix:r,isQuotedPrefix:o}=ot(e),l=i;if(l.startsWith("~")&&(l=this.expandHomePath(l)),i===""||i==="./"||i==="../"||i==="~"||i==="~/"||i==="/"||r&&i==="")i.startsWith("~")||l.startsWith("/")?t=l:t=ae.join(this.basePath,l),s="";else if(i.endsWith("/"))i.startsWith("~")||l.startsWith("/")?t=l:t=ae.join(this.basePath,l),s="";else {let f=ae.dirname(l),p=ae.basename(l);i.startsWith("~")||l.startsWith("/")?t=f:t=ae.join(this.basePath,f),s=p;}let h=J.readdirSync(t,{withFileTypes:!0}),u=[];for(let f of h){if(!f.name.toLowerCase().startsWith(s.toLowerCase()))continue;let p=f.isDirectory();if(!p&&f.isSymbolicLink())try{let C=ae.join(t,f.name);p=J.statSync(C).isDirectory();}catch{}let d,m=f.name,g=i;if(g.endsWith("/"))d=g+m;else if(g.includes("/"))if(g.startsWith("~/")){let C=g.slice(2),A=ae.dirname(C);d=`~/${A==="."?m:ae.join(A,m)}`;}else if(g.startsWith("/")){let C=ae.dirname(g);C==="/"?d=`/${m}`:d=`${C}/${m}`;}else d=ae.join(ae.dirname(g),m);else g.startsWith("~")?d=`~/${m}`:d=m;let y=p?`${d}/`:d,L=lt(y,{isDirectory:p,isAtPrefix:r,isQuotedPrefix:o});u.push({value:L,label:m+(p?"/":"")});}return u.sort((f,p)=>{let d=f.value.endsWith("/"),m=p.value.endsWith("/");return d&&!m?-1:!d&&m?1:f.label.localeCompare(p.label)}),u}catch{return []}}scoreEntry(e,t,s){let r=ae.basename(e).toLowerCase(),o=t.toLowerCase(),l=0;return r===o?l=100:r.startsWith(o)?l=80:r.includes(o)?l=50:e.toLowerCase().includes(o)&&(l=30),s&&l>0&&(l+=10),l}getFuzzyFileSuggestions(e,t){if(!this.fdPath)return [];try{let s=this.resolveScopedFuzzyQuery(e),i=s?.baseDir??this.basePath,r=s?.query??e,l=Ft(i,this.fdPath,r,100).map(u=>({...u,score:r?this.scoreEntry(u.path,r,u.isDirectory):1})).filter(u=>u.score>0);l.sort((u,f)=>f.score-u.score);let a=l.slice(0,20),h=[];for(let{path:u,isDirectory:f}of a){let p=f?u.slice(0,-1):u,d=s?this.scopedPathForDisplay(s.displayBase,p):p,m=ae.basename(p),g=f?`${d}/`:d,y=lt(g,{isDirectory:f,isAtPrefix:!0,isQuotedPrefix:t.isQuotedPrefix});h.push({value:y,label:m+(f?"/":""),description:d});}return h}catch{return []}}getForceFileSuggestions(e,t,s){let r=(e[t]||"").slice(0,s);if(r.trim().startsWith("/")&&!r.trim().includes(" "))return null;let o=this.extractPathPrefix(r,true);if(o!==null){let l=this.getFileSuggestions(o);return l.length===0?null:{items:l,prefix:o}}return null}shouldTriggerFileCompletion(e,t,s){let r=(e[t]||"").slice(0,s);return !(r.trim().startsWith("/")&&!r.trim().includes(" "))}};var re=new Intl.Segmenter(void 0,{granularity:"grapheme"});function ye(){return re}function Vt(n){let e=n.codePointAt(0);return e>=126976&&e<=130047||e>=8960&&e<=9215||e>=9728&&e<=10175||e>=11088&&e<=11093||n.includes("\uFE0F")||n.length>2}var Ut=new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Mark}|\\p{Surrogate})+$","v"),_t=new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Mark}\\p{Surrogate}]+","v"),Ht=new RegExp("^\\p{RGI_Emoji}$","v"),Nt=512,ue=new Map;function Re(n){if(Ut.test(n))return 0;if(Vt(n)&&Ht.test(n))return 2;let t=n.replace(_t,"").codePointAt(0);if(t===void 0)return 0;let s=getEastAsianWidth.eastAsianWidth(t);if(n.length>1)for(let i of n.slice(1)){let r=i.codePointAt(0);r>=65280&&r<=65519&&(s+=getEastAsianWidth.eastAsianWidth(r));}return s}function w(n){if(n.length===0)return 0;let e=true;for(let r=0;r<n.length;r++){let o=n.charCodeAt(r);if(o<32||o>126){e=false;break}}if(e)return n.length;let t=ue.get(n);if(t!==void 0)return t;let s=n;n.includes(" ")&&(s=s.replace(/\t/g," ")),s.includes("\x1B")&&(s=s.replace(/\x1b\[[0-9;]*[mGKHJ]/g,""),s=s.replace(/\x1b\]8;;[^\x07]*\x07/g,""),s=s.replace(/\x1b_[^\x07\x1b]*(?:\x07|\x1b\\)/g,""));let i=0;for(let{segment:r}of re.segment(s))i+=Re(r);if(ue.size>=Nt){let r=ue.keys().next().value;r!==void 0&&ue.delete(r);}return ue.set(n,i),i}function z(n,e){if(e>=n.length||n[e]!=="\x1B")return null;let t=n[e+1];if(t==="["){let s=e+2;for(;s<n.length&&!/[mGKHJ]/.test(n[s]);)s++;return s<n.length?{code:n.substring(e,s+1),length:s+1-e}:null}if(t==="]"){let s=e+2;for(;s<n.length;){if(n[s]==="\x07")return {code:n.substring(e,s+1),length:s+1-e};if(n[s]==="\x1B"&&n[s+1]==="\\")return {code:n.substring(e,s+2),length:s+2-e};s++;}return null}if(t==="_"){let s=e+2;for(;s<n.length;){if(n[s]==="\x07")return {code:n.substring(e,s+1),length:s+1-e};if(n[s]==="\x1B"&&n[s+1]==="\\")return {code:n.substring(e,s+2),length:s+2-e};s++;}return null}return null}var fe=class{constructor(){c(this,"bold",false);c(this,"dim",false);c(this,"italic",false);c(this,"underline",false);c(this,"blink",false);c(this,"inverse",false);c(this,"hidden",false);c(this,"strikethrough",false);c(this,"fgColor",null);c(this,"bgColor",null);}process(e){if(!e.endsWith("m"))return;let t=e.match(/\x1b\[([\d;]*)m/);if(!t)return;let s=t[1];if(s===""||s==="0"){this.reset();return}let i=(s??"").split(";"),r=0;for(;r<i.length;){let o=Number.parseInt(i[r]??"0",10);if(o===38||o===48){if(i[r+1]==="5"&&i[r+2]!==void 0){let l=`${i[r]};${i[r+1]};${i[r+2]}`;o===38?this.fgColor=l:this.bgColor=l,r+=3;continue}else if(i[r+1]==="2"&&i[r+4]!==void 0){let l=`${i[r]};${i[r+1]};${i[r+2]};${i[r+3]};${i[r+4]}`;o===38?this.fgColor=l:this.bgColor=l,r+=5;continue}}switch(o){case 0:this.reset();break;case 1:this.bold=true;break;case 2:this.dim=true;break;case 3:this.italic=true;break;case 4:this.underline=true;break;case 5:this.blink=true;break;case 7:this.inverse=true;break;case 8:this.hidden=true;break;case 9:this.strikethrough=true;break;case 21:this.bold=false;break;case 22:this.bold=false,this.dim=false;break;case 23:this.italic=false;break;case 24:this.underline=false;break;case 25:this.blink=false;break;case 27:this.inverse=false;break;case 28:this.hidden=false;break;case 29:this.strikethrough=false;break;case 39:this.fgColor=null;break;case 49:this.bgColor=null;break;default:o>=30&&o<=37||o>=90&&o<=97?this.fgColor=String(o):(o>=40&&o<=47||o>=100&&o<=107)&&(this.bgColor=String(o));break}r++;}}reset(){this.bold=false,this.dim=false,this.italic=false,this.underline=false,this.blink=false,this.inverse=false,this.hidden=false,this.strikethrough=false,this.fgColor=null,this.bgColor=null;}clear(){this.reset();}getActiveCodes(){let e=[];return this.bold&&e.push("1"),this.dim&&e.push("2"),this.italic&&e.push("3"),this.underline&&e.push("4"),this.blink&&e.push("5"),this.inverse&&e.push("7"),this.hidden&&e.push("8"),this.strikethrough&&e.push("9"),this.fgColor&&e.push(this.fgColor),this.bgColor&&e.push(this.bgColor),e.length===0?"":`\x1B[${e.join(";")}m`}hasActiveCodes(){return this.bold||this.dim||this.italic||this.underline||this.blink||this.inverse||this.hidden||this.strikethrough||this.fgColor!==null||this.bgColor!==null}getLineEndReset(){return this.underline?"\x1B[24m":""}};function ct(n,e){let t=0;for(;t<n.length;){let s=z(n,t);s?(e.process(s.code),t+=s.length):t++;}}function qt(n){let e=[],t="",s="",i=false,r=0;for(;r<n.length;){let o=z(n,r);if(o){s+=o.code,r+=o.length;continue}let l=n[r],a=l===" ";a!==i&&t&&(e.push(t),t=""),s&&(t+=s,s=""),i=a,t+=l,r++;}return s&&(t+=s),t&&e.push(t),e}function j(n,e){if(!n)return [""];let t=n.split(`
|
|
3
|
-
`),s=[],i=new fe;for(let r of t){let o=s.length>0?i.getActiveCodes():"";s.push(...zt(o+r,e)),ct(r,i);}return s.length>0?s:[""]}function zt(n,e){if(!n)return [""];if(w(n)<=e)return [n];let s=[],i=new fe,r=qt(n),o="",l=0;for(let a of r){let h=w(a),u=a.trim()==="";if(h>e&&!u){if(o){let d=i.getLineEndReset();d&&(o+=d),s.push(o),o="",l=0;}let p=Gt(a,e,i);s.push(...p.slice(0,-1)),o=p[p.length-1]??"",l=w(o);continue}if(l+h>e&&l>0){let p=o.trimEnd(),d=i.getLineEndReset();d&&(p+=d),s.push(p),u?(o=i.getActiveCodes(),l=0):(o=i.getActiveCodes()+a,l=h);}else o+=a,l+=h;ct(a,i);}return o&&s.push(o),s.length>0?s.map(a=>a.trimEnd()):[""]}var jt=/[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;function F(n){return /\s/.test(n)}function V(n){return jt.test(n)}function Gt(n,e,t){let s=[],i=t.getActiveCodes(),r=0,o=0,l=[];for(;o<n.length;){let a=z(n,o);if(a)l.push({type:"ansi",value:a.code}),o+=a.length;else {let h=o;for(;h<n.length&&!z(n,h);)h++;let u=n.slice(o,h);for(let f of re.segment(u))l.push({type:"grapheme",value:f.segment});o=h;}}for(let a of l){if(a.type==="ansi"){i+=a.value,t.process(a.value);continue}let h=a.value;if(!h)continue;let u=w(h);if(r+u>e){let f=t.getLineEndReset();f&&(i+=f),s.push(i),i=t.getActiveCodes(),r=0;}i+=h,r+=u;}return i&&s.push(i),s.length>0?s:[""]}function X(n,e,t){let s=w(n),i=Math.max(0,e-s),r=" ".repeat(i),o=n+r;return t(o)}function O(n,e,t="...",s=false){let i=w(n);if(i<=e)return s?n+" ".repeat(e-i):n;let r=w(t),o=e-r;if(o<=0)return t.substring(0,e);let l=0,a=[];for(;l<n.length;){let p=z(n,l);if(p)a.push({type:"ansi",value:p.code}),l+=p.length;else {let d=l;for(;d<n.length&&!z(n,d);)d++;let m=n.slice(l,d);for(let g of re.segment(m))a.push({type:"grapheme",value:g.segment});l=d;}}let h="",u=0;for(let p of a){if(p.type==="ansi"){h+=p.value;continue}let d=p.value;if(!d)continue;let m=w(d);if(u+m>o)break;h+=d,u+=m;}let f=`${h}\x1B[0m${t}`;if(s){let p=w(f);return f+" ".repeat(Math.max(0,e-p))}return f}function de(n,e,t,s=false){return Be(n,e,t,s).text}function Be(n,e,t,s=false){if(t<=0)return {text:"",width:0};let i=e+t,r="",o=0,l=0,a=0,h="";for(;a<n.length;){let u=z(n,a);if(u){l>=e&&l<i?r+=u.code:l<e&&(h+=u.code),a+=u.length;continue}let f=a;for(;f<n.length&&!z(n,f);)f++;for(let{segment:p}of re.segment(n.slice(a,f))){let d=Re(p),m=l>=e&&l<i,g=!s||l+d<=i;if(m&&g&&(h&&(r+=h,h=""),r+=p,o+=d),l+=d,l>=i)break}if(a=f,l>=i)break}return {text:r,width:o}}var Ee=new fe;function ut(n,e,t,s,i=false){let r="",o=0,l="",a=0,h=0,u=0,f="",p=false,d=t+s;for(Ee.clear();u<n.length;){let m=z(n,u);if(m){Ee.process(m.code),h<e?f+=m.code:h>=t&&h<d&&p&&(l+=m.code),u+=m.length;continue}let g=u;for(;g<n.length&&!z(n,g);)g++;for(let{segment:y}of re.segment(n.slice(u,g))){let L=Re(y);if(h<e?(f&&(r+=f,f=""),r+=y,o+=L):h>=t&&h<d&&(!i||h+L<=d)&&(p||(l+=Ee.getActiveCodes(),p=true),l+=y,a+=L),h+=L,s<=0?h>=e:h>=d)break}if(u=g,s<=0?h>=e:h>=d)break}return {before:r,beforeWidth:o,after:l,afterWidth:a}}var Oe=class{constructor(e=1,t=1,s){c(this,"children",[]);c(this,"paddingX");c(this,"paddingY");c(this,"bgFn");c(this,"cache");this.paddingX=e,this.paddingY=t,this.bgFn=s;}addChild(e){this.children.push(e),this.invalidateCache();}removeChild(e){let t=this.children.indexOf(e);t!==-1&&(this.children.splice(t,1),this.invalidateCache());}clear(){this.children=[],this.invalidateCache();}setBgFn(e){this.bgFn=e;}invalidateCache(){this.cache=void 0;}matchCache(e,t,s){let i=this.cache;return !!i&&i.width===e&&i.bgSample===s&&i.childLines.length===t.length&&i.childLines.every((r,o)=>r===t[o])}invalidate(){this.invalidateCache();for(let e of this.children)e.invalidate?.();}render(e){if(this.children.length===0)return [];let t=Math.max(1,e-this.paddingX*2),s=" ".repeat(this.paddingX),i=[];for(let l of this.children){let a=l.render(t);for(let h of a)i.push(s+h);}if(i.length===0)return [];let r=this.bgFn?this.bgFn("test"):void 0;if(this.matchCache(e,i,r))return this.cache.lines;let o=[];for(let l=0;l<this.paddingY;l++)o.push(this.applyBg("",e));for(let l of i)o.push(this.applyBg(l,e));for(let l=0;l<this.paddingY;l++)o.push(this.applyBg("",e));return this.cache={childLines:i,width:e,bgSample:r,lines:o},o}applyBg(e,t){let s=w(e),i=Math.max(0,t-s),r=e+" ".repeat(i);return this.bgFn?X(r,t,this.bgFn):r}};var D=false;function pe(n){D=n;}function Yt(){return D}var Qt={escape:"escape",esc:"esc",enter:"enter",return:"return",tab:"tab",space:"space",backspace:"backspace",delete:"delete",insert:"insert",clear:"clear",home:"home",end:"end",pageUp:"pageUp",pageDown:"pageDown",up:"up",down:"down",left:"left",right:"right",f1:"f1",f2:"f2",f3:"f3",f4:"f4",f5:"f5",f6:"f6",f7:"f7",f8:"f8",f9:"f9",f10:"f10",f11:"f11",f12:"f12",backtick:"`",hyphen:"-",equals:"=",leftbracket:"[",rightbracket:"]",backslash:"\\",semicolon:";",quote:"'",comma:",",period:".",slash:"/",exclamation:"!",at:"@",hash:"#",dollar:"$",percent:"%",caret:"^",ampersand:"&",asterisk:"*",leftparen:"(",rightparen:")",underscore:"_",plus:"+",pipe:"|",tilde:"~",leftbrace:"{",rightbrace:"}",colon:":",lessthan:"<",greaterthan:">",question:"?",ctrl:n=>`ctrl+${n}`,shift:n=>`shift+${n}`,alt:n=>`alt+${n}`,ctrlShift:n=>`ctrl+shift+${n}`,shiftCtrl:n=>`shift+ctrl+${n}`,ctrlAlt:n=>`ctrl+alt+${n}`,altCtrl:n=>`alt+ctrl+${n}`,shiftAlt:n=>`shift+alt+${n}`,altShift:n=>`alt+shift+${n}`,ctrlShiftAlt:n=>`ctrl+shift+alt+${n}`},Ie=new Set(["`","-","=","[","]","\\",";","'",",",".","/","!","@","#","$","%","^","&","*","(",")","_","+","|","~","{","}",":","<",">","?"]),W={shift:1,alt:2,ctrl:4},E={escape:27,tab:9,enter:13,space:32,backspace:127,kpEnter:57414},K={up:-1,down:-2,right:-3,left:-4},$={delete:-10,insert:-11,pageUp:-12,pageDown:-13,home:-14,end:-15},N={up:["\x1B[A","\x1BOA"],down:["\x1B[B","\x1BOB"],right:["\x1B[C","\x1BOC"],left:["\x1B[D","\x1BOD"],home:["\x1B[H","\x1BOH","\x1B[1~","\x1B[7~"],end:["\x1B[F","\x1BOF","\x1B[4~","\x1B[8~"],insert:["\x1B[2~"],delete:["\x1B[3~"],pageUp:["\x1B[5~","\x1B[[5~"],pageDown:["\x1B[6~","\x1B[[6~"],clear:["\x1B[E","\x1BOE"],f1:["\x1BOP","\x1B[11~","\x1B[[A"],f2:["\x1BOQ","\x1B[12~","\x1B[[B"],f3:["\x1BOR","\x1B[13~","\x1B[[C"],f4:["\x1BOS","\x1B[14~","\x1B[[D"],f5:["\x1B[15~","\x1B[[E"],f6:["\x1B[17~"],f7:["\x1B[18~"],f8:["\x1B[19~"],f9:["\x1B[20~"],f10:["\x1B[21~"],f11:["\x1B[23~"],f12:["\x1B[24~"]},Xt={up:["\x1B[a"],down:["\x1B[b"],right:["\x1B[c"],left:["\x1B[d"],clear:["\x1B[e"],insert:["\x1B[2$"],delete:["\x1B[3$"],pageUp:["\x1B[5$"],pageDown:["\x1B[6$"],home:["\x1B[7$"],end:["\x1B[8$"]},Jt={up:["\x1BOa"],down:["\x1BOb"],right:["\x1BOc"],left:["\x1BOd"],clear:["\x1BOe"],insert:["\x1B[2^"],delete:["\x1B[3^"],pageUp:["\x1B[5^"],pageDown:["\x1B[6^"],home:["\x1B[7^"],end:["\x1B[8^"]},Zt={"\x1BOA":"up","\x1BOB":"down","\x1BOC":"right","\x1BOD":"left","\x1BOH":"home","\x1BOF":"end","\x1B[E":"clear","\x1BOE":"clear","\x1BOe":"ctrl+clear","\x1B[e":"shift+clear","\x1B[2~":"insert","\x1B[2$":"shift+insert","\x1B[2^":"ctrl+insert","\x1B[3$":"shift+delete","\x1B[3^":"ctrl+delete","\x1B[[5~":"pageUp","\x1B[[6~":"pageDown","\x1B[a":"shift+up","\x1B[b":"shift+down","\x1B[c":"shift+right","\x1B[d":"shift+left","\x1BOa":"ctrl+up","\x1BOb":"ctrl+down","\x1BOc":"ctrl+right","\x1BOd":"ctrl+left","\x1B[5$":"shift+pageUp","\x1B[6$":"shift+pageDown","\x1B[7$":"shift+home","\x1B[8$":"shift+end","\x1B[5^":"ctrl+pageUp","\x1B[6^":"ctrl+pageDown","\x1B[7^":"ctrl+home","\x1B[8^":"ctrl+end","\x1BOP":"f1","\x1BOQ":"f2","\x1BOR":"f3","\x1BOS":"f4","\x1B[11~":"f1","\x1B[12~":"f2","\x1B[13~":"f3","\x1B[14~":"f4","\x1B[[A":"f1","\x1B[[B":"f2","\x1B[[C":"f3","\x1B[[D":"f4","\x1B[[E":"f5","\x1B[15~":"f5","\x1B[17~":"f6","\x1B[18~":"f7","\x1B[19~":"f8","\x1B[20~":"f9","\x1B[21~":"f10","\x1B[23~":"f11","\x1B[24~":"f12","\x1Bb":"alt+left","\x1Bf":"alt+right","\x1Bp":"alt+up","\x1Bn":"alt+down"},U=(n,e)=>e.includes(n),H=(n,e,t)=>t===W.shift?U(n,Xt[e]):t===W.ctrl?U(n,Jt[e]):false;function De(n){return n.includes("\x1B[200~")?false:!!(n.includes(":3u")||n.includes(":3~")||n.includes(":3A")||n.includes(":3B")||n.includes(":3C")||n.includes(":3D")||n.includes(":3H")||n.includes(":3F"))}function es(n){return n.includes("\x1B[200~")?false:!!(n.includes(":2u")||n.includes(":2~")||n.includes(":2A")||n.includes(":2B")||n.includes(":2C")||n.includes(":2D")||n.includes(":2H")||n.includes(":2F"))}function we(n){if(!n)return "press";let e=parseInt(n,10);return e===2?"repeat":e===3?"release":"press"}function dt(n){let e=n.match(/^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/);if(e){let r=parseInt(e[1],10),o=e[2]&&e[2].length>0?parseInt(e[2],10):void 0,l=e[3]?parseInt(e[3],10):void 0,a=e[4]?parseInt(e[4],10):1,h=we(e[5]);return {codepoint:r,shiftedKey:o,baseLayoutKey:l,modifier:a-1,eventType:h}}let t=n.match(/^\x1b\[1;(\d+)(?::(\d+))?([ABCD])$/);if(t){let r=parseInt(t[1],10),o=we(t[2]),l={A:-1,B:-2,C:-3,D:-4};return {codepoint:l[t[3]],modifier:r-1,eventType:o}}let s=n.match(/^\x1b\[(\d+)(?:;(\d+))?(?::(\d+))?~$/);if(s){let r=parseInt(s[1],10),o=s[2]?parseInt(s[2],10):1,l=we(s[3]),h={2:$.insert,3:$.delete,5:$.pageUp,6:$.pageDown,7:$.home,8:$.end}[r];if(h!==void 0)return {codepoint:h,modifier:o-1,eventType:l}}let i=n.match(/^\x1b\[1;(\d+)(?::(\d+))?([HF])$/);if(i){let r=parseInt(i[1],10),o=we(i[2]),l=i[3]==="H"?$.home:$.end;return {codepoint:l,modifier:r-1,eventType:o}}return null}function I(n,e,t){let s=dt(n);if(!s)return false;let i=s.modifier&-193,r=t&-193;if(i!==r)return false;if(s.codepoint===e)return true;if(s.baseLayoutKey!==void 0&&s.baseLayoutKey===e){let o=s.codepoint,l=o>=97&&o<=122,a=Ie.has(String.fromCharCode(o));if(!l&&!a)return true}return false}function ft(n,e,t){let s=n.match(/^\x1b\[27;(\d+);(\d+)~$/);if(!s)return false;let i=parseInt(s[1],10),r=parseInt(s[2],10),o=i-1;return r===e&&o===t}function ts(n){let e=n.toLowerCase(),t=e.charCodeAt(0);return t>=97&&t<=122||e==="["||e==="\\"||e==="]"||e==="_"?String.fromCharCode(t&31):e==="-"?"":null}function ss(n){let e=n.toLowerCase().split("+"),t=e[e.length-1];return t?{key:t,ctrl:e.includes("ctrl"),shift:e.includes("shift"),alt:e.includes("alt")}:null}function G(n,e){let t=ss(e);if(!t)return false;let{key:s,ctrl:i,shift:r,alt:o}=t,l=0;switch(r&&(l|=W.shift),o&&(l|=W.alt),i&&(l|=W.ctrl),s){case "escape":case "esc":return l!==0?false:n==="\x1B"||I(n,E.escape,0);case "space":return !D&&(i&&!o&&!r&&n==="\0"||o&&!i&&!r&&n==="\x1B ")?true:l===0?n===" "||I(n,E.space,0):I(n,E.space,l);case "tab":return r&&!i&&!o?n==="\x1B[Z"||I(n,E.tab,W.shift):l===0?n===" "||I(n,E.tab,0):I(n,E.tab,l);case "enter":case "return":return r&&!i&&!o?I(n,E.enter,W.shift)||I(n,E.kpEnter,W.shift)||ft(n,E.enter,W.shift)?true:D?n==="\x1B\r"||n===`
|
|
4
|
-
`:false:
|
|
5
|
-
`||
|
|
6
|
-
`))return "shift+enter";let
|
|
7
|
-
`||n==="\x1BOM")return "enter";if(n==="\0")return "ctrl+space";if(n===" ")return "space";if(n==="\x7F"||n==="\b")return "backspace";if(n==="\x1B[Z")return "shift+tab";if(!D&&n==="\x1B\r")return "alt+enter";if(!D&&n==="\x1B ")return "alt+space";if(n==="\x1B\x7F"||n==="\x1B\b")return "alt+backspace";if(!D&&n==="\x1BB")return "alt+left";if(!D&&n==="\x1BF")return "alt+right";if(!D&&n.length===2&&n[0]==="\x1B"){let s=n.charCodeAt(1);if(s>=1&&s<=26)return `ctrl+alt+${String.fromCharCode(s+96)}`;if(s>=97&&s<=122)return `alt+${String.fromCharCode(s)}`}if(n==="\x1B[A")return "up";if(n==="\x1B[B")return "down";if(n==="\x1B[C")return "right";if(n==="\x1B[D")return "left";if(n==="\x1B[H"||n==="\x1BOH")return "home";if(n==="\x1B[F"||n==="\x1BOF")return "end";if(n==="\x1B[3~")return "delete";if(n==="\x1B[5~")return "pageUp";if(n==="\x1B[6~")return "pageDown";if(n.length===1){let s=n.charCodeAt(0);if(s>=1&&s<=26)return `ctrl+${String.fromCharCode(s+96)}`;if(s>=32&&s<=126)return n}}var pt={cursorUp:"up",cursorDown:"down",cursorLeft:["left","ctrl+b"],cursorRight:["right","ctrl+f"],cursorWordLeft:["alt+left","ctrl+left","alt+b"],cursorWordRight:["alt+right","ctrl+right","alt+f"],cursorLineStart:["home","ctrl+a"],cursorLineEnd:["end","ctrl+e"],jumpForward:"ctrl+]",jumpBackward:"ctrl+alt+]",pageUp:"pageUp",pageDown:"pageDown",deleteCharBackward:"backspace",deleteCharForward:["delete","ctrl+d"],deleteWordBackward:["ctrl+w","alt+backspace"],deleteWordForward:["alt+d","alt+delete"],deleteToLineStart:"ctrl+u",deleteToLineEnd:"ctrl+k",newLine:"shift+enter",submit:"enter",tab:"tab",selectUp:"up",selectDown:"down",selectPageUp:"pageUp",selectPageDown:"pageDown",selectConfirm:"enter",selectCancel:["escape","ctrl+c"],copy:"ctrl+c",yank:"ctrl+y",yankPop:"alt+y",undo:"ctrl+-",expandTools:"ctrl+o",toggleSessionPath:"ctrl+p",toggleSessionSort:"ctrl+s",renameSession:"ctrl+r",deleteSession:"ctrl+d",deleteSessionNoninvasive:"ctrl+backspace"},ke=class{constructor(e={}){c(this,"actionToKeys");this.actionToKeys=new Map,this.buildMaps(e);}buildMaps(e){this.actionToKeys.clear();for(let[t,s]of Object.entries(pt)){let i=Array.isArray(s)?s:[s];this.actionToKeys.set(t,[...i]);}for(let[t,s]of Object.entries(e)){if(s===void 0)continue;let i=Array.isArray(s)?s:[s];this.actionToKeys.set(t,i);}}matches(e,t){let s=this.actionToKeys.get(t);if(!s)return false;for(let i of s)if(G(e,i))return true;return false}getKeys(e){return this.actionToKeys.get(e)??[]}setConfig(e){this.buildMaps(e);}},Se=null;function q(){return Se||(Se=new ke),Se}function ns(n){Se=n;}var me=class{constructor(e="",t=1,s=1,i){c(this,"text");c(this,"paddingX");c(this,"paddingY");c(this,"customBgFn");c(this,"cachedText");c(this,"cachedWidth");c(this,"cachedLines");this.text=e,this.paddingX=t,this.paddingY=s,this.customBgFn=i;}setText(e){this.text=e,this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}setCustomBgFn(e){this.customBgFn=e,this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}invalidate(){this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}render(e){if(this.cachedLines&&this.cachedText===this.text&&this.cachedWidth===e)return this.cachedLines;if(!this.text||this.text.trim()===""){let f=[];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=f,f}let t=this.text.replace(/\t/g," "),s=Math.max(1,e-this.paddingX*2),i=j(t,s),r=" ".repeat(this.paddingX),o=" ".repeat(this.paddingX),l=[];for(let f of i){let p=r+f+o;if(this.customBgFn)l.push(X(p,e,this.customBgFn));else {let d=w(p),m=Math.max(0,e-d);l.push(p+" ".repeat(m));}}let a=" ".repeat(e),h=[];for(let f=0;f<this.paddingY;f++){let p=this.customBgFn?X(a,e,this.customBgFn):a;h.push(p);}let u=[...h,...l,...h];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=u,u.length>0?u:[""]}};var ge=class extends me{constructor(t,s,i,r="Loading..."){super("",1,0);this.spinnerColorFn=s;this.messageColorFn=i;this.message=r;c(this,"frames",["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]);c(this,"currentFrame",0);c(this,"intervalId",null);c(this,"ui",null);this.ui=t,this.start();}render(t){return ["",...super.render(t)]}start(){this.updateDisplay(),this.intervalId=setInterval(()=>{this.currentFrame=(this.currentFrame+1)%this.frames.length,this.updateDisplay();},80);}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null);}setMessage(t){this.message=t,this.updateDisplay();}updateDisplay(){let t=this.frames[this.currentFrame]??"";this.setText(`${this.spinnerColorFn(t)} ${this.messageColorFn(this.message??"")}`),this.ui&&this.ui.requestRender();}};var Fe=class extends ge{constructor(){super(...arguments);c(this,"abortController",new AbortController);c(this,"onAbort");}get signal(){return this.abortController.signal}get aborted(){return this.abortController.signal.aborted}handleInput(t){q().matches(t,"selectCancel")&&(this.abortController.abort(),this.onAbort?.());}dispose(){this.stop();}};var oe=class{constructor(){c(this,"ring",[]);}push(e,t){if(e)if(t.accumulate&&this.ring.length>0){let s=this.ring.pop();this.ring.push(t.prepend?e+s:s+e);}else this.ring.push(e);}peek(){return this.ring.length>0?this.ring[this.ring.length-1]:void 0}rotate(){if(this.ring.length>1){let e=this.ring.pop();this.ring.unshift(e);}}get length(){return this.ring.length}};var Te=null,xt={widthPx:9,heightPx:18};function bt(){return xt}function Ve(n){xt=n;}function vt(){let n=process.env.TERM_PROGRAM?.toLowerCase()||"",e=process.env.TERM?.toLowerCase()||"",t=process.env.COLORTERM?.toLowerCase()||"";return process.env.KITTY_WINDOW_ID||n==="kitty"?{images:"kitty",trueColor:true,hyperlinks:true}:n==="ghostty"||e.includes("ghostty")||process.env.GHOSTTY_RESOURCES_DIR?{images:"kitty",trueColor:true,hyperlinks:true}:process.env.WEZTERM_PANE||n==="wezterm"?{images:"kitty",trueColor:true,hyperlinks:true}:process.env.ITERM_SESSION_ID||n==="iterm.app"?{images:"iterm2",trueColor:true,hyperlinks:true}:n==="vscode"?{images:null,trueColor:true,hyperlinks:true}:n==="alacritty"?{images:null,trueColor:true,hyperlinks:true}:{images:null,trueColor:t==="truecolor"||t==="24bit",hyperlinks:true}}function le(){return Te||(Te=vt()),Te}function rs(){Te=null;}var mt="\x1B_G",gt="\x1B]1337;File=";function te(n){return n.startsWith(mt)||n.startsWith(gt)?true:n.includes(mt)||n.includes(gt)}function os(){return Math.floor(Math.random()*4294967294)+1}function Ct(n,e={}){let s=["a=T","f=100","q=2"];if(e.columns&&s.push(`c=${e.columns}`),e.rows&&s.push(`r=${e.rows}`),e.imageId&&s.push(`i=${e.imageId}`),n.length<=4096)return `\x1B_G${s.join(",")};${n}\x1B\\`;let i=[],r=0,o=true;for(;r<n.length;){let l=n.slice(r,r+4096),a=r+4096>=n.length;o?(i.push(`\x1B_G${s.join(",")},m=1;${l}\x1B\\`),o=false):a?i.push(`\x1B_Gm=0;${l}\x1B\\`):i.push(`\x1B_Gm=1;${l}\x1B\\`),r+=4096;}return i.join("")}function ls(n){return `\x1B_Ga=d,d=I,i=${n}\x1B\\`}function as(){return "\x1B_Ga=d,d=A\x1B\\"}function yt(n,e={}){let t=[`inline=${e.inline!==false?1:0}`];if(e.width!==void 0&&t.push(`width=${e.width}`),e.height!==void 0&&t.push(`height=${e.height}`),e.name){let s=Buffer.from(e.name).toString("base64");t.push(`name=${s}`);}return e.preserveAspectRatio===false&&t.push("preserveAspectRatio=0"),`\x1B]1337;File=${t.join(";")}:${n}\x07`}function Lt(n,e,t={widthPx:9,heightPx:18}){let i=e*t.widthPx/n.widthPx,r=n.heightPx*i,o=Math.ceil(r/t.heightPx);return Math.max(1,o)}function wt(n){try{let e=Buffer.from(n,"base64");if(e.length<24||e[0]!==137||e[1]!==80||e[2]!==78||e[3]!==71)return null;let t=e.readUInt32BE(16),s=e.readUInt32BE(20);return {widthPx:t,heightPx:s}}catch{return null}}function It(n){try{let e=Buffer.from(n,"base64");if(e.length<2||e[0]!==255||e[1]!==216)return null;let t=2;for(;t<e.length-9;){if(e[t]!==255){t++;continue}let s=e[t+1];if(s!==void 0&&s>=192&&s<=194){let r=e.readUInt16BE(t+5);return {widthPx:e.readUInt16BE(t+7),heightPx:r}}if(t+3>=e.length)return null;let i=e.readUInt16BE(t+2);if(i<2)return null;t+=2+i;}return null}catch{return null}}function St(n){try{let e=Buffer.from(n,"base64");if(e.length<10)return null;let t=e.slice(0,6).toString("ascii");if(t!=="GIF87a"&&t!=="GIF89a")return null;let s=e.readUInt16LE(6),i=e.readUInt16LE(8);return {widthPx:s,heightPx:i}}catch{return null}}function kt(n){try{let e=Buffer.from(n,"base64");if(e.length<30)return null;let t=e.slice(0,4).toString("ascii"),s=e.slice(8,12).toString("ascii");if(t!=="RIFF"||s!=="WEBP")return null;let i=e.slice(12,16).toString("ascii");if(i==="VP8 "){if(e.length<30)return null;let r=e.readUInt16LE(26)&16383,o=e.readUInt16LE(28)&16383;return {widthPx:r,heightPx:o}}else if(i==="VP8L"){if(e.length<25)return null;let r=e.readUInt32LE(21),o=(r&16383)+1,l=(r>>14&16383)+1;return {widthPx:o,heightPx:l}}else if(i==="VP8X"){if(e.length<30)return null;let r=((e[24]??0)|(e[25]??0)<<8|(e[26]??0)<<16)+1,o=((e[27]??0)|(e[28]??0)<<8|(e[29]??0)<<16)+1;return {widthPx:r,heightPx:o}}return null}catch{return null}}function Ue(n,e){return e==="image/png"?wt(n):e==="image/jpeg"?It(n):e==="image/gif"?St(n):e==="image/webp"?kt(n):null}function _e(n,e,t={}){let s=le();if(!s.images)return null;let i=t.maxWidthCells??80,r=Lt(e,i,bt());return s.images==="kitty"?{sequence:Ct(n,{columns:i,rows:r,imageId:t.imageId}),rows:r,imageId:t.imageId}:s.images==="iterm2"?{sequence:yt(n,{width:i,height:"auto",preserveAspectRatio:t.preserveAspectRatio??true}),rows:r}:null}function Ae(n,e,t){let s=[];return t&&s.push(t),s.push(`[${n}]`),e&&s.push(`${e.widthPx}x${e.heightPx}`),`[Image: ${s.join(" ")}]`}function Ne(n){return n!==null&&"focused"in n}var se="\x1B_pi:c\x07";function Tt(n,e){if(n===void 0)return;if(typeof n=="number")return n;let t=n.match(/^(\d+(?:\.\d+)?)%$/);if(t)return Math.floor(e*parseFloat(t[1]??"0")/100)}var Pe=class{constructor(){c(this,"children",[]);}addChild(e){this.children.push(e);}removeChild(e){let t=this.children.indexOf(e);t!==-1&&this.children.splice(t,1);}clear(){this.children=[];}invalidate(){for(let e of this.children)e.invalidate?.();}render(e){let t=[];for(let s of this.children)t.push(...s.render(e));return t}},xe=class xe extends Pe{constructor(t,s){super();c(this,"terminal");c(this,"previousLines",[]);c(this,"previousWidth",0);c(this,"focusedComponent",null);c(this,"inputListeners",new Set);c(this,"onDebug");c(this,"renderRequested",false);c(this,"cursorRow",0);c(this,"hardwareCursorRow",0);c(this,"inputBuffer","");c(this,"cellSizeQueryPending",false);c(this,"showHardwareCursor",process.env.PI_HARDWARE_CURSOR==="1");c(this,"clearOnShrink",process.env.PI_CLEAR_ON_SHRINK==="1");c(this,"maxLinesRendered",0);c(this,"previousViewportTop",0);c(this,"fullRedrawCount",0);c(this,"stopped",false);c(this,"overlayStack",[]);this.terminal=t,s!==void 0&&(this.showHardwareCursor=s);}get fullRedraws(){return this.fullRedrawCount}getShowHardwareCursor(){return this.showHardwareCursor}setShowHardwareCursor(t){this.showHardwareCursor!==t&&(this.showHardwareCursor=t,t||this.terminal.hideCursor(),this.requestRender());}getClearOnShrink(){return this.clearOnShrink}setClearOnShrink(t){this.clearOnShrink=t;}setFocus(t){Ne(this.focusedComponent)&&(this.focusedComponent.focused=false),this.focusedComponent=t,Ne(t)&&(t.focused=true);}showOverlay(t,s){let i={component:t,options:s,preFocus:this.focusedComponent,hidden:false};return this.overlayStack.push(i),this.isOverlayVisible(i)&&this.setFocus(t),this.terminal.hideCursor(),this.requestRender(),{hide:()=>{let r=this.overlayStack.indexOf(i);if(r!==-1){if(this.overlayStack.splice(r,1),this.focusedComponent===t){let o=this.getTopmostVisibleOverlay();this.setFocus(o?.component??i.preFocus);}this.overlayStack.length===0&&this.terminal.hideCursor(),this.requestRender();}},setHidden:r=>{if(i.hidden!==r){if(i.hidden=r,r){if(this.focusedComponent===t){let o=this.getTopmostVisibleOverlay();this.setFocus(o?.component??i.preFocus);}}else this.isOverlayVisible(i)&&this.setFocus(t);this.requestRender();}},isHidden:()=>i.hidden}}hideOverlay(){let t=this.overlayStack.pop();if(!t)return;let s=this.getTopmostVisibleOverlay();this.setFocus(s?.component??t.preFocus),this.overlayStack.length===0&&this.terminal.hideCursor(),this.requestRender();}hasOverlay(){return this.overlayStack.some(t=>this.isOverlayVisible(t))}isOverlayVisible(t){return t.hidden?false:t.options?.visible?t.options.visible(this.terminal.columns,this.terminal.rows):true}getTopmostVisibleOverlay(){for(let t=this.overlayStack.length-1;t>=0;t--){let s=this.overlayStack[t];if(s&&this.isOverlayVisible(s))return this.overlayStack[t]}}invalidate(){super.invalidate();for(let t of this.overlayStack)t.component.invalidate?.();}start(){this.stopped=false,this.terminal.start(t=>this.handleInput(t),()=>this.requestRender()),this.terminal.hideCursor(),this.queryCellSize(),this.requestRender();}addInputListener(t){return this.inputListeners.add(t),()=>{this.inputListeners.delete(t);}}removeInputListener(t){this.inputListeners.delete(t);}queryCellSize(){le().images&&(this.cellSizeQueryPending=true,this.terminal.write("\x1B[16t"));}stop(){if(this.stopped=true,this.previousLines.length>0){let s=this.previousLines.length-this.hardwareCursorRow;s>0?this.terminal.write(`\x1B[${s}B`):s<0&&this.terminal.write(`\x1B[${-s}A`),this.terminal.write(`\r
|
|
8
|
-
`);}this.terminal.showCursor(),this.terminal.stop();}requestRender(t=false){t
|
|
9
|
-
`),
|
|
10
|
-
`;
|
|
11
|
-
`.repeat(
|
|
12
|
-
`:"\r";let
|
|
13
|
-
`),
|
|
14
|
-
`);
|
|
15
|
-
`);throw new Error(
|
|
16
|
-
\x1B[2K`;
|
|
17
|
-
`);
|
|
1
|
+
'use strict';var child_process=require('child_process'),ie=require('fs'),lt=require('os'),pe=require('path'),getEastAsianWidth=require('get-east-asian-width'),perf_hooks=require('perf_hooks'),marked=require('marked'),events=require('events'),module$1=require('module');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ie__namespace=/*#__PURE__*/_interopNamespace(ie);var lt__namespace=/*#__PURE__*/_interopNamespace(lt);var pe__namespace=/*#__PURE__*/_interopNamespace(pe);var as=Object.defineProperty;var cs=(i,e,t)=>e in i?as(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var u=(i,e,t)=>cs(i,typeof e!="symbol"?e+"":e,t);var us=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,W=us();function Ct(i,e){let t=i.toLowerCase(),s=e.toLowerCase(),n=d=>{if(d.length===0)return {matches:true,score:0};if(d.length>s.length)return {matches:false,score:0};let h=0,f=0,m=-1,g=0;for(let p=0;p<s.length&&h<d.length;p++)if(s[p]===d[h]){let b=p===0||/[\s\-_./:]/.test(s[p-1]);m===p-1?(g++,f-=g*5):(g=0,m>=0&&(f+=(p-m-1)*2)),b&&(f-=10),f+=p*.1,m=p,h++;}return h<d.length?{matches:false,score:0}:(d===s&&(f-=100),{matches:true,score:f})},r=n(t);if(r.matches)return r;let o=t.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/),a=t.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/),l=o?`${o.groups?.digits??""}${o.groups?.letters??""}`:a?`${a.groups?.letters??""}${a.groups?.digits??""}`:"";if(!l)return r;let c=n(l);return c.matches?{matches:true,score:c.score+5}:r}function ge(i,e,t){if(!e.trim())return i;let s=e.trim().split(/\s+/).filter(r=>r.length>0);if(s.length===0)return i;let n=[];for(let r of i){let o=t(r),a=0,l=true;for(let c of s){let d=Ct(c,o);if(d.matches)a+=d.score;else {l=false;break}}l&&n.push({item:r,totalScore:a});}return n.sort((r,o)=>r.totalScore-o.totalScore),n.map(r=>r.item)}var kt=new Set([" "," ",'"',"'","="]);function re(i){return i.replace(/\\/g,"/")}function fs(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ps(i){let e=re(i);if(!e.includes("/"))return e;let t=e.endsWith("/"),s=e.replace(/^\/+|\/+$/g,"");if(!s)return e;let n="[\\\\/]",r=s.split("/").filter(Boolean).map(a=>fs(a));if(r.length===0)return e;let o=r.join(n);return t&&(o+=n),o}function Ne(i){for(let e=i.length-1;e>=0;e-=1)if(kt.has(i[e]??""))return e;return -1}function ms(i){let e=false,t=-1;for(let s=0;s<i.length;s+=1)i[s]==='"'&&(e=!e,e&&(t=s));return e?t:null}function It(i,e){return e===0||kt.has(i[e-1]??"")}function qe(i){let e=ms(i);return e===null?null:e>0&&i[e-1]==="@"?It(i,e-1)?i.slice(e-1):null:It(i,e)?i.slice(e):null}function wt(i){return i.startsWith('@"')?{rawPrefix:i.slice(2),isAtPrefix:true,isQuotedPrefix:true}:i.startsWith('"')?{rawPrefix:i.slice(1),isAtPrefix:false,isQuotedPrefix:true}:i.startsWith("@")?{rawPrefix:i.slice(1),isAtPrefix:true,isQuotedPrefix:false}:{rawPrefix:i,isAtPrefix:false,isQuotedPrefix:false}}function St(i,e){let t=e.isQuotedPrefix||i.includes(" "),s=e.isAtPrefix?"@":"";return t?`${`${s}"`}${i}"`:`${s}${i}`}async function gs(i,e,t,s,n){let r=["--base-directory",i,"--max-results",String(s),"--type","f","--type","d","--follow","--hidden","--exclude",".git","--exclude",".git/*","--exclude",".git/**"];return re(t).includes("/")&&r.push("--full-path"),t&&r.push(ps(t)),await new Promise(o=>{if(n.aborted){o([]);return}let a=child_process.spawn(e,r,{stdio:["ignore","pipe","pipe"]}),l="",c=false,d=f=>{c||(c=true,n.removeEventListener("abort",h),o(f));},h=()=>{a.exitCode===null&&a.kill("SIGKILL");};n.addEventListener("abort",h,{once:true}),a.stdout.setEncoding("utf-8"),a.stdout.on("data",f=>{l+=f;}),a.on("error",()=>{d([]);}),a.on("close",f=>{if(n.aborted||f!==0||!l){d([]);return}let m=l.trim().split(`
|
|
2
|
+
`).filter(Boolean),g=[];for(let p of m){let b=re(p),y=b.endsWith("/"),x=y?b.slice(0,-1):b;x===".git"||x.startsWith(".git/")||x.includes("/.git/")||g.push({path:b,isDirectory:y});}d(g);});})}var ze=class{constructor(e=[],t,s=null){u(this,"commands");u(this,"basePath");u(this,"fdPath");this.commands=e,this.basePath=t,this.fdPath=s;}async getSuggestions(e,t,s,n){let o=(e[t]||"").slice(0,s),a=this.extractAtPrefix(o);if(a){let{rawPrefix:d,isQuotedPrefix:h}=wt(a),f=await this.getFuzzyFileSuggestions(d,{isQuotedPrefix:h,signal:n.signal});return f.length===0?null:{items:f,prefix:a}}if(!n.force&&o.startsWith("/")){let d=o.indexOf(" ");if(d===-1){let p=o.slice(1),b=this.commands.map(x=>{let I="name"in x?x.name:x.value,M="argumentHint"in x&&x.argumentHint?x.argumentHint:void 0,T=x.description??"",w=M?T?`${M} \u2014 ${T}`:M:T;return {name:I,label:I,description:w||void 0}}),y=ge(b,p,x=>x.name).map(x=>({value:x.name,label:x.label,...x.description&&{description:x.description}}));return y.length===0?null:{items:y,prefix:o}}let h=o.slice(1,d),f=o.slice(d+1),m=this.commands.find(p=>("name"in p?p.name:p.value)===h);if(!m||!("getArgumentCompletions"in m)||!m.getArgumentCompletions)return null;let g=await m.getArgumentCompletions(f);return !Array.isArray(g)||g.length===0?null:{items:g,prefix:f}}let l=this.extractPathPrefix(o,n.force??false);if(l===null)return null;let c=this.getFileSuggestions(l);return c.length===0?null:{items:c,prefix:l}}applyCompletion(e,t,s,n,r){let o=e[t]||"",a=o.slice(0,s-r.length),l=o.slice(s),c=r.startsWith('"')||r.startsWith('@"'),d=l.startsWith('"'),h=n.value.endsWith('"'),f=c&&h&&d?l.slice(1):l;if(r.startsWith("/")&&a.trim()===""&&!r.slice(1).includes("/")){let M=`${a}/${n.value} ${f}`,T=[...e];return T[t]=M,{lines:T,cursorLine:t,cursorCol:a.length+n.value.length+2}}if(r.startsWith("@")){let M=n.label.endsWith("/"),T=M?"":" ",w=`${a+n.value}${T}${f}`,A=[...e];A[t]=w;let $=n.value.endsWith('"'),D=M&&$?n.value.length-1:n.value.length;return {lines:A,cursorLine:t,cursorCol:a.length+D+T.length}}let g=o.slice(0,s);if(g.includes("/")&&g.includes(" ")){let M=a+n.value+f,T=[...e];T[t]=M;let w=n.label.endsWith("/"),A=n.value.endsWith('"'),$=w&&A?n.value.length-1:n.value.length;return {lines:T,cursorLine:t,cursorCol:a.length+$}}let p=a+n.value+f,b=[...e];b[t]=p;let y=n.label.endsWith("/"),x=n.value.endsWith('"'),I=y&&x?n.value.length-1:n.value.length;return {lines:b,cursorLine:t,cursorCol:a.length+I}}extractAtPrefix(e){let t=qe(e);if(t?.startsWith('@"'))return t;let s=Ne(e),n=s===-1?0:s+1;return e[n]==="@"?e.slice(n):null}extractHashPrefix(e){let t=qe(e);if(t?.startsWith('#"'))return t;let s=Ne(e),n=s===-1?0:s+1;return e[n]==="#"?e.slice(n):null}extractPathPrefix(e,t=false){let s=qe(e);if(s)return s;let n=Ne(e),r=n===-1?e:e.slice(n+1);return t||r.includes("/")||r.startsWith(".")||r.startsWith("~/")||r===""&&e.endsWith(" ")?r:null}expandHomePath(e){if(e.startsWith("~/")){let t=pe.join(lt.homedir(),e.slice(2));return e.endsWith("/")&&!t.endsWith("/")?`${t}/`:t}else if(e==="~")return lt.homedir();return e}resolveScopedFuzzyQuery(e){let t=re(e),s=t.lastIndexOf("/");if(s===-1)return null;let n=t.slice(0,s+1),r=t.slice(s+1),o;n.startsWith("~/")?o=this.expandHomePath(n):n.startsWith("/")?o=n:o=pe.join(this.basePath,n);try{if(!ie.statSync(o).isDirectory())return null}catch{return null}return {baseDir:o,query:r,displayBase:n}}scopedPathForDisplay(e,t){let s=re(t);return e==="/"?`/${s}`:`${re(e)}${s}`}getFileSuggestions(e){try{let t,s,{rawPrefix:n,isAtPrefix:r,isQuotedPrefix:o}=wt(e),a=n;if(a.startsWith("~")&&(a=this.expandHomePath(a)),n===""||n==="./"||n==="../"||n==="~"||n==="~/"||n==="/"||r&&n==="")n.startsWith("~")||a.startsWith("/")?t=a:t=pe.join(this.basePath,a),s="";else if(n.endsWith("/"))n.startsWith("~")||a.startsWith("/")?t=a:t=pe.join(this.basePath,a),s="";else {let h=pe.dirname(a),f=pe.basename(a);n.startsWith("~")||a.startsWith("/")?t=h:t=pe.join(this.basePath,h),s=f;}let c=ie.readdirSync(t,{withFileTypes:!0}),d=[];for(let h of c){if(!h.name.toLowerCase().startsWith(s.toLowerCase()))continue;let f=h.isDirectory();if(!f&&h.isSymbolicLink())try{let x=pe.join(t,h.name);f=ie.statSync(x).isDirectory();}catch{}let m,g=h.name,p=n;if(p.endsWith("/"))m=p+g;else if(p.includes("/")||p.includes("\\"))if(p.startsWith("~/")){let x=p.slice(2),I=pe.dirname(x);m=`~/${I==="."?g:pe.join(I,g)}`;}else if(p.startsWith("/")){let x=pe.dirname(p);x==="/"?m=`/${g}`:m=`${x}/${g}`;}else m=pe.join(pe.dirname(p),g),p.startsWith("./")&&!m.startsWith("./")&&(m=`./${m}`);else p.startsWith("~")?m=`~/${g}`:m=g;m=re(m);let b=f?`${m}/`:m,y=St(b,{isDirectory:f,isAtPrefix:r,isQuotedPrefix:o});d.push({value:y,label:g+(f?"/":"")});}return d.sort((h,f)=>{let m=h.value.endsWith("/"),g=f.value.endsWith("/");return m&&!g?-1:!m&&g?1:h.label.localeCompare(f.label)}),d}catch{return []}}scoreEntry(e,t,s){let r=pe.basename(e).toLowerCase(),o=t.toLowerCase(),a=0;return r===o?a=100:r.startsWith(o)?a=80:r.includes(o)?a=50:e.toLowerCase().includes(o)&&(a=30),s&&a>0&&(a+=10),a}async getFuzzyFileSuggestions(e,t){if(!this.fdPath||t.signal.aborted)return [];try{let s=this.resolveScopedFuzzyQuery(e),n=s?.baseDir??this.basePath,r=s?.query??e,o=await gs(n,this.fdPath,r,100,t.signal);if(t.signal.aborted)return [];let a=o.map(d=>({...d,score:r?this.scoreEntry(d.path,r,d.isDirectory):1})).filter(d=>d.score>0);a.sort((d,h)=>h.score-d.score);let l=a.slice(0,20),c=[];for(let{path:d,isDirectory:h}of l){let f=h?d.slice(0,-1):d,m=s?this.scopedPathForDisplay(s.displayBase,f):f,g=pe.basename(f),p=h?`${m}/`:m,b=St(p,{isDirectory:h,isAtPrefix:!0,isQuotedPrefix:t.isQuotedPrefix});c.push({value:b,label:g+(h?"/":""),description:m});}return c}catch{return []}}shouldTriggerFileCompletion(e,t,s){let r=(e[t]||"").slice(0,s);return !(r.trim().startsWith("/")&&!r.trim().includes(" "))}};var J=new Intl.Segmenter(void 0,{granularity:"grapheme"});function Ae(){return J}function bs(i){let e=i.codePointAt(0);return e>=126976&&e<=130047||e>=8960&&e<=9215||e>=9728&&e<=10175||e>=11088&&e<=11093||i.includes("\uFE0F")||i.length>2}var xs=new RegExp("^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Mark}|\\p{Surrogate})+$","v"),vs=new RegExp("^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Mark}\\p{Surrogate}]+","v"),Cs=new RegExp("^\\p{RGI_Emoji}$","v"),ys=512,be=new Map;function Ye(i){for(let e=0;e<i.length;e++){let t=i.charCodeAt(e);if(t<32||t>126)return false}return true}function Ls(i,e){if(e<=0||i.length===0)return {text:"",width:0};if(Ye(i)){let l=i.slice(0,e);return {text:l,width:l.length}}let t=i.includes("\x1B"),s=i.includes(" ");if(!t&&!s){let l="",c=0;for(let{segment:d}of J.segment(i)){let h=oe(d);if(c+h>e)break;l+=d,c+=h;}return {text:l,width:c}}let n="",r=0,o=0,a="";for(;o<i.length;){let l=N(i,o);if(l){a+=l.code,o+=l.length;continue}if(i[o]===" "){if(r+3>e)break;a&&(n+=a,a=""),n+=" ",r+=3,o++;continue}let c=o;for(;c<i.length&&i[c]!==" "&&!N(i,c);)c++;for(let{segment:d}of J.segment(i.slice(o,c))){let h=oe(d);if(r+h>e)return {text:n,width:r};a&&(n+=a,a=""),n+=d,r+=h;}o=c;}return {text:n,width:r}}function je(i,e,t,s,n,r){let o="\x1B[0m",a=e+s,l;return t.length>0?l=`${i}${o}${t}${o}`:l=`${i}${o}`,r?l+" ".repeat(Math.max(0,n-a)):l}function oe(i){if(xs.test(i))return 0;if(bs(i)&&Cs.test(i))return 2;let t=i.replace(vs,"").codePointAt(0);if(t===void 0)return 0;if(t>=127462&&t<=127487)return 2;let s=getEastAsianWidth.eastAsianWidth(t);if(i.length>1)for(let n of i.slice(1)){let r=n.codePointAt(0);r>=65280&&r<=65519?s+=getEastAsianWidth.eastAsianWidth(r):(r===3635||r===3763)&&(s+=1);}return s}function S(i){if(i.length===0)return 0;if(Ye(i))return i.length;let e=be.get(i);if(e!==void 0)return e;let t=i;if(i.includes(" ")&&(t=t.replace(/\t/g," ")),t.includes("\x1B")){let n="",r=0;for(;r<t.length;){let o=N(t,r);if(o){r+=o.length;continue}n+=t[r],r++;}t=n;}let s=0;for(let{segment:n}of J.segment(t))s+=oe(n);if(be.size>=ys){let n=be.keys().next().value;n!==void 0&&be.delete(n);}return be.set(i,s),s}var Is=/[\u0e33\u0eb3]/,ws=/[\u0e33\u0eb3]/g;function At(i){return Is.test(i)?i.replace(ws,e=>e==="\u0E33"?"\u0E4D\u0E32":"\u0ECD\u0EB2"):i}function N(i,e){if(e>=i.length||i[e]!=="\x1B")return null;let t=i[e+1];if(t==="["){let s=e+2;for(;s<i.length&&!/[mGKHJ]/.test(i[s]);)s++;return s<i.length?{code:i.substring(e,s+1),length:s+1-e}:null}if(t==="]"){let s=e+2;for(;s<i.length;){if(i[s]==="\x07")return {code:i.substring(e,s+1),length:s+1-e};if(i[s]==="\x1B"&&i[s+1]==="\\")return {code:i.substring(e,s+2),length:s+2-e};s++;}return null}if(t==="_"){let s=e+2;for(;s<i.length;){if(i[s]==="\x07")return {code:i.substring(e,s+1),length:s+1-e};if(i[s]==="\x1B"&&i[s+1]==="\\")return {code:i.substring(e,s+2),length:s+2-e};s++;}return null}return null}function Ss(i){if(!i.startsWith("\x1B]8;"))return;let e=i.endsWith("\x07")?"\x07":"\x1B\\",t=i.slice(4,e==="\x07"?-1:-2),s=t.indexOf(";");if(s===-1)return;let n=t.slice(0,s),r=t.slice(s+1);return r?{params:n,url:r,terminator:e}:null}function ks(i){return `\x1B]8;${i.params};${i.url}${i.terminator}`}function Ts(i){return `\x1B]8;;${i}`}var xe=class{constructor(){u(this,"bold",false);u(this,"dim",false);u(this,"italic",false);u(this,"underline",false);u(this,"blink",false);u(this,"inverse",false);u(this,"hidden",false);u(this,"strikethrough",false);u(this,"fgColor",null);u(this,"bgColor",null);u(this,"activeHyperlink",null);}process(e){let t=Ss(e);if(t!==void 0){this.activeHyperlink=t;return}if(!e.endsWith("m"))return;let s=e.match(/\x1b\[([\d;]*)m/);if(!s)return;let n=s[1];if(n===void 0||n===""||n==="0"){this.reset();return}let r=n.split(";"),o=0;for(;o<r.length;){let a=r[o];if(a===void 0)break;let l=Number.parseInt(a,10);if(l===38||l===48){if(r[o+1]==="5"&&r[o+2]!==void 0){let c=`${r[o]};${r[o+1]};${r[o+2]}`;l===38?this.fgColor=c:this.bgColor=c,o+=3;continue}else if(r[o+1]==="2"&&r[o+4]!==void 0){let c=`${r[o]};${r[o+1]};${r[o+2]};${r[o+3]};${r[o+4]}`;l===38?this.fgColor=c:this.bgColor=c,o+=5;continue}}switch(l){case 0:this.reset();break;case 1:this.bold=true;break;case 2:this.dim=true;break;case 3:this.italic=true;break;case 4:this.underline=true;break;case 5:this.blink=true;break;case 7:this.inverse=true;break;case 8:this.hidden=true;break;case 9:this.strikethrough=true;break;case 21:this.bold=false;break;case 22:this.bold=false,this.dim=false;break;case 23:this.italic=false;break;case 24:this.underline=false;break;case 25:this.blink=false;break;case 27:this.inverse=false;break;case 28:this.hidden=false;break;case 29:this.strikethrough=false;break;case 39:this.fgColor=null;break;case 49:this.bgColor=null;break;default:l>=30&&l<=37||l>=90&&l<=97?this.fgColor=String(l):(l>=40&&l<=47||l>=100&&l<=107)&&(this.bgColor=String(l));break}o++;}}reset(){this.bold=false,this.dim=false,this.italic=false,this.underline=false,this.blink=false,this.inverse=false,this.hidden=false,this.strikethrough=false,this.fgColor=null,this.bgColor=null;}clear(){this.reset(),this.activeHyperlink=null;}getActiveCodes(){let e=[];this.bold&&e.push("1"),this.dim&&e.push("2"),this.italic&&e.push("3"),this.underline&&e.push("4"),this.blink&&e.push("5"),this.inverse&&e.push("7"),this.hidden&&e.push("8"),this.strikethrough&&e.push("9"),this.fgColor&&e.push(this.fgColor),this.bgColor&&e.push(this.bgColor);let t=e.length>0?`\x1B[${e.join(";")}m`:"";return this.activeHyperlink&&(t+=ks(this.activeHyperlink)),t}hasActiveCodes(){return this.bold||this.dim||this.italic||this.underline||this.blink||this.inverse||this.hidden||this.strikethrough||this.fgColor!==null||this.bgColor!==null||this.activeHyperlink!==null}getLineEndReset(){let e="";return this.underline&&(e+="\x1B[24m"),this.activeHyperlink&&(e+=Ts(this.activeHyperlink.terminator)),e}};function Pt(i,e){let t=0;for(;t<i.length;){let s=N(i,t);s?(e.process(s.code),t+=s.length):t++;}}function As(i){let e=[],t="",s="",n=false,r=0;for(;r<i.length;){let o=N(i,r);if(o){s+=o.code,r+=o.length;continue}let a=i[r],l=a===" ";l!==n&&t&&(e.push(t),t=""),s&&(t+=s,s=""),n=l,t+=a,r++;}return s&&(t+=s),t&&e.push(t),e}function Y(i,e){if(!i)return [""];let t=i.split(`
|
|
3
|
+
`),s=[],n=new xe;for(let r of t){let o=s.length>0?n.getActiveCodes():"";s.push(...Ps(o+r,e)),Pt(r,n);}return s.length>0?s:[""]}function Ps(i,e){if(!i)return [""];if(S(i)<=e)return [i];let s=[],n=new xe,r=As(i),o="",a=0;for(let l of r){let c=S(l),d=l.trim()==="";if(c>e&&!d){if(o){let g=n.getLineEndReset();g&&(o+=g),s.push(o),o="",a=0;}let f=Rs(l,e,n);s.push(...f.slice(0,-1)),o=f[f.length-1]??"",a=S(o);continue}if(a+c>e&&a>0){let f=o.trimEnd(),m=n.getLineEndReset();m&&(f+=m),s.push(f),d?(o=n.getActiveCodes(),a=0):(o=n.getActiveCodes()+l,a=c);}else o+=l,a+=c;Pt(l,n);}return o&&s.push(o),s.length>0?s.map(l=>l.trimEnd()):[""]}var Ms=/[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;function V(i){return /\s/.test(i)}function U(i){return Ms.test(i)}function Rs(i,e,t){let s=[],n=t.getActiveCodes(),r=0,o=0,a=[];for(;o<i.length;){let l=N(i,o);if(l)a.push({type:"ansi",value:l.code}),o+=l.length;else {let c=o;for(;c<i.length&&!N(i,c);)c++;let d=i.slice(o,c);for(let h of J.segment(d))a.push({type:"grapheme",value:h.segment});o=c;}}for(let l of a){if(l.type==="ansi"){n+=l.value,t.process(l.value);continue}let c=l.value;if(!c)continue;let d=S(c);if(r+d>e){let h=t.getLineEndReset();h&&(n+=h),s.push(n),n=t.getActiveCodes(),r=0;}n+=c,r+=d;}return n&&s.push(n),s.length>0?s:[""]}function te(i,e,t){let s=S(i),n=Math.max(0,e-s),r=" ".repeat(n),o=i+r;return t(o)}function _(i,e,t="...",s=false){if(e<=0)return "";if(i.length===0)return s?" ".repeat(e):"";let n=S(t);if(n>=e){let p=S(i);if(p<=e)return s?i+" ".repeat(e-p):i;let b=Ls(t,e);return b.width===0?s?" ".repeat(e):"":je("",0,b.text,b.width,e,s)}if(Ye(i)){if(i.length<=e)return s?i+" ".repeat(e-i.length):i;let p=e-n;return je(i.slice(0,p),p,t,n,e,s)}let r=e-n,o="",a="",l=0,c=0,d=true,h=false,f=false,m=i.includes("\x1B"),g=i.includes(" ");if(!m&&!g){for(let{segment:p}of J.segment(i)){let b=oe(p);if(d&&c+b<=r?(o+=p,c+=b):d=false,l+=b,l>e){h=true;break}}f=!h;}else {let p=0;for(;p<i.length;){let b=N(i,p);if(b){a+=b.code,p+=b.length;continue}if(i[p]===" "){if(d&&c+3<=r?(a&&(o+=a,a=""),o+=" ",c+=3):(d=false,a=""),l+=3,l>e){h=true;break}p++;continue}let y=p;for(;y<i.length&&i[y]!==" "&&!N(i,y);)y++;for(let{segment:x}of J.segment(i.slice(p,y))){let I=oe(x);if(d&&c+I<=r?(a&&(o+=a,a=""),o+=x,c+=I):(d=false,a=""),l+=I,l>e){h=true;break}}if(h)break;p=y;}f=p>=i.length;}return !h&&f?s?i+" ".repeat(Math.max(0,e-l)):i:je(o,c,t,n,e,s)}function he(i,e,t,s=false){return Xe(i,e,t,s).text}function Xe(i,e,t,s=false){if(t<=0)return {text:"",width:0};let n=e+t,r="",o=0,a=0,l=0,c="";for(;l<i.length;){let d=N(i,l);if(d){a>=e&&a<n?r+=d.code:a<e&&(c+=d.code),l+=d.length;continue}let h=l;for(;h<i.length&&!N(i,h);)h++;for(let{segment:f}of J.segment(i.slice(l,h))){let m=oe(f),g=a>=e&&a<n,p=!s||a+m<=n;if(g&&p&&(c&&(r+=c,c=""),r+=f,o+=m),a+=m,a>=n)break}if(l=h,a>=n)break}return {text:r,width:o}}var Ge=new xe;function Mt(i,e,t,s,n=false){let r="",o=0,a="",l=0,c=0,d=0,h="",f=false,m=t+s;for(Ge.clear();d<i.length;){let g=N(i,d);if(g){Ge.process(g.code),c<e?h+=g.code:c>=t&&c<m&&f&&(a+=g.code),d+=g.length;continue}let p=d;for(;p<i.length&&!N(i,p);)p++;for(let{segment:b}of J.segment(i.slice(d,p))){let y=oe(b);if(c<e?(h&&(r+=h,h=""),r+=b,o+=y):c>=t&&c<m&&(!n||c+y<=m)&&(f||(a+=Ge.getActiveCodes(),f=true),a+=b,l+=y),c+=y,s<=0?c>=e:c>=m)break}if(d=p,s<=0?c>=e:c>=m)break}return {before:r,beforeWidth:o,after:a,afterWidth:l}}var Qe=class{constructor(e=1,t=1,s){u(this,"children",[]);u(this,"paddingX");u(this,"paddingY");u(this,"bgFn");u(this,"cache");this.paddingX=e,this.paddingY=t,this.bgFn=s;}addChild(e){this.children.push(e),this.invalidateCache();}removeChild(e){let t=this.children.indexOf(e);t!==-1&&(this.children.splice(t,1),this.invalidateCache());}clear(){this.children=[],this.invalidateCache();}setBgFn(e){this.bgFn=e;}invalidateCache(){this.cache=void 0;}matchCache(e,t,s){let n=this.cache;return !!n&&n.width===e&&n.bgSample===s&&n.childLines.length===t.length&&n.childLines.every((r,o)=>r===t[o])}invalidate(){this.invalidateCache();for(let e of this.children)e.invalidate?.();}render(e){if(this.children.length===0)return [];let t=Math.max(1,e-this.paddingX*2),s=" ".repeat(this.paddingX),n=[];for(let a of this.children){let l=a.render(t);for(let c of l)n.push(s+c);}if(n.length===0)return [];let r=this.bgFn?this.bgFn("test"):void 0;if(this.matchCache(e,n,r))return this.cache.lines;let o=[];for(let a=0;a<this.paddingY;a++)o.push(this.applyBg("",e));for(let a of n)o.push(this.applyBg(a,e));for(let a=0;a<this.paddingY;a++)o.push(this.applyBg("",e));return this.cache={childLines:n,width:e,bgSample:r,lines:o},o}applyBg(e,t){let s=S(e),n=Math.max(0,t-s),r=e+" ".repeat(n);return this.bgFn?te(r,t,this.bgFn):r}};var F=false;function Ce(i){F=i;}function Ks(){return F}var $s={escape:"escape",esc:"esc",enter:"enter",return:"return",tab:"tab",space:"space",backspace:"backspace",delete:"delete",insert:"insert",clear:"clear",home:"home",end:"end",pageUp:"pageUp",pageDown:"pageDown",up:"up",down:"down",left:"left",right:"right",f1:"f1",f2:"f2",f3:"f3",f4:"f4",f5:"f5",f6:"f6",f7:"f7",f8:"f8",f9:"f9",f10:"f10",f11:"f11",f12:"f12",backtick:"`",hyphen:"-",equals:"=",leftbracket:"[",rightbracket:"]",backslash:"\\",semicolon:";",quote:"'",comma:",",period:".",slash:"/",exclamation:"!",at:"@",hash:"#",dollar:"$",percent:"%",caret:"^",ampersand:"&",asterisk:"*",leftparen:"(",rightparen:")",underscore:"_",plus:"+",pipe:"|",tilde:"~",leftbrace:"{",rightbrace:"}",colon:":",lessthan:"<",greaterthan:">",question:"?",ctrl:i=>`ctrl+${i}`,shift:i=>`shift+${i}`,alt:i=>`alt+${i}`,super:i=>`super+${i}`,ctrlShift:i=>`ctrl+shift+${i}`,shiftCtrl:i=>`shift+ctrl+${i}`,ctrlAlt:i=>`ctrl+alt+${i}`,altCtrl:i=>`alt+ctrl+${i}`,shiftAlt:i=>`shift+alt+${i}`,altShift:i=>`alt+shift+${i}`,ctrlSuper:i=>`ctrl+super+${i}`,superCtrl:i=>`super+ctrl+${i}`,shiftSuper:i=>`shift+super+${i}`,superShift:i=>`super+shift+${i}`,altSuper:i=>`alt+super+${i}`,superAlt:i=>`super+alt+${i}`,ctrlShiftAlt:i=>`ctrl+shift+alt+${i}`,ctrlShiftSuper:i=>`ctrl+shift+super+${i}`},Ke=new Set(["`","-","=","[","]","\\",";","'",",",".","/","!","@","#","$","%","^","&","*","(",")","_","+","|","~","{","}",":","<",">","?"]),C={shift:1,alt:2,ctrl:4,super:8},P={escape:27,tab:9,enter:13,space:32,backspace:127,kpEnter:57414},B={up:-1,down:-2,right:-3,left:-4},R={delete:-10,insert:-11,pageUp:-12,pageDown:-13,home:-14,end:-15},Es=new Map([[57399,48],[57400,49],[57401,50],[57402,51],[57403,52],[57404,53],[57405,54],[57406,55],[57407,56],[57408,57],[57409,46],[57410,47],[57411,42],[57412,45],[57413,43],[57415,61],[57416,44],[57417,B.left],[57418,B.right],[57419,B.up],[57420,B.down],[57421,R.pageUp],[57422,R.pageDown],[57423,R.home],[57424,R.end],[57425,R.insert],[57426,R.delete]]);function $e(i){return Es.get(i)??i}function ve(i,e){return (e&-193&C.shift)!==0&&i>=65&&i<=90?i+32:i}var z={up:["\x1B[A","\x1BOA"],down:["\x1B[B","\x1BOB"],right:["\x1B[C","\x1BOC"],left:["\x1B[D","\x1BOD"],home:["\x1B[H","\x1BOH","\x1B[1~","\x1B[7~"],end:["\x1B[F","\x1BOF","\x1B[4~","\x1B[8~"],insert:["\x1B[2~"],delete:["\x1B[3~"],pageUp:["\x1B[5~","\x1B[[5~"],pageDown:["\x1B[6~","\x1B[[6~"],clear:["\x1B[E","\x1BOE"],f1:["\x1BOP","\x1B[11~","\x1B[[A"],f2:["\x1BOQ","\x1B[12~","\x1B[[B"],f3:["\x1BOR","\x1B[13~","\x1B[[C"],f4:["\x1BOS","\x1B[14~","\x1B[[D"],f5:["\x1B[15~","\x1B[[E"],f6:["\x1B[17~"],f7:["\x1B[18~"],f8:["\x1B[19~"],f9:["\x1B[20~"],f10:["\x1B[21~"],f11:["\x1B[23~"],f12:["\x1B[24~"]},Ws={up:["\x1B[a"],down:["\x1B[b"],right:["\x1B[c"],left:["\x1B[d"],clear:["\x1B[e"],insert:["\x1B[2$"],delete:["\x1B[3$"],pageUp:["\x1B[5$"],pageDown:["\x1B[6$"],home:["\x1B[7$"],end:["\x1B[8$"]},Os={up:["\x1BOa"],down:["\x1BOb"],right:["\x1BOc"],left:["\x1BOd"],clear:["\x1BOe"],insert:["\x1B[2^"],delete:["\x1B[3^"],pageUp:["\x1B[5^"],pageDown:["\x1B[6^"],home:["\x1B[7^"],end:["\x1B[8^"]},Bs={"\x1BOA":"up","\x1BOB":"down","\x1BOC":"right","\x1BOD":"left","\x1BOH":"home","\x1BOF":"end","\x1B[E":"clear","\x1BOE":"clear","\x1BOe":"ctrl+clear","\x1B[e":"shift+clear","\x1B[2~":"insert","\x1B[2$":"shift+insert","\x1B[2^":"ctrl+insert","\x1B[3$":"shift+delete","\x1B[3^":"ctrl+delete","\x1B[[5~":"pageUp","\x1B[[6~":"pageDown","\x1B[a":"shift+up","\x1B[b":"shift+down","\x1B[c":"shift+right","\x1B[d":"shift+left","\x1BOa":"ctrl+up","\x1BOb":"ctrl+down","\x1BOc":"ctrl+right","\x1BOd":"ctrl+left","\x1B[5$":"shift+pageUp","\x1B[6$":"shift+pageDown","\x1B[7$":"shift+home","\x1B[8$":"shift+end","\x1B[5^":"ctrl+pageUp","\x1B[6^":"ctrl+pageDown","\x1B[7^":"ctrl+home","\x1B[8^":"ctrl+end","\x1BOP":"f1","\x1BOQ":"f2","\x1BOR":"f3","\x1BOS":"f4","\x1B[11~":"f1","\x1B[12~":"f2","\x1B[13~":"f3","\x1B[14~":"f4","\x1B[[A":"f1","\x1B[[B":"f2","\x1B[[C":"f3","\x1B[[D":"f4","\x1B[[E":"f5","\x1B[15~":"f5","\x1B[17~":"f6","\x1B[18~":"f7","\x1B[19~":"f8","\x1B[20~":"f9","\x1B[21~":"f10","\x1B[23~":"f11","\x1B[24~":"f12","\x1Bb":"alt+left","\x1Bf":"alt+right","\x1Bp":"alt+up","\x1Bn":"alt+down"},H=(i,e)=>e.includes(i),q=(i,e,t)=>t===C.shift?H(i,Ws[e]):t===C.ctrl?H(i,Os[e]):false;function Je(i){return i.includes("\x1B[200~")?false:!!(i.includes(":3u")||i.includes(":3~")||i.includes(":3A")||i.includes(":3B")||i.includes(":3C")||i.includes(":3D")||i.includes(":3H")||i.includes(":3F"))}function Ds(i){return i.includes("\x1B[200~")?false:!!(i.includes(":2u")||i.includes(":2~")||i.includes(":2A")||i.includes(":2B")||i.includes(":2C")||i.includes(":2D")||i.includes(":2H")||i.includes(":2F"))}function Me(i){if(!i)return "press";let e=parseInt(i,10);return e===2?"repeat":e===3?"release":"press"}function Et(i){let e=i.match(/^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/);if(e){let r=parseInt(e[1],10),o=e[2]&&e[2].length>0?parseInt(e[2],10):void 0,a=e[3]?parseInt(e[3],10):void 0,l=e[4]?parseInt(e[4],10):1,c=Me(e[5]);return {codepoint:r,shiftedKey:o,baseLayoutKey:a,modifier:l-1,eventType:c}}let t=i.match(/^\x1b\[1;(\d+)(?::(\d+))?([ABCD])$/);if(t){let r=parseInt(t[1],10),o=Me(t[2]),a={A:-1,B:-2,C:-3,D:-4};return {codepoint:a[t[3]],modifier:r-1,eventType:o}}let s=i.match(/^\x1b\[(\d+)(?:;(\d+))?(?::(\d+))?~$/);if(s){let r=parseInt(s[1],10),o=s[2]?parseInt(s[2],10):1,a=Me(s[3]),c={2:R.insert,3:R.delete,5:R.pageUp,6:R.pageDown,7:R.home,8:R.end}[r];if(c!==void 0)return {codepoint:c,modifier:o-1,eventType:a}}let n=i.match(/^\x1b\[1;(\d+)(?::(\d+))?([HF])$/);if(n){let r=parseInt(n[1],10),o=Me(n[2]),a=n[3]==="H"?R.home:R.end;return {codepoint:a,modifier:r-1,eventType:o}}return null}function k(i,e,t){let s=Et(i);if(!s)return false;let n=s.modifier&-193,r=t&-193;if(n!==r)return false;let o=ve($e(s.codepoint),s.modifier),a=ve($e(e),t);if(o===a)return true;if(s.baseLayoutKey!==void 0&&s.baseLayoutKey===e){let l=o,c=l>=97&&l<=122,d=Ke.has(String.fromCharCode(l));if(!c&&!d)return true}return false}function Ee(i){let e=i.match(/^\x1b\[27;(\d+);(\d+)~$/);if(!e)return null;let t=parseInt(e[1],10);return {codepoint:parseInt(e[2],10),modifier:t-1}}function j(i,e,t){let s=Ee(i);return s?s.codepoint===e&&s.modifier===t:false}function Wt(){return !!process.env.WT_SESSION&&!process.env.SSH_CONNECTION&&!process.env.SSH_CLIENT&&!process.env.SSH_TTY}function Rt(i,e){return i==="\x7F"?e===0:i!=="\b"?false:Wt()?e===C.ctrl:e===0}function Fs(i){let e=i.toLowerCase(),t=e.charCodeAt(0);return t>=97&&t<=122||e==="["||e==="\\"||e==="]"||e==="_"?String.fromCharCode(t&31):e==="-"?"":null}function Kt(i){return i>="0"&&i<="9"}function Re(i,e,t){if(t===0)return false;let s=Ee(i);return !s||s.modifier!==t?false:ve(s.codepoint,s.modifier)===ve(e,t)}function _s(i,e){let t=[],s=e&-193;if((s&-16)===0)return s&C.shift&&t.push("shift"),s&C.ctrl&&t.push("ctrl"),s&C.alt&&t.push("alt"),s&C.super&&t.push("super"),t.length>0?`${t.join("+")}+${i}`:i}function Vs(i){let e=i.toLowerCase().split("+"),t=e[e.length-1];return t?{key:t,ctrl:e.includes("ctrl"),shift:e.includes("shift"),alt:e.includes("alt"),super:e.includes("super")}:null}function X(i,e){let t=Vs(e);if(!t)return false;let{key:s,ctrl:n,shift:r,alt:o,super:a}=t,l=0;switch(r&&(l|=C.shift),o&&(l|=C.alt),n&&(l|=C.ctrl),a&&(l|=C.super),s){case "escape":case "esc":return l!==0?false:i==="\x1B"||k(i,P.escape,0)||j(i,P.escape,0);case "space":return !F&&(l===C.ctrl&&i==="\0"||l===C.alt&&i==="\x1B ")?true:l===0?i===" "||k(i,P.space,0)||j(i,P.space,0):k(i,P.space,l)||j(i,P.space,l);case "tab":return l===C.shift?i==="\x1B[Z"||k(i,P.tab,C.shift)||j(i,P.tab,C.shift):l===0?i===" "||k(i,P.tab,0):k(i,P.tab,l)||j(i,P.tab,l);case "enter":case "return":return l===C.shift?k(i,P.enter,C.shift)||k(i,P.kpEnter,C.shift)||j(i,P.enter,C.shift)?true:F?i==="\x1B\r"||i===`
|
|
4
|
+
`:false:l===C.alt?k(i,P.enter,C.alt)||k(i,P.kpEnter,C.alt)||j(i,P.enter,C.alt)?true:F?false:i==="\x1B\r":l===0?i==="\r"||!F&&i===`
|
|
5
|
+
`||i==="\x1BOM"||k(i,P.enter,0)||k(i,P.kpEnter,0):k(i,P.enter,l)||k(i,P.kpEnter,l)||j(i,P.enter,l);case "backspace":return l===C.alt?i==="\x1B\x7F"||i==="\x1B\b"?true:k(i,P.backspace,C.alt)||j(i,P.backspace,C.alt):l===C.ctrl?Rt(i,C.ctrl)?true:k(i,P.backspace,C.ctrl)||j(i,P.backspace,C.ctrl):l===0?Rt(i,0)||k(i,P.backspace,0)||j(i,P.backspace,0):k(i,P.backspace,l)||j(i,P.backspace,l);case "insert":return l===0?H(i,z.insert)||k(i,R.insert,0):q(i,"insert",l)?true:k(i,R.insert,l);case "delete":return l===0?H(i,z.delete)||k(i,R.delete,0):q(i,"delete",l)?true:k(i,R.delete,l);case "clear":return l===0?H(i,z.clear):q(i,"clear",l);case "home":return l===0?H(i,z.home)||k(i,R.home,0):q(i,"home",l)?true:k(i,R.home,l);case "end":return l===0?H(i,z.end)||k(i,R.end,0):q(i,"end",l)?true:k(i,R.end,l);case "pageup":return l===0?H(i,z.pageUp)||k(i,R.pageUp,0):q(i,"pageUp",l)?true:k(i,R.pageUp,l);case "pagedown":return l===0?H(i,z.pageDown)||k(i,R.pageDown,0):q(i,"pageDown",l)?true:k(i,R.pageDown,l);case "up":return l===C.alt?i==="\x1Bp"||k(i,B.up,C.alt):l===0?H(i,z.up)||k(i,B.up,0):q(i,"up",l)?true:k(i,B.up,l);case "down":return l===C.alt?i==="\x1Bn"||k(i,B.down,C.alt):l===0?H(i,z.down)||k(i,B.down,0):q(i,"down",l)?true:k(i,B.down,l);case "left":return l===C.alt?i==="\x1B[1;3D"||!F&&i==="\x1BB"||i==="\x1Bb"||k(i,B.left,C.alt):l===C.ctrl?i==="\x1B[1;5D"||q(i,"left",C.ctrl)||k(i,B.left,C.ctrl):l===0?H(i,z.left)||k(i,B.left,0):q(i,"left",l)?true:k(i,B.left,l);case "right":return l===C.alt?i==="\x1B[1;3C"||!F&&i==="\x1BF"||i==="\x1Bf"||k(i,B.right,C.alt):l===C.ctrl?i==="\x1B[1;5C"||q(i,"right",C.ctrl)||k(i,B.right,C.ctrl):l===0?H(i,z.right)||k(i,B.right,0):q(i,"right",l)?true:k(i,B.right,l);case "f1":case "f2":case "f3":case "f4":case "f5":case "f6":case "f7":case "f8":case "f9":case "f10":case "f11":case "f12":return l!==0?false:H(i,z[s])}if(s.length===1&&(s>="a"&&s<="z"||Kt(s)||Ke.has(s))){let c=s.charCodeAt(0),d=Fs(s),h=s>="a"&&s<="z",f=Kt(s);return l===C.ctrl+C.alt&&!F&&d&&i===`\x1B${d}`||l===C.alt&&!F&&(h||f)&&i===`\x1B${s}`?true:l===C.ctrl?d&&i===d?true:k(i,c,C.ctrl)||Re(i,c,C.ctrl):l===C.shift+C.ctrl?k(i,c,C.shift+C.ctrl)||Re(i,c,C.shift+C.ctrl):l===C.shift?h&&i===s.toUpperCase()?true:k(i,c,C.shift)||Re(i,c,C.shift):l!==0?k(i,c,l)||Re(i,c,l):i===s||k(i,c,0)}return false}function $t(i,e,t){let s=$e(i),n=ve(s,e),r=n>=97&&n<=122,o=n>=48&&n<=57,a=Ke.has(String.fromCharCode(n)),l=r||o||a?n:t??n,c;if(l===P.escape?c="escape":l===P.tab?c="tab":l===P.enter||l===P.kpEnter?c="enter":l===P.space?c="space":l===P.backspace?c="backspace":l===R.delete?c="delete":l===R.insert?c="insert":l===R.home?c="home":l===R.end?c="end":l===R.pageUp?c="pageUp":l===R.pageDown?c="pageDown":l===B.up?c="up":l===B.down?c="down":l===B.left?c="left":l===B.right?c="right":(l>=48&&l<=57||l>=97&&l<=122||Ke.has(String.fromCharCode(l)))&&(c=String.fromCharCode(l)),!!c)return _s(c,e)}function Us(i){let e=Et(i);if(e)return $t(e.codepoint,e.modifier,e.baseLayoutKey);let t=Ee(i);if(t)return $t(t.codepoint,t.modifier);if(F&&(i==="\x1B\r"||i===`
|
|
6
|
+
`))return "shift+enter";let s=Bs[i];if(s)return s;if(i==="\x1B")return "escape";if(i==="")return "ctrl+\\";if(i==="")return "ctrl+]";if(i==="")return "ctrl+-";if(i==="\x1B\x1B")return "ctrl+alt+[";if(i==="\x1B")return "ctrl+alt+\\";if(i==="\x1B")return "ctrl+alt+]";if(i==="\x1B")return "ctrl+alt+-";if(i===" ")return "tab";if(i==="\r"||!F&&i===`
|
|
7
|
+
`||i==="\x1BOM")return "enter";if(i==="\0")return "ctrl+space";if(i===" ")return "space";if(i==="\x7F")return "backspace";if(i==="\b")return Wt()?"ctrl+backspace":"backspace";if(i==="\x1B[Z")return "shift+tab";if(!F&&i==="\x1B\r")return "alt+enter";if(!F&&i==="\x1B ")return "alt+space";if(i==="\x1B\x7F"||i==="\x1B\b")return "alt+backspace";if(!F&&i==="\x1BB")return "alt+left";if(!F&&i==="\x1BF")return "alt+right";if(!F&&i.length===2&&i[0]==="\x1B"){let n=i.charCodeAt(1);if(n>=1&&n<=26)return `ctrl+alt+${String.fromCharCode(n+96)}`;if(n>=97&&n<=122||n>=48&&n<=57)return `alt+${String.fromCharCode(n)}`}if(i==="\x1B[A")return "up";if(i==="\x1B[B")return "down";if(i==="\x1B[C")return "right";if(i==="\x1B[D")return "left";if(i==="\x1B[H"||i==="\x1BOH")return "home";if(i==="\x1B[F"||i==="\x1BOF")return "end";if(i==="\x1B[3~")return "delete";if(i==="\x1B[5~")return "pageUp";if(i==="\x1B[6~")return "pageDown";if(i.length===1){let n=i.charCodeAt(0);if(n>=1&&n<=26)return `ctrl+${String.fromCharCode(n+96)}`;if(n>=32&&n<=126)return i}}var Hs=/^\x1b\[(\d+)(?::(\d*))?(?::(\d+))?(?:;(\d+))?(?::(\d+))?u$/;function We(i){let e=i.match(Hs);if(!e)return;let t=Number.parseInt(e[1]??"",10);if(!Number.isFinite(t))return;let s=e[2]&&e[2].length>0?Number.parseInt(e[2],10):void 0,n=e[4]?Number.parseInt(e[4],10):1,r=Number.isFinite(n)?n-1:0;if((r&-194)!==0||r&(C.alt|C.ctrl))return;let o=t;if(r&C.shift&&typeof s=="number"&&(o=s),o=$e(o),!(!Number.isFinite(o)||o<32))try{return String.fromCodePoint(o)}catch{return}}function qs(i){let e=Ee(i);if(!(!e||(e.modifier&-193&-2)!==0)&&!(!Number.isFinite(e.codepoint)||e.codepoint<32))try{return String.fromCodePoint(e.codepoint)}catch{return}}function Ze(i){return We(i)??qs(i)}var Ot={"tui.editor.cursorUp":{defaultKeys:"up",description:"Move cursor up"},"tui.editor.cursorDown":{defaultKeys:"down",description:"Move cursor down"},"tui.editor.cursorLeft":{defaultKeys:["left","ctrl+b"],description:"Move cursor left"},"tui.editor.cursorRight":{defaultKeys:["right","ctrl+f"],description:"Move cursor right"},"tui.editor.cursorWordLeft":{defaultKeys:["alt+left","ctrl+left","alt+b"],description:"Move cursor word left"},"tui.editor.cursorWordRight":{defaultKeys:["alt+right","ctrl+right","alt+f"],description:"Move cursor word right"},"tui.editor.cursorLineStart":{defaultKeys:["home","ctrl+a"],description:"Move to line start"},"tui.editor.cursorLineEnd":{defaultKeys:["end","ctrl+e"],description:"Move to line end"},"tui.editor.jumpForward":{defaultKeys:"ctrl+]",description:"Jump forward to character"},"tui.editor.jumpBackward":{defaultKeys:"ctrl+alt+]",description:"Jump backward to character"},"tui.editor.pageUp":{defaultKeys:"pageUp",description:"Page up"},"tui.editor.pageDown":{defaultKeys:"pageDown",description:"Page down"},"tui.editor.deleteCharBackward":{defaultKeys:"backspace",description:"Delete character backward"},"tui.editor.deleteCharForward":{defaultKeys:["delete","ctrl+d"],description:"Delete character forward"},"tui.editor.deleteWordBackward":{defaultKeys:["ctrl+w","alt+backspace"],description:"Delete word backward"},"tui.editor.deleteWordForward":{defaultKeys:["alt+d","alt+delete"],description:"Delete word forward"},"tui.editor.deleteToLineStart":{defaultKeys:"ctrl+u",description:"Delete to line start"},"tui.editor.deleteToLineEnd":{defaultKeys:"ctrl+k",description:"Delete to line end"},"tui.editor.yank":{defaultKeys:"ctrl+y",description:"Yank"},"tui.editor.yankPop":{defaultKeys:"alt+y",description:"Yank pop"},"tui.editor.undo":{defaultKeys:"ctrl+-",description:"Undo"},"tui.input.newLine":{defaultKeys:"shift+enter",description:"Insert newline"},"tui.input.submit":{defaultKeys:"enter",description:"Submit input"},"tui.input.tab":{defaultKeys:"tab",description:"Tab / autocomplete"},"tui.input.copy":{defaultKeys:"ctrl+c",description:"Copy selection"},"tui.select.up":{defaultKeys:"up",description:"Move selection up"},"tui.select.down":{defaultKeys:"down",description:"Move selection down"},"tui.select.pageUp":{defaultKeys:"pageUp",description:"Selection page up"},"tui.select.pageDown":{defaultKeys:"pageDown",description:"Selection page down"},"tui.select.confirm":{defaultKeys:"enter",description:"Confirm selection"},"tui.select.cancel":{defaultKeys:["escape","ctrl+c"],description:"Cancel selection"}};function et(i){if(i===void 0)return [];let e=Array.isArray(i)?i:[i],t=new Set,s=[];for(let n of e)t.has(n)||(t.add(n),s.push(n));return s}var Be=class{constructor(e,t={}){u(this,"definitions");u(this,"userBindings");u(this,"keysById",new Map);u(this,"conflicts",[]);this.definitions=e,this.userBindings=t,this.rebuild();}rebuild(){this.keysById.clear(),this.conflicts=[];let e=new Map;for(let[t,s]of Object.entries(this.userBindings))if(t in this.definitions)for(let n of et(s)){let r=e.get(n)??new Set;r.add(t),e.set(n,r);}for(let[t,s]of e)s.size>1&&this.conflicts.push({key:t,keybindings:[...s]});for(let[t,s]of Object.entries(this.definitions)){let n=this.userBindings[t],r=et(n===void 0?s.defaultKeys:n);this.keysById.set(t,r);}}matches(e,t){let s=this.keysById.get(t)??[];for(let n of s)if(X(e,n))return true;return false}getKeys(e){return [...this.keysById.get(e)??[]]}getDefinition(e){return this.definitions[e]}getConflicts(){return this.conflicts.map(e=>({...e,keybindings:[...e.keybindings]}))}setUserBindings(e){this.userBindings=e,this.rebuild();}getUserBindings(){return {...this.userBindings}}getResolvedBindings(){let e={};for(let t of Object.keys(this.definitions)){let s=this.keysById.get(t)??[];e[t]=s.length===1?s[0]:[...s];}return e}},Oe=null;function zs(i){Oe=i;}function G(){return Oe||(Oe=new Be(Ot)),Oe}var ye=class{constructor(e="",t=1,s=1,n){u(this,"text");u(this,"paddingX");u(this,"paddingY");u(this,"customBgFn");u(this,"cachedText");u(this,"cachedWidth");u(this,"cachedLines");this.text=e,this.paddingX=t,this.paddingY=s,this.customBgFn=n;}setText(e){this.text=e,this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}setCustomBgFn(e){this.customBgFn=e,this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}invalidate(){this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}render(e){if(this.cachedLines&&this.cachedText===this.text&&this.cachedWidth===e)return this.cachedLines;if(!this.text||this.text.trim()===""){let h=[];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=h,h}let t=this.text.replace(/\t/g," "),s=Math.max(1,e-this.paddingX*2),n=Y(t,s),r=" ".repeat(this.paddingX),o=" ".repeat(this.paddingX),a=[];for(let h of n){let f=r+h+o;if(this.customBgFn)a.push(te(f,e,this.customBgFn));else {let m=S(f),g=Math.max(0,e-m);a.push(f+" ".repeat(g));}}let l=" ".repeat(e),c=[];for(let h=0;h<this.paddingY;h++){let f=this.customBgFn?te(l,e,this.customBgFn):l;c.push(f);}let d=[...c,...a,...c];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=d,d.length>0?d:[""]}};var Bt=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],Dt=80,Le=class extends ye{constructor(t,s,n,r="Loading...",o){super("",1,0);u(this,"spinnerColorFn",s);u(this,"messageColorFn",n);u(this,"message",r);u(this,"frames",[...Bt]);u(this,"intervalMs",Dt);u(this,"currentFrame",0);u(this,"intervalId",null);u(this,"ui",null);u(this,"renderIndicatorVerbatim",false);this.ui=t,this.setIndicator(o);}render(t){return ["",...super.render(t)]}start(){this.updateDisplay(),this.restartAnimation();}stop(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null);}setMessage(t){this.message=t,this.updateDisplay();}setIndicator(t){this.renderIndicatorVerbatim=t!==void 0,this.frames=t?.frames!==void 0?[...t.frames]:[...Bt],this.intervalMs=t?.intervalMs&&t.intervalMs>0?t.intervalMs:Dt,this.currentFrame=0,this.start();}restartAnimation(){this.stop(),!(this.frames.length<=1)&&(this.intervalId=setInterval(()=>{this.currentFrame=(this.currentFrame+1)%this.frames.length,this.updateDisplay();},this.intervalMs));}updateDisplay(){let t=this.frames[this.currentFrame]??"",s=this.renderIndicatorVerbatim?t:this.spinnerColorFn(t),n=t.length>0?`${s} `:"";this.setText(`${n}${this.messageColorFn(this.message)}`),this.ui&&this.ui.requestRender();}};var tt=class extends Le{constructor(){super(...arguments);u(this,"abortController",new AbortController);u(this,"onAbort");}get signal(){return this.abortController.signal}get aborted(){return this.abortController.signal.aborted}handleInput(t){G().matches(t,"tui.select.cancel")&&(this.abortController.abort(),this.onAbort?.());}dispose(){this.stop();}};var fe=class{constructor(){u(this,"ring",[]);}push(e,t){if(e)if(t.accumulate&&this.ring.length>0){let s=this.ring.pop();this.ring.push(t.prepend?e+s:s+e);}else this.ring.push(e);}peek(){return this.ring.length>0?this.ring[this.ring.length-1]:void 0}rotate(){if(this.ring.length>1){let e=this.ring.pop();this.ring.unshift(e);}}get length(){return this.ring.length}};var Ie=null,Vt={widthPx:9,heightPx:18};function Ut(){return Vt}function st(i){Vt=i;}function Ht(){let i=process.env.TERM_PROGRAM?.toLowerCase()||"",e=process.env.TERM?.toLowerCase()||"",t=process.env.COLORTERM?.toLowerCase()||"";return !!process.env.TMUX||!!process.env.CMUX_WORKSPACE_ID||e.startsWith("tmux")||e.startsWith("screen")?{images:null,trueColor:t==="truecolor"||t==="24bit",hyperlinks:false}:process.env.KITTY_WINDOW_ID||i==="kitty"?{images:"kitty",trueColor:true,hyperlinks:true}:i==="ghostty"||e.includes("ghostty")||process.env.GHOSTTY_RESOURCES_DIR?{images:"kitty",trueColor:true,hyperlinks:true}:process.env.WEZTERM_PANE||i==="wezterm"?{images:"kitty",trueColor:true,hyperlinks:true}:process.env.ITERM_SESSION_ID||i==="iterm.app"?{images:"iterm2",trueColor:true,hyperlinks:true}:i==="vscode"?{images:null,trueColor:true,hyperlinks:true}:i==="alacritty"?{images:null,trueColor:true,hyperlinks:true}:{images:null,trueColor:t==="truecolor"||t==="24bit",hyperlinks:false}}function se(){return Ie||(Ie=Ht()),Ie}function js(){Ie=null;}function Gs(i){Ie=i;}var Ft="\x1B_G",_t="\x1B]1337;File=";function le(i){return i.startsWith(Ft)||i.startsWith(_t)?true:i.includes(Ft)||i.includes(_t)}function Ys(){return Math.floor(Math.random()*4294967294)+1}function Nt(i,e={}){let s=["a=T","f=100","q=2"];if(e.columns&&s.push(`c=${e.columns}`),e.rows&&s.push(`r=${e.rows}`),e.imageId&&s.push(`i=${e.imageId}`),i.length<=4096)return `\x1B_G${s.join(",")};${i}\x1B\\`;let n=[],r=0,o=true;for(;r<i.length;){let a=i.slice(r,r+4096),l=r+4096>=i.length;o?(n.push(`\x1B_G${s.join(",")},m=1;${a}\x1B\\`),o=false):l?n.push(`\x1B_Gm=0;${a}\x1B\\`):n.push(`\x1B_Gm=1;${a}\x1B\\`),r+=4096;}return n.join("")}function Xs(i){return `\x1B_Ga=d,d=I,i=${i}\x1B\\`}function Qs(){return "\x1B_Ga=d,d=A\x1B\\"}function qt(i,e={}){let t=[`inline=${e.inline!==false?1:0}`];if(e.width!==void 0&&t.push(`width=${e.width}`),e.height!==void 0&&t.push(`height=${e.height}`),e.name){let s=Buffer.from(e.name).toString("base64");t.push(`name=${s}`);}return e.preserveAspectRatio===false&&t.push("preserveAspectRatio=0"),`\x1B]1337;File=${t.join(";")}:${i}\x07`}function zt(i,e,t={widthPx:9,heightPx:18}){let n=e*t.widthPx/i.widthPx,r=i.heightPx*n,o=Math.ceil(r/t.heightPx);return Math.max(1,o)}function jt(i){try{let e=Buffer.from(i,"base64");if(e.length<24||e[0]!==137||e[1]!==80||e[2]!==78||e[3]!==71)return null;let t=e.readUInt32BE(16),s=e.readUInt32BE(20);return {widthPx:t,heightPx:s}}catch{return null}}function Gt(i){try{let e=Buffer.from(i,"base64");if(e.length<2||e[0]!==255||e[1]!==216)return null;let t=2;for(;t<e.length-9;){if(e[t]!==255){t++;continue}let s=e[t+1];if(s!==void 0&&s>=192&&s<=194){let r=e.readUInt16BE(t+5);return {widthPx:e.readUInt16BE(t+7),heightPx:r}}if(t+3>=e.length)return null;let n=e.readUInt16BE(t+2);if(n<2)return null;t+=2+n;}return null}catch{return null}}function Yt(i){try{let e=Buffer.from(i,"base64");if(e.length<10)return null;let t=e.slice(0,6).toString("ascii");if(t!=="GIF87a"&&t!=="GIF89a")return null;let s=e.readUInt16LE(6),n=e.readUInt16LE(8);return {widthPx:s,heightPx:n}}catch{return null}}function Xt(i){try{let e=Buffer.from(i,"base64");if(e.length<30)return null;let t=e.slice(0,4).toString("ascii"),s=e.slice(8,12).toString("ascii");if(t!=="RIFF"||s!=="WEBP")return null;let n=e.slice(12,16).toString("ascii");if(n==="VP8 "){if(e.length<30)return null;let r=e.readUInt16LE(26)&16383,o=e.readUInt16LE(28)&16383;return {widthPx:r,heightPx:o}}else if(n==="VP8L"){if(e.length<25)return null;let r=e.readUInt32LE(21),o=(r&16383)+1,a=(r>>14&16383)+1;return {widthPx:o,heightPx:a}}else if(n==="VP8X"){if(e.length<30)return null;let r=e[24]??0,o=e[25]??0,a=e[26]??0,l=e[27]??0,c=e[28]??0,d=e[29]??0,h=(r|o<<8|a<<16)+1,f=(l|c<<8|d<<16)+1;return {widthPx:h,heightPx:f}}return null}catch{return null}}function it(i,e){return e==="image/png"?jt(i):e==="image/jpeg"?Gt(i):e==="image/gif"?Yt(i):e==="image/webp"?Xt(i):null}function nt(i,e,t={}){let s=se();if(!s.images)return null;let n=t.maxWidthCells??80,r=zt(e,n,Ut());return s.images==="kitty"?{sequence:Nt(i,{columns:n,rows:r,imageId:t.imageId}),rows:r,imageId:t.imageId}:s.images==="iterm2"?{sequence:qt(i,{width:n,height:"auto",preserveAspectRatio:t.preserveAspectRatio??true}),rows:r}:null}function rt(i,e){return `\x1B]8;;${e}\x1B\\${i}\x1B]8;;\x1B\\`}function De(i,e,t){let s=[];return t&&s.push(t),s.push(`[${i}]`),e&&s.push(`${e.widthPx}x${e.heightPx}`),`[Image: ${s.join(" ")}]`}function at(i){return i!==null&&"focused"in i}var ce="\x1B_pi:c\x07";function Qt(i,e){if(i===void 0)return;if(typeof i=="number")return i;let t=i.match(/^(\d+(?:\.\d+)?)%$/);if(t?.[1])return Math.floor(e*parseFloat(t[1])/100)}function Js(){return !!process.env.TERMUX_VERSION}var Fe=class{constructor(){u(this,"children",[]);}addChild(e){this.children.push(e);}removeChild(e){let t=this.children.indexOf(e);t!==-1&&this.children.splice(t,1);}clear(){this.children=[];}invalidate(){for(let e of this.children)e.invalidate?.();}render(e){let t=[];for(let s of this.children){let n=s.render(e);for(let r of n)t.push(r);}return t}},ae=class ae extends Fe{constructor(t,s){super();u(this,"terminal");u(this,"previousLines",[]);u(this,"previousWidth",0);u(this,"previousHeight",0);u(this,"focusedComponent",null);u(this,"inputListeners",new Set);u(this,"onDebug");u(this,"renderRequested",false);u(this,"renderTimer");u(this,"lastRenderAt",0);u(this,"cursorRow",0);u(this,"hardwareCursorRow",0);u(this,"showHardwareCursor",process.env.PI_HARDWARE_CURSOR==="1");u(this,"clearOnShrink",process.env.PI_CLEAR_ON_SHRINK==="1");u(this,"maxLinesRendered",0);u(this,"previousViewportTop",0);u(this,"fullRedrawCount",0);u(this,"stopped",false);u(this,"focusOrderCounter",0);u(this,"overlayStack",[]);this.terminal=t,s!==void 0&&(this.showHardwareCursor=s);}get fullRedraws(){return this.fullRedrawCount}getShowHardwareCursor(){return this.showHardwareCursor}setShowHardwareCursor(t){this.showHardwareCursor!==t&&(this.showHardwareCursor=t,t||this.terminal.hideCursor(),this.requestRender());}getClearOnShrink(){return this.clearOnShrink}setClearOnShrink(t){this.clearOnShrink=t;}setFocus(t){at(this.focusedComponent)&&(this.focusedComponent.focused=false),this.focusedComponent=t,at(t)&&(t.focused=true);}showOverlay(t,s){let n={component:t,options:s,preFocus:this.focusedComponent,hidden:false,focusOrder:++this.focusOrderCounter};return this.overlayStack.push(n),!s?.nonCapturing&&this.isOverlayVisible(n)&&this.setFocus(t),this.terminal.hideCursor(),this.requestRender(),{hide:()=>{let r=this.overlayStack.indexOf(n);if(r!==-1){if(this.overlayStack.splice(r,1),this.focusedComponent===t){let o=this.getTopmostVisibleOverlay();this.setFocus(o?.component??n.preFocus);}this.overlayStack.length===0&&this.terminal.hideCursor(),this.requestRender();}},setHidden:r=>{if(n.hidden!==r){if(n.hidden=r,r){if(this.focusedComponent===t){let o=this.getTopmostVisibleOverlay();this.setFocus(o?.component??n.preFocus);}}else !s?.nonCapturing&&this.isOverlayVisible(n)&&(n.focusOrder=++this.focusOrderCounter,this.setFocus(t));this.requestRender();}},isHidden:()=>n.hidden,focus:()=>{!this.overlayStack.includes(n)||!this.isOverlayVisible(n)||(this.focusedComponent!==t&&this.setFocus(t),n.focusOrder=++this.focusOrderCounter,this.requestRender());},unfocus:()=>{if(this.focusedComponent!==t)return;let r=this.getTopmostVisibleOverlay();this.setFocus(r&&r!==n?r.component:n.preFocus),this.requestRender();},isFocused:()=>this.focusedComponent===t}}hideOverlay(){let t=this.overlayStack.pop();if(t){if(this.focusedComponent===t.component){let s=this.getTopmostVisibleOverlay();this.setFocus(s?.component??t.preFocus);}this.overlayStack.length===0&&this.terminal.hideCursor(),this.requestRender();}}hasOverlay(){return this.overlayStack.some(t=>this.isOverlayVisible(t))}isOverlayVisible(t){return t.hidden?false:t.options?.visible?t.options.visible(this.terminal.columns,this.terminal.rows):true}getTopmostVisibleOverlay(){for(let t=this.overlayStack.length-1;t>=0;t--){let s=this.overlayStack[t];if(s&&!s.options?.nonCapturing&&this.isOverlayVisible(s))return s}}invalidate(){super.invalidate();for(let t of this.overlayStack)t.component.invalidate?.();}start(){this.stopped=false,this.terminal.start(t=>this.handleInput(t),()=>this.requestRender()),this.terminal.hideCursor(),this.queryCellSize(),this.requestRender();}addInputListener(t){return this.inputListeners.add(t),()=>{this.inputListeners.delete(t);}}removeInputListener(t){this.inputListeners.delete(t);}queryCellSize(){se().images&&this.terminal.write("\x1B[16t");}stop(){if(this.stopped=true,this.renderTimer&&(clearTimeout(this.renderTimer),this.renderTimer=void 0),this.previousLines.length>0){let s=this.previousLines.length-this.hardwareCursorRow;s>0?this.terminal.write(`\x1B[${s}B`):s<0&&this.terminal.write(`\x1B[${-s}A`),this.terminal.write(`\r
|
|
8
|
+
`);}this.terminal.showCursor(),this.terminal.stop();}requestRender(t=false){if(t){this.previousLines=[],this.previousWidth=-1,this.previousHeight=-1,this.cursorRow=0,this.hardwareCursorRow=0,this.maxLinesRendered=0,this.previousViewportTop=0,this.renderTimer&&(clearTimeout(this.renderTimer),this.renderTimer=void 0),this.renderRequested=true,process.nextTick(()=>{this.stopped||!this.renderRequested||(this.renderRequested=false,this.lastRenderAt=perf_hooks.performance.now(),this.doRender());});return}this.renderRequested||(this.renderRequested=true,process.nextTick(()=>this.scheduleRender()));}scheduleRender(){if(this.stopped||this.renderTimer||!this.renderRequested)return;let t=perf_hooks.performance.now()-this.lastRenderAt,s=Math.max(0,ae.MIN_RENDER_INTERVAL_MS-t);this.renderTimer=setTimeout(()=>{this.renderTimer=void 0,!(this.stopped||!this.renderRequested)&&(this.renderRequested=false,this.lastRenderAt=perf_hooks.performance.now(),this.doRender(),this.renderRequested&&this.scheduleRender());},s);}handleInput(t){if(this.inputListeners.size>0){let n=t;for(let r of this.inputListeners){let o=r(n);if(o?.consume)return;o?.data!==void 0&&(n=o.data);}if(n.length===0)return;t=n;}if(this.consumeCellSizeResponse(t))return;if(X(t,"shift+ctrl+d")&&this.onDebug){this.onDebug();return}let s=this.overlayStack.find(n=>n.component===this.focusedComponent);if(s&&!this.isOverlayVisible(s)){let n=this.getTopmostVisibleOverlay();n?this.setFocus(n.component):this.setFocus(s.preFocus);}if(this.focusedComponent?.handleInput){if(Je(t)&&!this.focusedComponent.wantsKeyRelease)return;this.focusedComponent.handleInput(t),this.requestRender();}}consumeCellSizeResponse(t){let s=t.match(/^\x1b\[6;(\d+);(\d+)t$/);if(!s?.[1]||!s[2])return false;let n=parseInt(s[1],10),r=parseInt(s[2],10);return n<=0||r<=0||(st({widthPx:r,heightPx:n}),this.invalidate(),this.requestRender()),true}resolveOverlayLayout(t,s,n,r){let o=t??{},a=typeof o.margin=="number"?{top:o.margin,right:o.margin,bottom:o.margin,left:o.margin}:o.margin??{},l=Math.max(0,a.top??0),c=Math.max(0,a.right??0),d=Math.max(0,a.bottom??0),h=Math.max(0,a.left??0),f=Math.max(1,n-h-c),m=Math.max(1,r-l-d),g=Qt(o.width,n)??Math.min(80,f);o.minWidth!==void 0&&(g=Math.max(g,o.minWidth)),g=Math.max(1,Math.min(g,f));let p=Qt(o.maxHeight,r);p!==void 0&&(p=Math.max(1,Math.min(p,m)));let b=p!==void 0?Math.min(s,p):s,y,x;if(o.row!==void 0)if(typeof o.row=="string"){let I=o.row.match(/^(\d+(?:\.\d+)?)%$/);if(I?.[1]){let M=Math.max(0,m-b),T=parseFloat(I[1])/100;y=l+Math.floor(M*T);}else y=this.resolveAnchorRow("center",b,m,l);}else y=o.row;else {let I=o.anchor??"center";y=this.resolveAnchorRow(I,b,m,l);}if(o.col!==void 0)if(typeof o.col=="string"){let I=o.col.match(/^(\d+(?:\.\d+)?)%$/);if(I?.[1]){let M=Math.max(0,f-g),T=parseFloat(I[1])/100;x=h+Math.floor(M*T);}else x=this.resolveAnchorCol("center",g,f,h);}else x=o.col;else {let I=o.anchor??"center";x=this.resolveAnchorCol(I,g,f,h);}return o.offsetY!==void 0&&(y+=o.offsetY),o.offsetX!==void 0&&(x+=o.offsetX),y=Math.max(l,Math.min(y,r-d-b)),x=Math.max(h,Math.min(x,n-c-g)),{width:g,row:y,col:x,maxHeight:p}}resolveAnchorRow(t,s,n,r){switch(t){case "top-left":case "top-center":case "top-right":return r;case "bottom-left":case "bottom-center":case "bottom-right":return r+n-s;case "left-center":case "center":case "right-center":return r+Math.floor((n-s)/2)}}resolveAnchorCol(t,s,n,r){switch(t){case "top-left":case "left-center":case "bottom-left":return r;case "top-right":case "right-center":case "bottom-right":return r+n-s;case "top-center":case "center":case "bottom-center":return r+Math.floor((n-s)/2)}}compositeOverlays(t,s,n){if(this.overlayStack.length===0)return t;let r=[...t],o=[],a=r.length,l=this.overlayStack.filter(h=>this.isOverlayVisible(h));l.sort((h,f)=>h.focusOrder-f.focusOrder);for(let h of l){let{component:f,options:m}=h,{width:g,maxHeight:p}=this.resolveOverlayLayout(m,0,s,n),b=f.render(g);p!==void 0&&b.length>p&&(b=b.slice(0,p));let{row:y,col:x}=this.resolveOverlayLayout(m,b.length,s,n);o.push({overlayLines:b,row:y,col:x,w:g}),a=Math.max(a,y+b.length);}let c=Math.max(r.length,n,a);for(;r.length<c;)r.push("");let d=Math.max(0,c-n);for(let{overlayLines:h,row:f,col:m,w:g}of o)for(let p=0;p<h.length;p++){let b=d+f+p,y=h[p];if(b>=0&&b<r.length&&y!==void 0){let x=S(y)>g?he(y,0,g,true):y,I=r[b];I!==void 0&&(r[b]=this.compositeLineAt(I,x,m,g,s));}}return r}applyLineResets(t){let s=ae.SEGMENT_RESET;for(let n=0;n<t.length;n++){let r=t[n];r&&!le(r)&&(t[n]=At(r)+s);}return t}compositeLineAt(t,s,n,r,o){if(le(t))return t;let a=n+r,l=Mt(t,n,a,o-a,true),c=Xe(s,0,r,true),d=Math.max(0,n-l.beforeWidth),h=Math.max(0,r-c.width),f=Math.max(n,l.beforeWidth),m=Math.max(r,c.width),g=Math.max(0,o-f-m),p=Math.max(0,g-l.afterWidth),b=ae.SEGMENT_RESET,y=l.before+" ".repeat(d)+b+c.text+" ".repeat(h)+b+l.after+" ".repeat(p);return S(y)<=o?y:he(y,0,o,true)}extractCursorPosition(t,s){let n=Math.max(0,t.length-s);for(let r=t.length-1;r>=n;r--){let o=t[r];if(!o)continue;let a=o.indexOf(ce);if(a!==-1){let l=o.slice(0,a),c=S(l);return t[r]=o.slice(0,a)+o.slice(a+ce.length),{row:r,col:c}}}return null}doRender(){if(this.stopped)return;let t=this.terminal.columns,s=this.terminal.rows,n=this.previousWidth!==0&&this.previousWidth!==t,r=this.previousHeight!==0&&this.previousHeight!==s,o=this.previousHeight>0?this.previousViewportTop+this.previousHeight:s,a=r?Math.max(0,o-s):this.previousViewportTop,l=a,c=this.hardwareCursorRow,d=v=>{let L=c-a;return v-l-L},h=this.render(t);this.overlayStack.length>0&&(h=this.compositeOverlays(h,t,s));let f=this.extractCursorPosition(h,s);h=this.applyLineResets(h);let m=v=>{this.fullRedrawCount+=1;let L="\x1B[?2026h";v&&(L+="\x1B[2J\x1B[H\x1B[3J");for(let O=0;O<h.length;O++)O>0&&(L+=`\r
|
|
9
|
+
`),L+=h[O];L+="\x1B[?2026l",this.terminal.write(L),this.cursorRow=Math.max(0,h.length-1),this.hardwareCursorRow=this.cursorRow,v?this.maxLinesRendered=h.length:this.maxLinesRendered=Math.max(this.maxLinesRendered,h.length);let E=Math.max(s,h.length);this.previousViewportTop=Math.max(0,E-s),this.positionHardwareCursor(f,h.length),this.previousLines=h,this.previousWidth=t,this.previousHeight=s;},g=process.env.PI_DEBUG_REDRAW==="1",p=v=>{if(!g)return;let L=pe__namespace.join(lt__namespace.homedir(),".pi","agent","pi-debug.log"),E=`[${new Date().toISOString()}] fullRender: ${v} (prev=${this.previousLines.length}, new=${h.length}, height=${s})
|
|
10
|
+
`;ie__namespace.appendFileSync(L,E);};if(this.previousLines.length===0&&!n&&!r){p("first render"),m(false);return}if(n){p(`terminal width changed (${this.previousWidth} -> ${t})`),m(true);return}if(r&&!Js()){p(`terminal height changed (${this.previousHeight} -> ${s})`),m(true);return}if(this.clearOnShrink&&h.length<this.maxLinesRendered&&this.overlayStack.length===0){p(`clearOnShrink (maxLinesRendered=${this.maxLinesRendered})`),m(true);return}let b=-1,y=-1,x=Math.max(h.length,this.previousLines.length);for(let v=0;v<x;v++){let L=v<this.previousLines.length?this.previousLines[v]:"",E=v<h.length?h[v]:"";L!==E&&(b===-1&&(b=v),y=v);}let I=h.length>this.previousLines.length;I&&(b===-1&&(b=this.previousLines.length),y=h.length-1);let M=I&&b===this.previousLines.length&&b>0;if(b===-1){this.positionHardwareCursor(f,h.length),this.previousViewportTop=a,this.previousHeight=s;return}if(b>=h.length){if(this.previousLines.length>h.length){let v="\x1B[?2026h",L=Math.max(0,h.length-1);if(L<a){p(`deleted lines moved viewport up (${L} < ${a})`),m(true);return}let E=d(L);E>0?v+=`\x1B[${E}B`:E<0&&(v+=`\x1B[${-E}A`),v+="\r";let O=this.previousLines.length-h.length;if(O>s){p(`extraLines > height (${O} > ${s})`),m(true);return}O>0&&(v+="\x1B[1B");for(let ne=0;ne<O;ne++)v+="\r\x1B[2K",ne<O-1&&(v+="\x1B[1B");O>0&&(v+=`\x1B[${O}A`),v+="\x1B[?2026l",this.terminal.write(v),this.cursorRow=L,this.hardwareCursorRow=L;}this.positionHardwareCursor(f,h.length),this.previousLines=h,this.previousWidth=t,this.previousHeight=s,this.previousViewportTop=a;return}if(b<a){p(`firstChanged < viewportTop (${b} < ${a})`),m(true);return}let T="\x1B[?2026h",w=a+s-1,A=M?b-1:b;if(A>w){let v=Math.max(0,Math.min(s-1,c-a)),L=s-1-v;L>0&&(T+=`\x1B[${L}B`);let E=A-w;T+=`\r
|
|
11
|
+
`.repeat(E),a+=E,l+=E,c=A;}let $=d(A);$>0?T+=`\x1B[${$}B`:$<0&&(T+=`\x1B[${-$}A`),T+=M?`\r
|
|
12
|
+
`:"\r";let D=Math.min(y,h.length-1);for(let v=b;v<=D;v++){v>b&&(T+=`\r
|
|
13
|
+
`),T+="\x1B[2K";let L=h[v];if(!L)continue;if(!le(L)&&S(L)>t){let O=pe__namespace.join(lt__namespace.homedir(),".pi","agent","pi-crash.log"),ne=[`Crash at ${new Date().toISOString()}`,`Terminal width: ${t}`,`Line ${v} visible width: ${S(L)}`,"","=== All rendered lines ===",...h.map((vt,ls)=>`[${ls}] (w=${S(vt??"")}) ${vt??""}`),""].join(`
|
|
14
|
+
`);ie__namespace.mkdirSync(pe__namespace.dirname(O),{recursive:true}),ie__namespace.writeFileSync(O,ne),this.stop();let os=[`Rendered line ${v} exceeds terminal width (${S(L)} > ${t}).`,"","This is likely caused by a custom TUI component not truncating its output.","Use visibleWidth() to measure and truncateToWidth() to truncate lines.","",`Debug log written to: ${O}`].join(`
|
|
15
|
+
`);throw new Error(os)}T+=L;}let K=D;if(this.previousLines.length>h.length){if(D<h.length-1){let L=h.length-1-D;T+=`\x1B[${L}B`,K=h.length-1;}let v=this.previousLines.length-h.length;for(let L=h.length;L<this.previousLines.length;L++)T+=`\r
|
|
16
|
+
\x1B[2K`;T+=`\x1B[${v}A`;}if(T+="\x1B[?2026l",process.env.PI_TUI_DEBUG==="1"){let v="/tmp/tui";ie__namespace.mkdirSync(v,{recursive:true});let L=pe__namespace.join(v,`render-${Date.now()}-${Math.random().toString(36).slice(2)}.log`),E=[`firstChanged: ${b}`,`viewportTop: ${l}`,`cursorRow: ${this.cursorRow}`,`height: ${s}`,`lineDiff: ${$}`,`hardwareCursorRow: ${c}`,`renderEnd: ${D}`,`finalCursorRow: ${K}`,`cursorPos: ${JSON.stringify(f)}`,`newLines.length: ${h.length}`,`previousLines.length: ${this.previousLines.length}`,"","=== newLines ===",JSON.stringify(h,null,2),"","=== previousLines ===",JSON.stringify(this.previousLines,null,2),"","=== buffer ===",JSON.stringify(T)].join(`
|
|
17
|
+
`);ie__namespace.writeFileSync(L,E);}this.terminal.write(T),this.cursorRow=Math.max(0,h.length-1),this.hardwareCursorRow=K,this.maxLinesRendered=Math.max(this.maxLinesRendered,h.length),this.previousViewportTop=Math.max(a,K-s+1),this.positionHardwareCursor(f,h.length),this.previousLines=h,this.previousWidth=t,this.previousHeight=s;}positionHardwareCursor(t,s){if(!t||s<=0){this.terminal.hideCursor();return}let n=Math.max(0,Math.min(t.row,s-1)),r=Math.max(0,t.col),o=n-this.hardwareCursorRow,a="";o>0?a+=`\x1B[${o}B`:o<0&&(a+=`\x1B[${-o}A`),a+=`\x1B[${r+1}G`,a&&this.terminal.write(a),this.hardwareCursorRow=n,this.showHardwareCursor?this.terminal.showCursor():this.terminal.hideCursor();}};u(ae,"MIN_RENDER_INTERVAL_MS",16),u(ae,"SEGMENT_RESET","\x1B[0m\x1B]8;;\x07");var ct=ae;var me=class{constructor(){u(this,"stack",[]);}push(e){this.stack.push(structuredClone(e));}pop(){return this.stack.pop()}clear(){this.stack.length=0;}get length(){return this.stack.length}};var Jt=32,Zt=2,Zs=10,ei=i=>i.replace(/[\r\n]+/g," ").trim(),ti=(i,e,t)=>Math.max(e,Math.min(i,t)),we=class{constructor(e,t,s,n={}){u(this,"items",[]);u(this,"filteredItems",[]);u(this,"selectedIndex",0);u(this,"maxVisible",5);u(this,"theme");u(this,"layout");u(this,"onSelect");u(this,"onCancel");u(this,"onSelectionChange");this.items=e,this.filteredItems=e,this.maxVisible=t,this.theme=s,this.layout=n;}setFilter(e){this.filteredItems=this.items.filter(t=>t.value.toLowerCase().startsWith(e.toLowerCase())),this.selectedIndex=0;}setSelectedIndex(e){this.selectedIndex=Math.max(0,Math.min(e,this.filteredItems.length-1));}invalidate(){}render(e){let t=[];if(this.filteredItems.length===0)return t.push(this.theme.noMatch(" No matching commands")),t;let s=this.getPrimaryColumnWidth(),n=Math.max(0,Math.min(this.selectedIndex-Math.floor(this.maxVisible/2),this.filteredItems.length-this.maxVisible)),r=Math.min(n+this.maxVisible,this.filteredItems.length);for(let o=n;o<r;o++){let a=this.filteredItems[o];if(!a)continue;let l=o===this.selectedIndex,c=a.description?ei(a.description):void 0;t.push(this.renderItem(a,l,e,c,s));}if(n>0||r<this.filteredItems.length){let o=` (${this.selectedIndex+1}/${this.filteredItems.length})`;t.push(this.theme.scrollInfo(_(o,e-2,"")));}return t}handleInput(e){let t=G();if(t.matches(e,"tui.select.up"))this.selectedIndex=this.selectedIndex===0?this.filteredItems.length-1:this.selectedIndex-1,this.notifySelectionChange();else if(t.matches(e,"tui.select.down"))this.selectedIndex=this.selectedIndex===this.filteredItems.length-1?0:this.selectedIndex+1,this.notifySelectionChange();else if(t.matches(e,"tui.select.confirm")){let s=this.filteredItems[this.selectedIndex];s&&this.onSelect&&this.onSelect(s);}else t.matches(e,"tui.select.cancel")&&this.onCancel&&this.onCancel();}renderItem(e,t,s,n,r){let o=t?"\u2192 ":" ",a=S(o);if(n&&s>40){let d=Math.max(1,Math.min(r,s-a-4)),h=Math.max(1,d-Zt),f=this.truncatePrimary(e,t,h,d),m=S(f),g=" ".repeat(Math.max(1,d-m)),p=a+m+g.length,b=s-p-2;if(b>Zs){let y=_(n,b,"");if(t)return this.theme.selectedText(`${o}${f}${g}${y}`);let x=this.theme.description(g+y);return o+f+x}}let l=s-a-2,c=this.truncatePrimary(e,t,l,l);return t?this.theme.selectedText(`${o}${c}`):o+c}getPrimaryColumnWidth(){let{min:e,max:t}=this.getPrimaryColumnBounds(),s=this.filteredItems.reduce((n,r)=>Math.max(n,S(this.getDisplayValue(r))+Zt),0);return ti(s,e,t)}getPrimaryColumnBounds(){let e=this.layout.minPrimaryColumnWidth??this.layout.maxPrimaryColumnWidth??Jt,t=this.layout.maxPrimaryColumnWidth??this.layout.minPrimaryColumnWidth??Jt;return {min:Math.max(1,Math.min(e,t)),max:Math.max(1,Math.max(e,t))}}truncatePrimary(e,t,s,n){let r=this.getDisplayValue(e),o=this.layout.truncatePrimary?this.layout.truncatePrimary({text:r,maxWidth:s,columnWidth:n,item:e,isSelected:t}):_(r,s,"");return _(o,s,"")}getDisplayValue(e){return e.label||e.value}notifySelectionChange(){let e=this.filteredItems[this.selectedIndex];e&&this.onSelectionChange&&this.onSelectionChange(e);}getSelectedItem(){return this.filteredItems[this.selectedIndex]||null}};var _e=Ae(),si=/\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g,ii=/^\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]$/;function Q(i){return i.length>=10&&ii.test(i)}function ni(i,e){if(e.size===0||!i.includes("[paste #"))return _e.segment(i);let t=[];for(let o of i.matchAll(si)){let a=Number.parseInt(o[1],10);e.has(a)&&t.push({start:o.index,end:o.index+o[0].length});}if(t.length===0)return _e.segment(i);let s=_e.segment(i),n=[],r=0;for(let o of s){for(;r<t.length&&t[r].end<=o.index;)r++;let a=r<t.length?t[r]:null;if(a&&o.index>=a.start&&o.index<a.end){if(o.index===a.start){let l=i.slice(a.start,a.end);n.push({segment:l,index:a.start,input:i});}}else n.push(o);}return n}function ut(i,e,t){if(!i||e<=0)return [{text:"",startIndex:0,endIndex:0}];if(S(i)<=e)return [{text:i,startIndex:0,endIndex:i.length}];let n=[],r=t??[..._e.segment(i)],o=0,a=0,l=-1,c=0;for(let d=0;d<r.length;d++){let h=r[d],f=h.segment,m=S(f),g=h.index,p=!Q(f)&&V(f);if(o+m>e&&(l>=0&&o-c+m<=e?(n.push({text:i.slice(a,l),startIndex:a,endIndex:l}),a=l,o-=c):a<g&&(n.push({text:i.slice(a,g),startIndex:a,endIndex:g}),a=g,o=0),l=-1),m>e){let y=ut(f,e);for(let I=0;I<y.length-1;I++){let M=y[I];n.push({text:M.text,startIndex:g+M.startIndex,endIndex:g+M.endIndex});}let x=y[y.length-1];a=g+x.startIndex,o=S(x.text),l=-1;continue}o+=m;let b=r[d+1];p&&b&&(Q(b.segment)||!V(b.segment))&&(l=b.index,c=o);}return n.push({text:i.slice(a),startIndex:a,endIndex:i.length}),n}var ri={minPrimaryColumnWidth:12,maxPrimaryColumnWidth:32},oi=20,ht=class{constructor(e,t,s={}){u(this,"state",{lines:[""],cursorLine:0,cursorCol:0});u(this,"focused",false);u(this,"tui");u(this,"theme");u(this,"paddingX",0);u(this,"lastWidth",80);u(this,"scrollOffset",0);u(this,"borderColor");u(this,"autocompleteProvider");u(this,"autocompleteList");u(this,"autocompleteState",null);u(this,"autocompletePrefix","");u(this,"autocompleteMaxVisible",5);u(this,"autocompleteAbort");u(this,"autocompleteDebounceTimer");u(this,"autocompleteRequestTask",Promise.resolve());u(this,"autocompleteStartToken",0);u(this,"autocompleteRequestId",0);u(this,"pastes",new Map);u(this,"pasteCounter",0);u(this,"pasteBuffer","");u(this,"isInPaste",false);u(this,"history",[]);u(this,"historyIndex",-1);u(this,"killRing",new fe);u(this,"lastAction",null);u(this,"jumpMode",null);u(this,"preferredVisualCol",null);u(this,"snappedFromCursorCol",null);u(this,"undoStack",new me);u(this,"onSubmit");u(this,"onChange");u(this,"disableSubmit",false);this.tui=e,this.theme=t,this.borderColor=t.borderColor;let n=s.paddingX??0;this.paddingX=Number.isFinite(n)?Math.max(0,Math.floor(n)):0;let r=s.autocompleteMaxVisible??5;this.autocompleteMaxVisible=Number.isFinite(r)?Math.max(3,Math.min(20,Math.floor(r))):5;}validPasteIds(){return new Set(this.pastes.keys())}segment(e){return ni(e,this.validPasteIds())}getPaddingX(){return this.paddingX}setPaddingX(e){let t=Number.isFinite(e)?Math.max(0,Math.floor(e)):0;this.paddingX!==t&&(this.paddingX=t,this.tui.requestRender());}getAutocompleteMaxVisible(){return this.autocompleteMaxVisible}setAutocompleteMaxVisible(e){let t=Number.isFinite(e)?Math.max(3,Math.min(20,Math.floor(e))):5;this.autocompleteMaxVisible!==t&&(this.autocompleteMaxVisible=t,this.tui.requestRender());}setAutocompleteProvider(e){this.cancelAutocomplete(),this.autocompleteProvider=e;}addToHistory(e){let t=e.trim();t&&(this.history.length>0&&this.history[0]===t||(this.history.unshift(t),this.history.length>100&&this.history.pop()));}isEditorEmpty(){return this.state.lines.length===1&&this.state.lines[0]===""}isOnFirstVisualLine(){let e=this.buildVisualLineMap(this.lastWidth);return this.findCurrentVisualLine(e)===0}isOnLastVisualLine(){let e=this.buildVisualLineMap(this.lastWidth);return this.findCurrentVisualLine(e)===e.length-1}navigateHistory(e){if(this.lastAction=null,this.history.length===0)return;let t=this.historyIndex-e;t<-1||t>=this.history.length||(this.historyIndex===-1&&t>=0&&this.pushUndoSnapshot(),this.historyIndex=t,this.historyIndex===-1?this.setTextInternal(""):this.setTextInternal(this.history[this.historyIndex]||""));}setTextInternal(e){let t=e.split(`
|
|
18
|
+
`);this.state.lines=t.length===0?[""]:t,this.state.cursorLine=this.state.lines.length-1,this.setCursorCol(this.state.lines[this.state.cursorLine]?.length||0),this.scrollOffset=0,this.onChange&&this.onChange(this.getText());}invalidate(){}render(e){let t=Math.max(0,Math.floor((e-1)/2)),s=Math.min(this.paddingX,t),n=Math.max(1,e-s*2),r=Math.max(1,n-(s?0:1));this.lastWidth=r;let o=this.borderColor("\u2500"),a=this.layoutText(r),l=this.tui.terminal.rows,c=Math.max(5,Math.floor(l*.3)),d=a.findIndex(x=>x.hasCursor);d===-1&&(d=0),d<this.scrollOffset?this.scrollOffset=d:d>=this.scrollOffset+c&&(this.scrollOffset=d-c+1);let h=Math.max(0,a.length-c);this.scrollOffset=Math.max(0,Math.min(this.scrollOffset,h));let f=a.slice(this.scrollOffset,this.scrollOffset+c),m=[],g=" ".repeat(s),p=g;if(this.scrollOffset>0){let x=`\u2500\u2500\u2500 \u2191 ${this.scrollOffset} more `,I=e-S(x);I>=0?m.push(this.borderColor(x+"\u2500".repeat(I))):m.push(this.borderColor(_(x,e)));}else m.push(o.repeat(e));let b=this.focused&&!this.autocompleteState;for(let x of f){let I=x.text,M=S(x.text),T=false;if(x.hasCursor&&x.cursorPos!==void 0){let $=I.slice(0,x.cursorPos),D=I.slice(x.cursorPos),K=b?ce:"";if(D.length>0){let L=[...this.segment(D)][0]?.segment||"",E=D.slice(L.length),O=`\x1B[7m${L}\x1B[0m`;I=$+K+O+E;}else I=$+K+"\x1B[7m \x1B[0m",M=M+1,M>n&&s>0&&(T=true);}let w=" ".repeat(Math.max(0,n-M)),A=T?p.slice(1):p;m.push(`${g}${I}${w}${A}`);}let y=a.length-(this.scrollOffset+f.length);if(y>0){let x=`\u2500\u2500\u2500 \u2193 ${y} more `,I=e-S(x);m.push(this.borderColor(x+"\u2500".repeat(Math.max(0,I))));}else m.push(o.repeat(e));if(this.autocompleteState&&this.autocompleteList){let x=this.autocompleteList.render(n);for(let I of x){let M=S(I),T=" ".repeat(Math.max(0,n-M));m.push(`${g}${I}${T}${p}`);}}return m}handleInput(e){let t=G();if(this.jumpMode!==null){if(t.matches(e,"tui.editor.jumpForward")||t.matches(e,"tui.editor.jumpBackward")){this.jumpMode=null;return}let n=Ze(e)??(e.charCodeAt(0)>=32?e:void 0);if(n!==void 0){let r=this.jumpMode;this.jumpMode=null,this.jumpToChar(n,r);return}this.jumpMode=null;}if(e.includes("\x1B[200~")&&(this.isInPaste=true,this.pasteBuffer="",e=e.replace("\x1B[200~","")),this.isInPaste){this.pasteBuffer+=e;let n=this.pasteBuffer.indexOf("\x1B[201~");if(n!==-1){let r=this.pasteBuffer.substring(0,n);r.length>0&&this.handlePaste(r),this.isInPaste=false;let o=this.pasteBuffer.substring(n+6);this.pasteBuffer="",o.length>0&&this.handleInput(o);return}return}if(t.matches(e,"tui.input.copy"))return;if(t.matches(e,"tui.editor.undo")){this.undo();return}if(this.autocompleteState&&this.autocompleteList){if(t.matches(e,"tui.select.cancel")){this.cancelAutocomplete();return}if(t.matches(e,"tui.select.up")||t.matches(e,"tui.select.down")){this.autocompleteList.handleInput(e);return}if(t.matches(e,"tui.input.tab")){let n=this.autocompleteList.getSelectedItem();if(n&&this.autocompleteProvider){this.pushUndoSnapshot(),this.lastAction=null;let r=this.autocompleteProvider.applyCompletion(this.state.lines,this.state.cursorLine,this.state.cursorCol,n,this.autocompletePrefix);this.state.lines=r.lines,this.state.cursorLine=r.cursorLine,this.setCursorCol(r.cursorCol),this.cancelAutocomplete(),this.onChange&&this.onChange(this.getText());}return}if(t.matches(e,"tui.select.confirm")){let n=this.autocompleteList.getSelectedItem();if(n&&this.autocompleteProvider){this.pushUndoSnapshot(),this.lastAction=null;let r=this.autocompleteProvider.applyCompletion(this.state.lines,this.state.cursorLine,this.state.cursorCol,n,this.autocompletePrefix);if(this.state.lines=r.lines,this.state.cursorLine=r.cursorLine,this.setCursorCol(r.cursorCol),this.autocompletePrefix.startsWith("/"))this.cancelAutocomplete();else {this.cancelAutocomplete(),this.onChange&&this.onChange(this.getText());return}}}}if(t.matches(e,"tui.input.tab")&&!this.autocompleteState){this.handleTabCompletion();return}if(t.matches(e,"tui.editor.deleteToLineEnd")){this.deleteToEndOfLine();return}if(t.matches(e,"tui.editor.deleteToLineStart")){this.deleteToStartOfLine();return}if(t.matches(e,"tui.editor.deleteWordBackward")){this.deleteWordBackwards();return}if(t.matches(e,"tui.editor.deleteWordForward")){this.deleteWordForward();return}if(t.matches(e,"tui.editor.deleteCharBackward")||X(e,"shift+backspace")){this.handleBackspace();return}if(t.matches(e,"tui.editor.deleteCharForward")||X(e,"shift+delete")){this.handleForwardDelete();return}if(t.matches(e,"tui.editor.yank")){this.yank();return}if(t.matches(e,"tui.editor.yankPop")){this.yankPop();return}if(t.matches(e,"tui.editor.cursorLineStart")){this.moveToLineStart();return}if(t.matches(e,"tui.editor.cursorLineEnd")){this.moveToLineEnd();return}if(t.matches(e,"tui.editor.cursorWordLeft")){this.moveWordBackwards();return}if(t.matches(e,"tui.editor.cursorWordRight")){this.moveWordForwards();return}if(t.matches(e,"tui.input.newLine")||e.charCodeAt(0)===10&&e.length>1||e==="\x1B\r"||e==="\x1B[13;2~"||e.length>1&&e.includes("\x1B")&&e.includes("\r")||e===`
|
|
19
|
+
`&&e.length===1){if(this.shouldSubmitOnBackslashEnter(e,t)){this.handleBackspace(),this.submitValue();return}this.addNewLine();return}if(t.matches(e,"tui.input.submit")){if(this.disableSubmit)return;let n=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol>0&&n[this.state.cursorCol-1]==="\\"){this.handleBackspace(),this.addNewLine();return}this.submitValue();return}if(t.matches(e,"tui.editor.cursorUp")){this.isEditorEmpty()?this.navigateHistory(-1):this.historyIndex>-1&&this.isOnFirstVisualLine()?this.navigateHistory(-1):this.isOnFirstVisualLine()?this.moveToLineStart():this.moveCursor(-1,0);return}if(t.matches(e,"tui.editor.cursorDown")){this.historyIndex>-1&&this.isOnLastVisualLine()?this.navigateHistory(1):this.isOnLastVisualLine()?this.moveToLineEnd():this.moveCursor(1,0);return}if(t.matches(e,"tui.editor.cursorRight")){this.moveCursor(0,1);return}if(t.matches(e,"tui.editor.cursorLeft")){this.moveCursor(0,-1);return}if(t.matches(e,"tui.editor.pageUp")){this.pageScroll(-1);return}if(t.matches(e,"tui.editor.pageDown")){this.pageScroll(1);return}if(t.matches(e,"tui.editor.jumpForward")){this.jumpMode="forward";return}if(t.matches(e,"tui.editor.jumpBackward")){this.jumpMode="backward";return}if(X(e,"shift+space")){this.insertCharacter(" ");return}let s=Ze(e);if(s!==void 0){this.insertCharacter(s);return}e.charCodeAt(0)>=32&&this.insertCharacter(e);}layoutText(e){let t=[];if(this.state.lines.length===0||this.state.lines.length===1&&this.state.lines[0]==="")return t.push({text:"",hasCursor:true,cursorPos:0}),t;for(let s=0;s<this.state.lines.length;s++){let n=this.state.lines[s]||"",r=s===this.state.cursorLine;if(S(n)<=e)r?t.push({text:n,hasCursor:true,cursorPos:this.state.cursorCol}):t.push({text:n,hasCursor:false});else {let a=ut(n,e,[...this.segment(n)]);for(let l=0;l<a.length;l++){let c=a[l];if(!c)continue;let d=this.state.cursorCol,h=l===a.length-1,f=false,m=0;r&&(h?(f=d>=c.startIndex,m=d-c.startIndex):(f=d>=c.startIndex&&d<c.endIndex,f&&(m=d-c.startIndex,m>c.text.length&&(m=c.text.length)))),f?t.push({text:c.text,hasCursor:true,cursorPos:m}):t.push({text:c.text,hasCursor:false});}}}return t}getText(){return this.state.lines.join(`
|
|
20
|
+
`)}expandPasteMarkers(e){let t=e;for(let[s,n]of this.pastes){let r=new RegExp(`\\[paste #${s}( (\\+\\d+ lines|\\d+ chars))?\\]`,"g");t=t.replace(r,()=>n);}return t}getExpandedText(){return this.expandPasteMarkers(this.state.lines.join(`
|
|
21
|
+
`))}getLines(){return [...this.state.lines]}getCursor(){return {line:this.state.cursorLine,col:this.state.cursorCol}}setText(e){this.cancelAutocomplete(),this.lastAction=null,this.historyIndex=-1;let t=this.normalizeText(e);this.getText()!==t&&this.pushUndoSnapshot(),this.setTextInternal(t);}insertTextAtCursor(e){e&&(this.cancelAutocomplete(),this.pushUndoSnapshot(),this.lastAction=null,this.historyIndex=-1,this.insertTextAtCursorInternal(e));}normalizeText(e){return e.replace(/\r\n/g,`
|
|
18
22
|
`).replace(/\r/g,`
|
|
19
|
-
`).split(`
|
|
20
|
-
`)
|
|
21
|
-
|
|
22
|
-
`)}
|
|
23
|
-
`);
|
|
24
|
-
`).replace(/\r/g,`
|
|
25
|
-
`),s=t.split(`
|
|
26
|
-
`),i=this.state.lines[this.state.cursorLine]||"",r=i.slice(0,this.state.cursorCol),o=i.slice(this.state.cursorCol);s.length===1?(this.state.lines[this.state.cursorLine]=r+t+o,this.setCursorCol(this.state.cursorCol+t.length)):(this.state.lines=[...this.state.lines.slice(0,this.state.cursorLine),r+s[0],...s.slice(1,-1),s[s.length-1]+o,...this.state.lines.slice(this.state.cursorLine+1)],this.state.cursorLine+=s.length-1,this.setCursorCol((s[s.length-1]||"").length)),this.onChange&&this.onChange(this.getText());}insertCharacter(e,t){this.historyIndex=-1,t||((F(e)||this.lastAction!=="type-word")&&this.pushUndoSnapshot(),this.lastAction="type-word");let s=this.state.lines[this.state.cursorLine]||"",i=s.slice(0,this.state.cursorCol),r=s.slice(this.state.cursorCol);if(this.state.lines[this.state.cursorLine]=i+e+r,this.setCursorCol(this.state.cursorCol+e.length),this.onChange&&this.onChange(this.getText()),this.autocompleteState)this.updateAutocomplete();else if(e==="/"&&this.isAtStartOfMessage())this.tryTriggerAutocomplete();else if(e==="@"){let l=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol),a=l[l.length-2];(l.length===1||a===" "||a===" ")&&this.tryTriggerAutocomplete();}else if(/[a-zA-Z0-9.\-_]/.test(e)){let l=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(l)?this.tryTriggerAutocomplete():l.match(/(?:^|[\s])@[^\s]*$/)&&this.tryTriggerAutocomplete();}}handlePaste(e){this.historyIndex=-1,this.lastAction=null,this.pushUndoSnapshot();let i=e.replace(/\r\n/g,`
|
|
27
|
-
`).replace(/\r/g,`
|
|
28
|
-
`).replace(/\t/g," ").split("").filter(l=>l===`
|
|
29
|
-
`||l.charCodeAt(0)>=32).join("");if(/^[/~.]/.test(i)){let l=this.state.lines[this.state.cursorLine]||"",a=this.state.cursorCol>0?l[this.state.cursorCol-1]:"";a&&/\w/.test(a)&&(i=` ${i}`);}let r=i.split(`
|
|
30
|
-
`),o=i.length;if(r.length>10||o>1e3){this.pasteCounter++;let l=this.pasteCounter;this.pastes.set(l,i);let a=r.length>10?`[paste #${l} +${r.length} lines]`:`[paste #${l} ${o} chars]`;this.insertTextAtCursorInternal(a);return}if(r.length===1){for(let l of i)this.insertCharacter(l,true);return}this.insertTextAtCursorInternal(i);}addNewLine(){this.historyIndex=-1,this.lastAction=null,this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=e.slice(0,this.state.cursorCol),s=e.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=t,this.state.lines.splice(this.state.cursorLine+1,0,s),this.state.cursorLine++,this.setCursorCol(0),this.onChange&&this.onChange(this.getText());}shouldSubmitOnBackslashEnter(e,t){if(this.disableSubmit||!G(e,"enter"))return false;let s=t.getKeys("submit");if(!(s.includes("shift+enter")||s.includes("shift+return")))return false;let r=this.state.lines[this.state.cursorLine]||"";return this.state.cursorCol>0&&r[this.state.cursorCol-1]==="\\"}submitValue(){let e=this.state.lines.join(`
|
|
31
|
-
`).trim();for(let[t,s]of this.pastes){let i=new RegExp(`\\[paste #${t}( (\\+\\d+ lines|\\d+ chars))?\\]`,"g");e=e.replace(i,s);}this.state={lines:[""],cursorLine:0,cursorCol:0},this.pastes.clear(),this.pasteCounter=0,this.historyIndex=-1,this.scrollOffset=0,this.undoStack.clear(),this.lastAction=null,this.onChange&&this.onChange(""),this.onSubmit&&this.onSubmit(e);}handleBackspace(){if(this.historyIndex=-1,this.lastAction=null,this.state.cursorCol>0){this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=e.slice(0,this.state.cursorCol),s=[...Z.segment(t)],i=s[s.length-1],r=i?i.segment.length:1,o=e.slice(0,this.state.cursorCol-r),l=e.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=o+l,this.setCursorCol(this.state.cursorCol-r);}else if(this.state.cursorLine>0){this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=this.state.lines[this.state.cursorLine-1]||"";this.state.lines[this.state.cursorLine-1]=t+e,this.state.lines.splice(this.state.cursorLine,1),this.state.cursorLine--,this.setCursorCol(t.length);}if(this.onChange&&this.onChange(this.getText()),this.autocompleteState)this.updateAutocomplete();else {let t=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(t)?this.tryTriggerAutocomplete():t.match(/(?:^|[\s])@[^\s]*$/)&&this.tryTriggerAutocomplete();}}setCursorCol(e){this.state.cursorCol=e,this.preferredVisualCol=null;}moveToVisualLine(e,t,s){let i=e[t],r=e[s];if(i&&r){let o=this.state.cursorCol-i.startCol,a=t===e.length-1||e[t+1]?.logicalLine!==i.logicalLine?i.length:Math.max(0,i.length-1),u=s===e.length-1||e[s+1]?.logicalLine!==r.logicalLine?r.length:Math.max(0,r.length-1),f=this.computeVerticalMoveColumn(o,a,u);this.state.cursorLine=r.logicalLine;let p=r.startCol+f,d=this.state.lines[r.logicalLine]||"";this.state.cursorCol=Math.min(p,d.length);}}computeVerticalMoveColumn(e,t,s){let i=this.preferredVisualCol!==null,r=e<t,o=s<e;if(!i||r)return o?(this.preferredVisualCol=e,s):(this.preferredVisualCol=null,e);let l=s<this.preferredVisualCol;if(o||l)return s;let a=this.preferredVisualCol;return this.preferredVisualCol=null,a}moveToLineStart(){this.lastAction=null,this.setCursorCol(0);}moveToLineEnd(){this.lastAction=null;let e=this.state.lines[this.state.cursorLine]||"";this.setCursorCol(e.length);}deleteToStartOfLine(){this.historyIndex=-1;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol>0){this.pushUndoSnapshot();let t=e.slice(0,this.state.cursorCol);this.killRing.push(t,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill",this.state.lines[this.state.cursorLine]=e.slice(this.state.cursorCol),this.setCursorCol(0);}else if(this.state.cursorLine>0){this.pushUndoSnapshot(),this.killRing.push(`
|
|
23
|
+
`).replace(/\t/g," ")}insertTextAtCursorInternal(e){if(!e)return;let t=this.normalizeText(e),s=t.split(`
|
|
24
|
+
`),n=this.state.lines[this.state.cursorLine]||"",r=n.slice(0,this.state.cursorCol),o=n.slice(this.state.cursorCol);s.length===1?(this.state.lines[this.state.cursorLine]=r+t+o,this.setCursorCol(this.state.cursorCol+t.length)):(this.state.lines=[...this.state.lines.slice(0,this.state.cursorLine),r+s[0],...s.slice(1,-1),s[s.length-1]+o,...this.state.lines.slice(this.state.cursorLine+1)],this.state.cursorLine+=s.length-1,this.setCursorCol((s[s.length-1]||"").length)),this.onChange&&this.onChange(this.getText());}insertCharacter(e,t){this.historyIndex=-1,t||((V(e)||this.lastAction!=="type-word")&&this.pushUndoSnapshot(),this.lastAction="type-word");let s=this.state.lines[this.state.cursorLine]||"",n=s.slice(0,this.state.cursorCol),r=s.slice(this.state.cursorCol);if(this.state.lines[this.state.cursorLine]=n+e+r,this.setCursorCol(this.state.cursorCol+e.length),this.onChange&&this.onChange(this.getText()),this.autocompleteState)this.updateAutocomplete();else if(e==="/"&&this.isAtStartOfMessage())this.tryTriggerAutocomplete();else if(e==="@"||e==="#"){let a=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol),l=a[a.length-2];(a.length===1||l===" "||l===" ")&&this.tryTriggerAutocomplete();}else if(e==="/")(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol).startsWith("#")&&this.tryTriggerAutocomplete();else if(/[a-zA-Z0-9.\-_]/.test(e)){let a=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(a)?this.tryTriggerAutocomplete():a.match(/(?:^|[\s])[@#][^\s]*$/)&&this.tryTriggerAutocomplete();}}handlePaste(e){this.cancelAutocomplete(),this.historyIndex=-1,this.lastAction=null,this.pushUndoSnapshot();let t=e.replace(/\x1b\[(\d+);5u/g,(a,l)=>{let c=Number(l);return c>=97&&c<=122?String.fromCharCode(c-96):c>=65&&c<=90?String.fromCharCode(c-64):a}),n=this.normalizeText(t).split("").filter(a=>a===`
|
|
25
|
+
`||a.charCodeAt(0)>=32).join("");if(/^[/~.]/.test(n)){let a=this.state.lines[this.state.cursorLine]||"",l=this.state.cursorCol>0?a[this.state.cursorCol-1]:"";l&&/\w/.test(l)&&(n=` ${n}`);}let r=n.split(`
|
|
26
|
+
`),o=n.length;if(r.length>10||o>1e3){this.pasteCounter++;let a=this.pasteCounter;this.pastes.set(a,n);let l=r.length>10?`[paste #${a} +${r.length} lines]`:`[paste #${a} ${o} chars]`;this.insertTextAtCursorInternal(l);return}if(r.length===1){this.insertTextAtCursorInternal(n);return}this.insertTextAtCursorInternal(n);}addNewLine(){this.cancelAutocomplete(),this.historyIndex=-1,this.lastAction=null,this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=e.slice(0,this.state.cursorCol),s=e.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=t,this.state.lines.splice(this.state.cursorLine+1,0,s),this.state.cursorLine++,this.setCursorCol(0),this.onChange&&this.onChange(this.getText());}shouldSubmitOnBackslashEnter(e,t){if(this.disableSubmit||!X(e,"enter"))return false;let s=t.getKeys("tui.input.submit");if(!(s.includes("shift+enter")||s.includes("shift+return")))return false;let r=this.state.lines[this.state.cursorLine]||"";return this.state.cursorCol>0&&r[this.state.cursorCol-1]==="\\"}submitValue(){this.cancelAutocomplete();let e=this.expandPasteMarkers(this.state.lines.join(`
|
|
27
|
+
`)).trim();this.state={lines:[""],cursorLine:0,cursorCol:0},this.pastes.clear(),this.pasteCounter=0,this.historyIndex=-1,this.scrollOffset=0,this.undoStack.clear(),this.lastAction=null,this.onChange&&this.onChange(""),this.onSubmit&&this.onSubmit(e);}handleBackspace(){if(this.historyIndex=-1,this.lastAction=null,this.state.cursorCol>0){this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=e.slice(0,this.state.cursorCol),s=[...this.segment(t)],n=s[s.length-1],r=n?n.segment.length:1,o=e.slice(0,this.state.cursorCol-r),a=e.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=o+a,this.setCursorCol(this.state.cursorCol-r);}else if(this.state.cursorLine>0){this.pushUndoSnapshot();let e=this.state.lines[this.state.cursorLine]||"",t=this.state.lines[this.state.cursorLine-1]||"";this.state.lines[this.state.cursorLine-1]=t+e,this.state.lines.splice(this.state.cursorLine,1),this.state.cursorLine--,this.setCursorCol(t.length);}if(this.onChange&&this.onChange(this.getText()),this.autocompleteState)this.updateAutocomplete();else {let t=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(t)?this.tryTriggerAutocomplete():t.match(/(?:^|[\s])[@#][^\s]*$/)&&this.tryTriggerAutocomplete();}}setCursorCol(e){this.state.cursorCol=e,this.preferredVisualCol=null,this.snappedFromCursorCol=null;}moveToVisualLine(e,t,s){let n=e[t],r=e[s];if(!(n&&r))return;let o;if(this.snappedFromCursorCol!==null){let p=this.findVisualLineAt(e,n.logicalLine,this.snappedFromCursorCol);o=this.snappedFromCursorCol-e[p].startCol;}else o=this.state.cursorCol-n.startCol;let l=t===e.length-1||e[t+1]?.logicalLine!==n.logicalLine?n.length:Math.max(0,n.length-1),d=s===e.length-1||e[s+1]?.logicalLine!==r.logicalLine?r.length:Math.max(0,r.length-1),h=this.computeVerticalMoveColumn(o,l,d);this.state.cursorLine=r.logicalLine;let f=r.startCol+h,m=this.state.lines[r.logicalLine]||"";this.state.cursorCol=Math.min(f,m.length);let g=[...this.segment(m)];for(let p of g){if(p.index>this.state.cursorCol)break;if(!(p.segment.length<=1)&&this.state.cursorCol<p.index+p.segment.length){let b=p.index<r.startCol,y=s>t;if(b&&y){let x=p.index+p.segment.length,I=s+1;for(;I<e.length&&e[I].logicalLine===r.logicalLine&&e[I].startCol<x;)I++;if(I<e.length){this.moveToVisualLine(e,t,I);return}}this.snappedFromCursorCol=this.state.cursorCol,this.state.cursorCol=p.index;return}}this.snappedFromCursorCol=null;}computeVerticalMoveColumn(e,t,s){let n=this.preferredVisualCol!==null,r=e<t,o=s<e;if(!n||r)return o?(this.preferredVisualCol=e,s):(this.preferredVisualCol=null,e);let a=s<this.preferredVisualCol;if(o||a)return s;let l=this.preferredVisualCol;return this.preferredVisualCol=null,l}moveToLineStart(){this.lastAction=null,this.setCursorCol(0);}moveToLineEnd(){this.lastAction=null;let e=this.state.lines[this.state.cursorLine]||"";this.setCursorCol(e.length);}deleteToStartOfLine(){this.historyIndex=-1;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol>0){this.pushUndoSnapshot();let t=e.slice(0,this.state.cursorCol);this.killRing.push(t,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill",this.state.lines[this.state.cursorLine]=e.slice(this.state.cursorCol),this.setCursorCol(0);}else if(this.state.cursorLine>0){this.pushUndoSnapshot(),this.killRing.push(`
|
|
32
28
|
`,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine-1]||"";this.state.lines[this.state.cursorLine-1]=t+e,this.state.lines.splice(this.state.cursorLine,1),this.state.cursorLine--,this.setCursorCol(t.length);}this.onChange&&this.onChange(this.getText());}deleteToEndOfLine(){this.historyIndex=-1;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol<e.length){this.pushUndoSnapshot();let t=e.slice(this.state.cursorCol);this.killRing.push(t,{prepend:false,accumulate:this.lastAction==="kill"}),this.lastAction="kill",this.state.lines[this.state.cursorLine]=e.slice(0,this.state.cursorCol);}else if(this.state.cursorLine<this.state.lines.length-1){this.pushUndoSnapshot(),this.killRing.push(`
|
|
33
29
|
`,{prepend:false,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine+1]||"";this.state.lines[this.state.cursorLine]=e+t,this.state.lines.splice(this.state.cursorLine+1,1);}this.onChange&&this.onChange(this.getText());}deleteWordBackwards(){this.historyIndex=-1;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol===0){if(this.state.cursorLine>0){this.pushUndoSnapshot(),this.killRing.push(`
|
|
34
|
-
`,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine-1]||"";this.state.lines[this.state.cursorLine-1]=t+e,this.state.lines.splice(this.state.cursorLine,1),this.state.cursorLine--,this.setCursorCol(t.length);}}else {this.pushUndoSnapshot();let t=this.lastAction==="kill",s=this.state.cursorCol;this.moveWordBackwards();let
|
|
35
|
-
`,{prepend:false,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine+1]||"";this.state.lines[this.state.cursorLine]=e+t,this.state.lines.splice(this.state.cursorLine+1,1);}}else {this.pushUndoSnapshot();let t=this.lastAction==="kill",s=this.state.cursorCol;this.moveWordForwards();let
|
|
36
|
-
`);if(t.length===1){let s=this.state.lines[this.state.cursorLine]||"",
|
|
37
|
-
`);if(t.length===1){let s=this.state.lines[this.state.cursorLine]||"",
|
|
38
|
-
`){this.onSubmit&&this.onSubmit(this.value);return}if(t.matches(e,"deleteCharBackward")){this.handleBackspace();return}if(t.matches(e,"deleteCharForward")){this.handleForwardDelete();return}if(t.matches(e,"deleteWordBackward")){this.deleteWordBackwards();return}if(t.matches(e,"deleteWordForward")){this.deleteWordForward();return}if(t.matches(e,"deleteToLineStart")){this.deleteToLineStart();return}if(t.matches(e,"deleteToLineEnd")){this.deleteToLineEnd();return}if(t.matches(e,"yank")){this.yank();return}if(t.matches(e,"yankPop")){this.yankPop();return}if(t.matches(e,"cursorLeft")){if(this.lastAction=null,this.cursor>0){let
|
|
39
|
-
`);for(let l of
|
|
40
|
-
`)
|
|
41
|
-
`).
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
`);for(let l of o)s.push(`${r}${this.theme.codeBlock(l)}`);}s.push(this.theme.codeBlockBorder("```"));}else {let r=this.renderInlineTokens([i]);r&&s.push(r);}return s}getLongestWordWidth(e,t){let s=e.split(/\s+/).filter(r=>r.length>0),i=0;for(let r of s)i=Math.max(i,w(r));return t===void 0?i:Math.min(i,t)}wrapCellText(e,t){return j(e,Math.max(1,t))}renderTable(e,t){let s=[],i=e.header.length;if(i===0)return s;let r=3*i+1,o=t-r;if(o<i){let x=e.raw?j(e.raw,t):[];return x.push(""),x}let l=30,a=[],h=[];for(let x=0;x<i;x++){let b=this.renderInlineTokens(e.header[x].tokens||[]);a[x]=w(b),h[x]=Math.max(1,this.getLongestWordWidth(b,l));}for(let x of e.rows)for(let b=0;b<x.length;b++){let P=this.renderInlineTokens(x[b].tokens||[]);a[b]=Math.max(a[b]||0,w(P)),h[b]=Math.max(h[b]||1,this.getLongestWordWidth(P,l));}let u=h,f=u.reduce((x,b)=>x+b,0);if(f>o){u=new Array(i).fill(1);let x=o-i;if(x>0){let b=h.reduce((S,v)=>S+Math.max(0,v-1),0),P=h.map(S=>{let v=Math.max(0,S-1);return b>0?Math.floor(v/b*x):0});for(let S=0;S<i;S++){let v=u[S];v!==void 0&&(u[S]=v+(P[S]??0));}let B=P.reduce((S,v)=>S+v,0),T=x-B;for(let S=0;T>0&&S<i;S++){let v=u[S];v!==void 0&&(u[S]=v+1),T--;}}f=u.reduce((b,P)=>b+P,0);}let p=a.reduce((x,b)=>x+b,0)+r,d;if(p<=t)d=a.map((x,b)=>Math.max(x,u[b]??0));else {let x=a.reduce((T,S,v)=>T+Math.max(0,S-(u[v]??0)),0),b=Math.max(0,o-f);d=u.map((T,S)=>{let v=a[S],k=Math.max(0,(v??0)-T),M=0;return x>0&&(M=Math.floor(k/x*b)),T+M});let P=d.reduce((T,S)=>T+S,0),B=o-P;for(;B>0;){let T=false;for(let S=0;S<i&&B>0;S++)if((d[S]??0)<(a[S]??0)){let v=d[S];v!==void 0&&(d[S]=v+1),B--,T=true;}if(!T)break}}let m=d.map(x=>"\u2500".repeat(x));s.push(`\u250C\u2500${m.join("\u2500\u252C\u2500")}\u2500\u2510`);let g=e.header.map((x,b)=>{let P=this.renderInlineTokens(x.tokens||[]);return this.wrapCellText(P,d[b]??0)}),y=Math.max(...g.map(x=>x.length));for(let x=0;x<y;x++){let b=g.map((P,B)=>{let T=P[x]||"",S=T+" ".repeat(Math.max(0,(d[B]??0)-w(T)));return this.theme.bold(S)});s.push(`\u2502 ${b.join(" \u2502 ")} \u2502`);}let C=`\u251C\u2500${d.map(x=>"\u2500".repeat(x)).join("\u2500\u253C\u2500")}\u2500\u2524`;s.push(C);for(let x=0;x<e.rows.length;x++){let P=(e.rows[x]??[]).map((T,S)=>{let v=this.renderInlineTokens(T.tokens||[]);return this.wrapCellText(v,d[S]??0)}),B=Math.max(...P.map(T=>T.length));for(let T=0;T<B;T++){let S=P.map((v,k)=>{let M=v[T]||"";return M+" ".repeat(Math.max(0,(d[k]??0)-w(M)))});s.push(`\u2502 ${S.join(" \u2502 ")} \u2502`);}x<e.rows.length-1&&s.push(C);}let A=d.map(x=>"\u2500".repeat(x));return s.push(`\u2514\u2500${A.join("\u2500\u2534\u2500")}\u2500\u2518`),s.push(""),s}};var Ye=class{constructor(e,t,s,i,r,o={}){c(this,"items");c(this,"filteredItems");c(this,"theme");c(this,"selectedIndex",0);c(this,"maxVisible");c(this,"onChange");c(this,"onCancel");c(this,"searchInput");c(this,"searchEnabled");c(this,"submenuComponent",null);c(this,"submenuItemIndex",null);this.items=e,this.filteredItems=e,this.maxVisible=t,this.theme=s,this.onChange=i,this.onCancel=r,this.searchEnabled=o.enableSearch??false,this.searchEnabled&&(this.searchInput=new be);}updateValue(e,t){let s=this.items.find(i=>i.id===e);s&&(s.currentValue=t??"");}invalidate(){this.submenuComponent?.invalidate?.();}render(e){return this.submenuComponent?this.submenuComponent.render(e):this.renderMainList(e)}renderMainList(e){let t=[];if(this.searchEnabled&&this.searchInput&&(t.push(...this.searchInput.render(e)),t.push("")),this.items.length===0)return t.push(this.theme.hint(" No settings available")),this.searchEnabled&&this.addHintLine(t,e),t;let s=this.searchEnabled?this.filteredItems:this.items;if(s.length===0)return t.push(O(this.theme.hint(" No matching settings"),e)),this.addHintLine(t,e),t;let i=Math.max(0,Math.min(this.selectedIndex-Math.floor(this.maxVisible/2),s.length-this.maxVisible)),r=Math.min(i+this.maxVisible,s.length),o=Math.min(30,Math.max(...this.items.map(a=>w(a.label))));for(let a=i;a<r;a++){let h=s[a];if(!h)continue;let u=a===this.selectedIndex,f=u?this.theme.cursor:" ",p=w(f),d=h.label+" ".repeat(Math.max(0,o-w(h.label))),m=this.theme.label(d,u),g=" ",y=p+o+w(g),L=e-y-2,C=this.theme.value(O(h.currentValue,L,""),u);t.push(O(f+m+g+C,e));}if(i>0||r<s.length){let a=` (${this.selectedIndex+1}/${s.length})`;t.push(this.theme.hint(O(a,e-2,"")));}let l=s[this.selectedIndex];if(l?.description){t.push("");let a=j(l.description,e-4);for(let h of a)t.push(this.theme.description(` ${h}`));}return this.addHintLine(t,e),t}handleInput(e){if(this.submenuComponent){this.submenuComponent.handleInput?.(e);return}let t=q(),s=this.searchEnabled?this.filteredItems:this.items;if(t.matches(e,"selectUp")){if(s.length===0)return;this.selectedIndex=this.selectedIndex===0?s.length-1:this.selectedIndex-1;}else if(t.matches(e,"selectDown")){if(s.length===0)return;this.selectedIndex=this.selectedIndex===s.length-1?0:this.selectedIndex+1;}else if(t.matches(e,"selectConfirm")||e===" ")this.activateItem();else if(t.matches(e,"selectCancel"))this.onCancel();else if(this.searchEnabled&&this.searchInput){let i=e.replace(/ /g,"");if(!i)return;this.searchInput.handleInput(i),this.applyFilter(this.searchInput.getValue());}}activateItem(){let e=this.searchEnabled?this.filteredItems[this.selectedIndex]:this.items[this.selectedIndex];if(e){if(e.submenu)this.submenuItemIndex=this.selectedIndex,this.submenuComponent=e.submenu(e.currentValue,t=>{t!==void 0&&(e.currentValue=t,this.onChange(e.id,t)),this.closeSubmenu();});else if(e.values&&e.values.length>0){let s=(e.values.indexOf(e.currentValue)+1)%e.values.length,i=e.values[s];i!==void 0&&(e.currentValue=i,this.onChange(e.id,i));}}}closeSubmenu(){this.submenuComponent=null,this.submenuItemIndex!==null&&(this.selectedIndex=this.submenuItemIndex,this.submenuItemIndex=null);}applyFilter(e){this.filteredItems=ce(this.items,e,t=>t.label),this.selectedIndex=0;}addHintLine(e,t){e.push(""),e.push(O(this.theme.hint(this.searchEnabled?" Type to search \xB7 Enter/Space to change \xB7 Esc to cancel":" Enter/Space to change \xB7 Esc to cancel"),t));}};var Qe=class{constructor(e=1){c(this,"lines");this.lines=e;}setLines(e){this.lines=e;}invalidate(){}render(e){let t=[];for(let s=0;s<this.lines;s++)t.push("");return t}};var Xe=class{constructor(e,t=0,s=0){c(this,"text");c(this,"paddingX");c(this,"paddingY");this.text=e,this.paddingX=t,this.paddingY=s;}invalidate(){}render(e){let t=[],s=" ".repeat(e);for(let m=0;m<this.paddingY;m++)t.push(s);let i=Math.max(1,e-this.paddingX*2),r=this.text,o=this.text.indexOf(`
|
|
45
|
-
`);o!==-1&&(r=this.text.substring(0,o));let l=O(r,i),a=" ".repeat(this.paddingX),h=" ".repeat(this.paddingX),u=a+l+h,f=w(u),p=Math.max(0,e-f),d=u+" ".repeat(p);t.push(d);for(let m=0;m<this.paddingY;m++)t.push(s);return t}};var Y="\x1B",Pt="\x1B[200~",Me="\x1B[201~";function xs(n){if(!n.startsWith(Y))return "not-escape";if(n.length===1)return "incomplete";let e=n.slice(1);return e.startsWith("[")?e.startsWith("[M")?n.length>=6?"complete":"incomplete":bs(n):e.startsWith("]")?vs(n):e.startsWith("P")?Cs(n):e.startsWith("_")?ys(n):e.startsWith("O")?e.length>=2?"complete":"incomplete":(e.length===1,"complete")}function bs(n){if(!n.startsWith(`${Y}[`))return "complete";if(n.length<3)return "incomplete";let e=n.slice(2),t=e[e.length-1],s=t?.charCodeAt(0)??0;if(s>=64&&s<=126){if(e.startsWith("<")){if(/^<\d+;\d+;\d+[Mm]$/.test(e))return "complete";if(t==="M"||t==="m"){let r=e.slice(1,-1).split(";");if(r.length===3&&r.every(o=>/^\d+$/.test(o)))return "complete"}return "incomplete"}return "complete"}return "incomplete"}function vs(n){return !n.startsWith(`${Y}]`)||n.endsWith(`${Y}\\`)||n.endsWith("\x07")?"complete":"incomplete"}function Cs(n){return !n.startsWith(`${Y}P`)||n.endsWith(`${Y}\\`)?"complete":"incomplete"}function ys(n){return !n.startsWith(`${Y}_`)||n.endsWith(`${Y}\\`)?"complete":"incomplete"}function Mt(n){let e=[],t=0;for(;t<n.length;){let s=n.slice(t);if(s.startsWith(Y)){let i=1;for(;i<=s.length;){let r=s.slice(0,i),o=xs(r);if(o==="complete"){e.push(r),t+=i;break}else if(o==="incomplete")i++;else {e.push(r),t+=i;break}}if(i>s.length)return {sequences:e,remainder:s}}else e.push(s[0]),t++;}return {sequences:e,remainder:""}}var ve=class extends events.EventEmitter{constructor(t={}){super();c(this,"buffer","");c(this,"timeout",null);c(this,"timeoutMs");c(this,"pasteMode",false);c(this,"pasteBuffer","");this.timeoutMs=t.timeout??10;}process(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null);let s;if(Buffer.isBuffer(t))if(t.length===1&&t[0]>127){let o=t[0]-128;s=`\x1B${String.fromCharCode(o)}`;}else s=t.toString();else s=t;if(s.length===0&&this.buffer.length===0){this.emit("data","");return}if(this.buffer+=s,this.pasteMode){this.pasteBuffer+=this.buffer,this.buffer="";let o=this.pasteBuffer.indexOf(Me);if(o!==-1){let l=this.pasteBuffer.slice(0,o),a=this.pasteBuffer.slice(o+Me.length);this.pasteMode=false,this.pasteBuffer="",this.emit("paste",l),a.length>0&&this.process(a);}return}let i=this.buffer.indexOf(Pt);if(i!==-1){if(i>0){let l=this.buffer.slice(0,i),a=Mt(l);for(let h of a.sequences)this.emit("data",h);}this.buffer=this.buffer.slice(i+Pt.length),this.pasteMode=true,this.pasteBuffer=this.buffer,this.buffer="";let o=this.pasteBuffer.indexOf(Me);if(o!==-1){let l=this.pasteBuffer.slice(0,o),a=this.pasteBuffer.slice(o+Me.length);this.pasteMode=false,this.pasteBuffer="",this.emit("paste",l),a.length>0&&this.process(a);}return}let r=Mt(this.buffer);this.buffer=r.remainder;for(let o of r.sequences)this.emit("data",o);this.buffer.length>0&&(this.timeout=setTimeout(()=>{let o=this.flush();for(let l of o)this.emit("data",l);},this.timeoutMs));}flush(){if(this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.buffer.length===0)return [];let t=[this.buffer];return this.buffer="",t}clear(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.buffer="",this.pasteMode=false,this.pasteBuffer="";}getBuffer(){return this.buffer}destroy(){this.clear();}};var Je=class{constructor(){c(this,"wasRaw",false);c(this,"inputHandler");c(this,"resizeHandler");c(this,"_kittyProtocolActive",false);c(this,"stdinBuffer");c(this,"stdinDataHandler");c(this,"writeLogPath",process.env.PI_TUI_WRITE_LOG||"");}get kittyProtocolActive(){return this._kittyProtocolActive}start(e,t){this.inputHandler=e,this.resizeHandler=t,this.wasRaw=process.stdin.isRaw||false,process.stdin.setRawMode&&process.stdin.setRawMode(true),process.stdin.setEncoding("utf8"),process.stdin.resume(),process.stdout.write("\x1B[?2004h"),process.stdout.on("resize",this.resizeHandler),process.platform!=="win32"&&process.kill(process.pid,"SIGWINCH"),this.enableWindowsVTInput(),this.queryAndEnableKittyProtocol();}setupStdinBuffer(){this.stdinBuffer=new ve({timeout:10});let e=/^\x1b\[\?(\d+)u$/;this.stdinBuffer.on("data",t=>{if(!this._kittyProtocolActive&&t.match(e)){this._kittyProtocolActive=true,pe(true),process.stdout.write("\x1B[>7u");return}this.inputHandler&&this.inputHandler(t);}),this.stdinBuffer.on("paste",t=>{this.inputHandler&&this.inputHandler(`\x1B[200~${t}\x1B[201~`);}),this.stdinDataHandler=t=>{this.stdinBuffer.process(t);};}queryAndEnableKittyProtocol(){this.setupStdinBuffer(),process.stdin.on("data",this.stdinDataHandler),process.stdout.write("\x1B[?u");}enableWindowsVTInput(){if(process.platform==="win32")try{let e=Ls__default.default.load("kernel32.dll"),t=e.func("void* __stdcall GetStdHandle(int)"),s=e.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)"),i=e.func("bool __stdcall SetConsoleMode(void*, uint32_t)"),r=-10,o=512,l=t(r),a=new Uint32Array(1);s(l,a),i(l,a[0]|o);}catch{}}async drainInput(e=1e3,t=50){this._kittyProtocolActive&&(process.stdout.write("\x1B[<u"),this._kittyProtocolActive=false,pe(false));let s=this.inputHandler;this.inputHandler=void 0;let i=Date.now(),r=()=>{i=Date.now();};process.stdin.on("data",r);let o=Date.now()+e;try{for(;;){let l=Date.now(),a=o-l;if(a<=0||l-i>=t)break;await new Promise(h=>setTimeout(h,Math.min(t,a)));}}finally{process.stdin.removeListener("data",r),this.inputHandler=s;}}stop(){process.stdout.write("\x1B[?2004l"),this._kittyProtocolActive&&(process.stdout.write("\x1B[<u"),this._kittyProtocolActive=false,pe(false)),this.stdinBuffer&&(this.stdinBuffer.destroy(),this.stdinBuffer=void 0),this.stdinDataHandler&&(process.stdin.removeListener("data",this.stdinDataHandler),this.stdinDataHandler=void 0),this.inputHandler=void 0,this.resizeHandler&&(process.stdout.removeListener("resize",this.resizeHandler),this.resizeHandler=void 0),process.stdin.pause(),process.stdin.setRawMode&&process.stdin.setRawMode(this.wasRaw);}write(e){if(process.stdout.write(e),this.writeLogPath)try{J__namespace.appendFileSync(this.writeLogPath,e,{encoding:"utf8"});}catch{}}get columns(){return process.stdout.columns||80}get rows(){return process.stdout.rows||24}moveBy(e){e>0?process.stdout.write(`\x1B[${e}B`):e<0&&process.stdout.write(`\x1B[${-e}A`);}hideCursor(){process.stdout.write("\x1B[?25l");}showCursor(){process.stdout.write("\x1B[?25h");}clearLine(){process.stdout.write("\x1B[K");}clearFromCursor(){process.stdout.write("\x1B[J");}clearScreen(){process.stdout.write("\x1B[2J\x1B[H");}setTitle(e){process.stdout.write(`\x1B]0;${e}\x07`);}};exports.Box=Oe;exports.CURSOR_MARKER=se;exports.CancellableLoader=Fe;exports.CombinedAutocompleteProvider=$e;exports.Container=Pe;exports.DEFAULT_EDITOR_KEYBINDINGS=pt;exports.Editor=ze;exports.EditorKeybindingsManager=ke;exports.Image=je;exports.Input=be;exports.Key=Qt;exports.Loader=ge;exports.Markdown=Ge;exports.ProcessTerminal=Je;exports.SelectList=ie;exports.SettingsList=Ye;exports.Spacer=Qe;exports.StdinBuffer=ve;exports.TUI=qe;exports.Text=me;exports.TruncatedText=Xe;exports.allocateImageId=os;exports.calculateImageRows=Lt;exports.deleteAllKittyImages=as;exports.deleteKittyImage=ls;exports.detectCapabilities=vt;exports.encodeITerm2=yt;exports.encodeKitty=Ct;exports.fuzzyFilter=ce;exports.fuzzyMatch=et;exports.getCapabilities=le;exports.getCellDimensions=bt;exports.getEditorKeybindings=q;exports.getGifDimensions=St;exports.getImageDimensions=Ue;exports.getJpegDimensions=It;exports.getPngDimensions=wt;exports.getWebpDimensions=kt;exports.imageFallback=Ae;exports.isFocusable=Ne;exports.isKeyRelease=De;exports.isKeyRepeat=es;exports.isKittyProtocolActive=Yt;exports.matchesKey=G;exports.parseKey=is;exports.renderImage=_e;exports.resetCapabilitiesCache=rs;exports.setCellDimensions=Ve;exports.setEditorKeybindings=ns;exports.setKittyProtocolActive=pe;exports.sliceByColumn=de;exports.truncateToWidth=O;exports.visibleWidth=w;exports.wrapTextWithAnsi=j;
|
|
30
|
+
`,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine-1]||"";this.state.lines[this.state.cursorLine-1]=t+e,this.state.lines.splice(this.state.cursorLine,1),this.state.cursorLine--,this.setCursorCol(t.length);}}else {this.pushUndoSnapshot();let t=this.lastAction==="kill",s=this.state.cursorCol;this.moveWordBackwards();let n=this.state.cursorCol;this.setCursorCol(s);let r=e.slice(n,this.state.cursorCol);this.killRing.push(r,{prepend:true,accumulate:t}),this.lastAction="kill",this.state.lines[this.state.cursorLine]=e.slice(0,n)+e.slice(this.state.cursorCol),this.setCursorCol(n);}this.onChange&&this.onChange(this.getText());}deleteWordForward(){this.historyIndex=-1;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol>=e.length){if(this.state.cursorLine<this.state.lines.length-1){this.pushUndoSnapshot(),this.killRing.push(`
|
|
31
|
+
`,{prepend:false,accumulate:this.lastAction==="kill"}),this.lastAction="kill";let t=this.state.lines[this.state.cursorLine+1]||"";this.state.lines[this.state.cursorLine]=e+t,this.state.lines.splice(this.state.cursorLine+1,1);}}else {this.pushUndoSnapshot();let t=this.lastAction==="kill",s=this.state.cursorCol;this.moveWordForwards();let n=this.state.cursorCol;this.setCursorCol(s);let r=e.slice(this.state.cursorCol,n);this.killRing.push(r,{prepend:false,accumulate:t}),this.lastAction="kill",this.state.lines[this.state.cursorLine]=e.slice(0,this.state.cursorCol)+e.slice(n);}this.onChange&&this.onChange(this.getText());}handleForwardDelete(){this.historyIndex=-1,this.lastAction=null;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol<e.length){this.pushUndoSnapshot();let t=e.slice(this.state.cursorCol),n=[...this.segment(t)][0],r=n?n.segment.length:1,o=e.slice(0,this.state.cursorCol),a=e.slice(this.state.cursorCol+r);this.state.lines[this.state.cursorLine]=o+a;}else if(this.state.cursorLine<this.state.lines.length-1){this.pushUndoSnapshot();let t=this.state.lines[this.state.cursorLine+1]||"";this.state.lines[this.state.cursorLine]=e+t,this.state.lines.splice(this.state.cursorLine+1,1);}if(this.onChange&&this.onChange(this.getText()),this.autocompleteState)this.updateAutocomplete();else {let s=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(s)?this.tryTriggerAutocomplete():s.match(/(?:^|[\s])[@#][^\s]*$/)&&this.tryTriggerAutocomplete();}}buildVisualLineMap(e){let t=[];for(let s=0;s<this.state.lines.length;s++){let n=this.state.lines[s]||"",r=S(n);if(n.length===0)t.push({logicalLine:s,startCol:0,length:0});else if(r<=e)t.push({logicalLine:s,startCol:0,length:n.length});else {let o=ut(n,e,[...this.segment(n)]);for(let a of o)t.push({logicalLine:s,startCol:a.startIndex,length:a.endIndex-a.startIndex});}}return t}findVisualLineAt(e,t,s){for(let n=0;n<e.length;n++){let r=e[n];if(!r||r.logicalLine!==t)continue;let o=s-r.startCol,a=n===e.length-1||e[n+1]?.logicalLine!==r.logicalLine;if(o>=0&&(o<r.length||a&&o===r.length))return n}return e.length-1}findCurrentVisualLine(e){return this.findVisualLineAt(e,this.state.cursorLine,this.state.cursorCol)}moveCursor(e,t){this.lastAction=null;let s=this.buildVisualLineMap(this.lastWidth),n=this.findCurrentVisualLine(s);if(e!==0){let r=n+e;r>=0&&r<s.length&&this.moveToVisualLine(s,n,r);}if(t!==0){let r=this.state.lines[this.state.cursorLine]||"";if(t>0)if(this.state.cursorCol<r.length){let o=r.slice(this.state.cursorCol),l=[...this.segment(o)][0];this.setCursorCol(this.state.cursorCol+(l?l.segment.length:1));}else if(this.state.cursorLine<this.state.lines.length-1)this.state.cursorLine++,this.setCursorCol(0);else {let o=s[n];o&&(this.preferredVisualCol=this.state.cursorCol-o.startCol);}else if(this.state.cursorCol>0){let o=r.slice(0,this.state.cursorCol),a=[...this.segment(o)],l=a[a.length-1];this.setCursorCol(this.state.cursorCol-(l?l.segment.length:1));}else if(this.state.cursorLine>0){this.state.cursorLine--;let o=this.state.lines[this.state.cursorLine]||"";this.setCursorCol(o.length);}}}pageScroll(e){this.lastAction=null;let t=this.tui.terminal.rows,s=Math.max(5,Math.floor(t*.3)),n=this.buildVisualLineMap(this.lastWidth),r=this.findCurrentVisualLine(n),o=Math.max(0,Math.min(n.length-1,r+e*s));this.moveToVisualLine(n,r,o);}moveWordBackwards(){this.lastAction=null;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol===0){if(this.state.cursorLine>0){this.state.cursorLine--;let r=this.state.lines[this.state.cursorLine]||"";this.setCursorCol(r.length);}return}let t=e.slice(0,this.state.cursorCol),s=[...this.segment(t)],n=this.state.cursorCol;for(;s.length>0&&!Q(s[s.length-1]?.segment||"")&&V(s[s.length-1]?.segment||"");)n-=s.pop()?.segment.length||0;if(s.length>0){let r=s[s.length-1]?.segment||"";if(Q(r))n-=s.pop()?.segment.length||0;else if(U(r))for(;s.length>0&&U(s[s.length-1]?.segment||"")&&!Q(s[s.length-1]?.segment||"");)n-=s.pop()?.segment.length||0;else for(;s.length>0&&!V(s[s.length-1]?.segment||"")&&!U(s[s.length-1]?.segment||"")&&!Q(s[s.length-1]?.segment||"");)n-=s.pop()?.segment.length||0;}this.setCursorCol(n);}yank(){if(this.killRing.length===0)return;this.pushUndoSnapshot();let e=this.killRing.peek();this.insertYankedText(e),this.lastAction="yank";}yankPop(){if(this.lastAction!=="yank"||this.killRing.length<=1)return;this.pushUndoSnapshot(),this.deleteYankedText(),this.killRing.rotate();let e=this.killRing.peek();this.insertYankedText(e),this.lastAction="yank";}insertYankedText(e){this.historyIndex=-1;let t=e.split(`
|
|
32
|
+
`);if(t.length===1){let s=this.state.lines[this.state.cursorLine]||"",n=s.slice(0,this.state.cursorCol),r=s.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=n+e+r,this.setCursorCol(this.state.cursorCol+e.length);}else {let s=this.state.lines[this.state.cursorLine]||"",n=s.slice(0,this.state.cursorCol),r=s.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=n+(t[0]||"");for(let a=1;a<t.length-1;a++)this.state.lines.splice(this.state.cursorLine+a,0,t[a]||"");let o=this.state.cursorLine+t.length-1;this.state.lines.splice(o,0,(t[t.length-1]||"")+r),this.state.cursorLine=o,this.setCursorCol((t[t.length-1]||"").length);}this.onChange&&this.onChange(this.getText());}deleteYankedText(){let e=this.killRing.peek();if(!e)return;let t=e.split(`
|
|
33
|
+
`);if(t.length===1){let s=this.state.lines[this.state.cursorLine]||"",n=e.length,r=s.slice(0,this.state.cursorCol-n),o=s.slice(this.state.cursorCol);this.state.lines[this.state.cursorLine]=r+o,this.setCursorCol(this.state.cursorCol-n);}else {let s=this.state.cursorLine-(t.length-1),n=(this.state.lines[s]||"").length-(t[0]||"").length,r=(this.state.lines[this.state.cursorLine]||"").slice(this.state.cursorCol),o=(this.state.lines[s]||"").slice(0,n);this.state.lines.splice(s,t.length,o+r),this.state.cursorLine=s,this.setCursorCol(n);}this.onChange&&this.onChange(this.getText());}pushUndoSnapshot(){this.undoStack.push(this.state);}undo(){this.historyIndex=-1;let e=this.undoStack.pop();e&&(Object.assign(this.state,e),this.lastAction=null,this.preferredVisualCol=null,this.onChange&&this.onChange(this.getText()));}jumpToChar(e,t){this.lastAction=null;let s=t==="forward",n=this.state.lines,r=s?n.length:-1,o=s?1:-1;for(let a=this.state.cursorLine;a!==r;a+=o){let l=n[a]||"",d=a===this.state.cursorLine?s?this.state.cursorCol+1:this.state.cursorCol-1:void 0,h=s?l.indexOf(e,d):l.lastIndexOf(e,d);if(h!==-1){this.state.cursorLine=a,this.setCursorCol(h);return}}}moveWordForwards(){this.lastAction=null;let e=this.state.lines[this.state.cursorLine]||"";if(this.state.cursorCol>=e.length){this.state.cursorLine<this.state.lines.length-1&&(this.state.cursorLine++,this.setCursorCol(0));return}let t=e.slice(this.state.cursorCol),n=this.segment(t)[Symbol.iterator](),r=n.next(),o=this.state.cursorCol;for(;!r.done&&!Q(r.value.segment)&&V(r.value.segment);)o+=r.value.segment.length,r=n.next();if(!r.done){let a=r.value.segment;if(Q(a))o+=a.length;else if(U(a))for(;!r.done&&U(r.value.segment)&&!Q(r.value.segment);)o+=r.value.segment.length,r=n.next();else for(;!r.done&&!V(r.value.segment)&&!U(r.value.segment)&&!Q(r.value.segment);)o+=r.value.segment.length,r=n.next();}this.setCursorCol(o);}isSlashMenuAllowed(){return this.state.cursorLine===0}isAtStartOfMessage(){if(!this.isSlashMenuAllowed())return false;let t=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);return t.trim()===""||t.trim()==="/"}isInSlashCommandContext(e){return this.isSlashMenuAllowed()&&e.trimStart().startsWith("/")}getBestAutocompleteMatchIndex(e,t){if(!t)return -1;let s=-1;for(let n=0;n<e.length;n++){let r=e[n].value;if(r===t)return n;s===-1&&r.startsWith(t)&&(s=n);}return s}createAutocompleteList(e,t){let s=e.startsWith("/")?ri:void 0;return new we(t,this.autocompleteMaxVisible,this.theme.selectList,s)}tryTriggerAutocomplete(e=false){this.requestAutocomplete({force:false,explicitTab:e});}handleTabCompletion(){if(!this.autocompleteProvider)return;let t=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);this.isInSlashCommandContext(t)&&!t.trimStart().includes(" ")?this.handleSlashCommandCompletion():this.forceFileAutocomplete(true);}handleSlashCommandCompletion(){this.requestAutocomplete({force:false,explicitTab:true});}forceFileAutocomplete(e=false){this.requestAutocomplete({force:true,explicitTab:e});}requestAutocomplete(e){if(!this.autocompleteProvider||e.force&&!(!this.autocompleteProvider.shouldTriggerFileCompletion||this.autocompleteProvider.shouldTriggerFileCompletion(this.state.lines,this.state.cursorLine,this.state.cursorCol)))return;this.cancelAutocompleteRequest();let t=++this.autocompleteStartToken,s=this.getAutocompleteDebounceMs(e);if(s>0){this.autocompleteDebounceTimer=setTimeout(()=>{this.autocompleteDebounceTimer=void 0,this.startAutocompleteRequest(t,e);},s);return}this.startAutocompleteRequest(t,e);}async startAutocompleteRequest(e,t){let s=this.autocompleteRequestTask;this.autocompleteRequestTask=(async()=>{if(await s,e!==this.autocompleteStartToken||!this.autocompleteProvider)return;let n=new AbortController;this.autocompleteAbort=n;let r=++this.autocompleteRequestId,o=this.getText(),a=this.state.cursorLine,l=this.state.cursorCol;await this.runAutocompleteRequest(r,n,o,a,l,t);})(),await this.autocompleteRequestTask;}getAutocompleteDebounceMs(e){if(e.explicitTab||e.force)return 0;let s=(this.state.lines[this.state.cursorLine]||"").slice(0,this.state.cursorCol);return /(?:^|[ \t])(?:@(?:"[^"]*|[^\s]*)|#[^\s]*)$/.test(s)?oi:0}async runAutocompleteRequest(e,t,s,n,r,o){if(!this.autocompleteProvider)return;let a=await this.autocompleteProvider.getSuggestions(this.state.lines,this.state.cursorLine,this.state.cursorCol,{signal:t.signal,force:o.force});if(this.isAutocompleteRequestCurrent(e,t,s,n,r)){if(this.autocompleteAbort=void 0,!a||!Array.isArray(a.items)||a.items.length===0){this.cancelAutocomplete(),this.tui.requestRender();return}if(o.force&&o.explicitTab&&a.items.length===1){let l=a.items[0];this.pushUndoSnapshot(),this.lastAction=null;let c=this.autocompleteProvider.applyCompletion(this.state.lines,this.state.cursorLine,this.state.cursorCol,l,a.prefix);this.state.lines=c.lines,this.state.cursorLine=c.cursorLine,this.setCursorCol(c.cursorCol),this.onChange&&this.onChange(this.getText()),this.tui.requestRender();return}this.applyAutocompleteSuggestions(a,o.force?"force":"regular"),this.tui.requestRender();}}isAutocompleteRequestCurrent(e,t,s,n,r){return !t.signal.aborted&&e===this.autocompleteRequestId&&this.getText()===s&&this.state.cursorLine===n&&this.state.cursorCol===r}applyAutocompleteSuggestions(e,t){this.autocompletePrefix=e.prefix,this.autocompleteList=this.createAutocompleteList(e.prefix,e.items);let s=this.getBestAutocompleteMatchIndex(e.items,e.prefix);s>=0&&this.autocompleteList.setSelectedIndex(s),this.autocompleteState=t;}cancelAutocompleteRequest(){this.autocompleteStartToken+=1,this.autocompleteDebounceTimer&&(clearTimeout(this.autocompleteDebounceTimer),this.autocompleteDebounceTimer=void 0),this.autocompleteAbort?.abort(),this.autocompleteAbort=void 0;}clearAutocompleteUi(){this.autocompleteState=null,this.autocompleteList=void 0,this.autocompletePrefix="";}cancelAutocomplete(){this.cancelAutocompleteRequest(),this.clearAutocompleteUi();}isShowingAutocomplete(){return this.autocompleteState!==null}updateAutocomplete(){!this.autocompleteState||!this.autocompleteProvider||this.requestAutocomplete({force:this.autocompleteState==="force",explicitTab:false});}};var dt=class{constructor(e,t,s,n={},r){u(this,"base64Data");u(this,"mimeType");u(this,"dimensions");u(this,"theme");u(this,"options");u(this,"imageId");u(this,"cachedLines");u(this,"cachedWidth");this.base64Data=e,this.mimeType=t,this.theme=s,this.options=n,this.dimensions=r||it(e,t)||{widthPx:800,heightPx:600},this.imageId=n.imageId;}getImageId(){return this.imageId}invalidate(){this.cachedLines=void 0,this.cachedWidth=void 0;}render(e){if(this.cachedLines&&this.cachedWidth===e)return this.cachedLines;let t=Math.min(e-2,this.options.maxWidthCells??60),s=se(),n;if(s.images){let r=nt(this.base64Data,this.dimensions,{maxWidthCells:t,imageId:this.imageId});if(r){r.imageId&&(this.imageId=r.imageId),n=[];for(let a=0;a<r.rows-1;a++)n.push("");let o=r.rows>1?`\x1B[${r.rows-1}A`:"";n.push(o+r.sequence);}else {let o=De(this.mimeType,this.dimensions,this.options.filename);n=[this.theme.fallbackColor(o)];}}else {let r=De(this.mimeType,this.dimensions,this.options.filename);n=[this.theme.fallbackColor(r)];}return this.cachedLines=n,this.cachedWidth=e,n}};var ue=Ae(),Se=class{constructor(){u(this,"value","");u(this,"cursor",0);u(this,"onSubmit");u(this,"onEscape");u(this,"focused",false);u(this,"pasteBuffer","");u(this,"isInPaste",false);u(this,"killRing",new fe);u(this,"lastAction",null);u(this,"undoStack",new me);}getValue(){return this.value}setValue(e){this.value=e,this.cursor=Math.min(this.cursor,e.length);}handleInput(e){if(e.includes("\x1B[200~")&&(this.isInPaste=true,this.pasteBuffer="",e=e.replace("\x1B[200~","")),this.isInPaste){this.pasteBuffer+=e;let r=this.pasteBuffer.indexOf("\x1B[201~");if(r!==-1){let o=this.pasteBuffer.substring(0,r);this.handlePaste(o),this.isInPaste=false;let a=this.pasteBuffer.substring(r+6);this.pasteBuffer="",a&&this.handleInput(a);}return}let t=G();if(t.matches(e,"tui.select.cancel")){this.onEscape&&this.onEscape();return}if(t.matches(e,"tui.editor.undo")){this.undo();return}if(t.matches(e,"tui.input.submit")||e===`
|
|
34
|
+
`){this.onSubmit&&this.onSubmit(this.value);return}if(t.matches(e,"tui.editor.deleteCharBackward")){this.handleBackspace();return}if(t.matches(e,"tui.editor.deleteCharForward")){this.handleForwardDelete();return}if(t.matches(e,"tui.editor.deleteWordBackward")){this.deleteWordBackwards();return}if(t.matches(e,"tui.editor.deleteWordForward")){this.deleteWordForward();return}if(t.matches(e,"tui.editor.deleteToLineStart")){this.deleteToLineStart();return}if(t.matches(e,"tui.editor.deleteToLineEnd")){this.deleteToLineEnd();return}if(t.matches(e,"tui.editor.yank")){this.yank();return}if(t.matches(e,"tui.editor.yankPop")){this.yankPop();return}if(t.matches(e,"tui.editor.cursorLeft")){if(this.lastAction=null,this.cursor>0){let r=this.value.slice(0,this.cursor),o=[...ue.segment(r)],a=o[o.length-1];this.cursor-=a?a.segment.length:1;}return}if(t.matches(e,"tui.editor.cursorRight")){if(this.lastAction=null,this.cursor<this.value.length){let r=this.value.slice(this.cursor),a=[...ue.segment(r)][0];this.cursor+=a?a.segment.length:1;}return}if(t.matches(e,"tui.editor.cursorLineStart")){this.lastAction=null,this.cursor=0;return}if(t.matches(e,"tui.editor.cursorLineEnd")){this.lastAction=null,this.cursor=this.value.length;return}if(t.matches(e,"tui.editor.cursorWordLeft")){this.moveWordBackwards();return}if(t.matches(e,"tui.editor.cursorWordRight")){this.moveWordForwards();return}let s=We(e);if(s!==void 0){this.insertCharacter(s);return}[...e].some(r=>{let o=r.charCodeAt(0);return o<32||o===127||o>=128&&o<=159})||this.insertCharacter(e);}insertCharacter(e){(V(e)||this.lastAction!=="type-word")&&this.pushUndo(),this.lastAction="type-word",this.value=this.value.slice(0,this.cursor)+e+this.value.slice(this.cursor),this.cursor+=e.length;}handleBackspace(){if(this.lastAction=null,this.cursor>0){this.pushUndo();let e=this.value.slice(0,this.cursor),t=[...ue.segment(e)],s=t[t.length-1],n=s?s.segment.length:1;this.value=this.value.slice(0,this.cursor-n)+this.value.slice(this.cursor),this.cursor-=n;}}handleForwardDelete(){if(this.lastAction=null,this.cursor<this.value.length){this.pushUndo();let e=this.value.slice(this.cursor),s=[...ue.segment(e)][0],n=s?s.segment.length:1;this.value=this.value.slice(0,this.cursor)+this.value.slice(this.cursor+n);}}deleteToLineStart(){if(this.cursor===0)return;this.pushUndo();let e=this.value.slice(0,this.cursor);this.killRing.push(e,{prepend:true,accumulate:this.lastAction==="kill"}),this.lastAction="kill",this.value=this.value.slice(this.cursor),this.cursor=0;}deleteToLineEnd(){if(this.cursor>=this.value.length)return;this.pushUndo();let e=this.value.slice(this.cursor);this.killRing.push(e,{prepend:false,accumulate:this.lastAction==="kill"}),this.lastAction="kill",this.value=this.value.slice(0,this.cursor);}deleteWordBackwards(){if(this.cursor===0)return;let e=this.lastAction==="kill";this.pushUndo();let t=this.cursor;this.moveWordBackwards();let s=this.cursor;this.cursor=t;let n=this.value.slice(s,this.cursor);this.killRing.push(n,{prepend:true,accumulate:e}),this.lastAction="kill",this.value=this.value.slice(0,s)+this.value.slice(this.cursor),this.cursor=s;}deleteWordForward(){if(this.cursor>=this.value.length)return;let e=this.lastAction==="kill";this.pushUndo();let t=this.cursor;this.moveWordForwards();let s=this.cursor;this.cursor=t;let n=this.value.slice(this.cursor,s);this.killRing.push(n,{prepend:false,accumulate:e}),this.lastAction="kill",this.value=this.value.slice(0,this.cursor)+this.value.slice(s);}yank(){let e=this.killRing.peek();e&&(this.pushUndo(),this.value=this.value.slice(0,this.cursor)+e+this.value.slice(this.cursor),this.cursor+=e.length,this.lastAction="yank");}yankPop(){if(this.lastAction!=="yank"||this.killRing.length<=1)return;this.pushUndo();let e=this.killRing.peek()||"";this.value=this.value.slice(0,this.cursor-e.length)+this.value.slice(this.cursor),this.cursor-=e.length,this.killRing.rotate();let t=this.killRing.peek()||"";this.value=this.value.slice(0,this.cursor)+t+this.value.slice(this.cursor),this.cursor+=t.length,this.lastAction="yank";}pushUndo(){this.undoStack.push({value:this.value,cursor:this.cursor});}undo(){let e=this.undoStack.pop();e&&(this.value=e.value,this.cursor=e.cursor,this.lastAction=null);}moveWordBackwards(){if(this.cursor===0)return;this.lastAction=null;let e=this.value.slice(0,this.cursor),t=[...ue.segment(e)];for(;t.length>0&&V(t[t.length-1]?.segment||"");)this.cursor-=t.pop()?.segment.length||0;if(t.length>0){let s=t[t.length-1]?.segment||"";if(U(s))for(;t.length>0&&U(t[t.length-1]?.segment||"");)this.cursor-=t.pop()?.segment.length||0;else for(;t.length>0&&!V(t[t.length-1]?.segment||"")&&!U(t[t.length-1]?.segment||"");)this.cursor-=t.pop()?.segment.length||0;}}moveWordForwards(){if(this.cursor>=this.value.length)return;this.lastAction=null;let e=this.value.slice(this.cursor),s=ue.segment(e)[Symbol.iterator](),n=s.next();for(;!n.done&&V(n.value.segment);)this.cursor+=n.value.segment.length,n=s.next();if(!n.done){let r=n.value.segment;if(U(r))for(;!n.done&&U(n.value.segment);)this.cursor+=n.value.segment.length,n=s.next();else for(;!n.done&&!V(n.value.segment)&&!U(n.value.segment);)this.cursor+=n.value.segment.length,n=s.next();}}handlePaste(e){this.lastAction=null,this.pushUndo();let t=e.replace(/\r\n/g,"").replace(/\r/g,"").replace(/\n/g,"").replace(/\t/g," ");this.value=this.value.slice(0,this.cursor)+t+this.value.slice(this.cursor),this.cursor+=t.length;}invalidate(){}render(e){let s=e-2;if(s<=0)return ["> "];let n="",r=this.cursor,o=S(this.value);if(o<s)n=this.value;else {let x=this.cursor===this.value.length?s-1:s,I=S(this.value.slice(0,this.cursor));if(x>0){let M=Math.floor(x/2),T=0;I<M?T=0:I>o-M?T=Math.max(0,o-x):T=Math.max(0,I-M),n=he(this.value,T,x,true),r=he(this.value,T,Math.max(0,I-T),true).length;}else n="",r=0;}let l=[...ue.segment(n.slice(r))][0],c=n.slice(0,r),d=l?.segment??" ",h=n.slice(r+d.length),f=this.focused?ce:"",m=`\x1B[7m${d}\x1B[27m`,g=c+f+m+h,p=S(g),b=" ".repeat(Math.max(0,s-p));return ["> "+g+b]}};var ci=/^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,ft=class extends marked.Tokenizer{del(e){let t=ci.exec(e);if(!t)return;let s=t[2]??"";return {type:"del",raw:t[0],text:s,tokens:this.lexer.inlineTokens(s)}}},es=new marked.Marked;es.setOptions({tokenizer:new ft});var pt=class{constructor(e,t,s,n,r){u(this,"text");u(this,"paddingX");u(this,"paddingY");u(this,"defaultTextStyle");u(this,"theme");u(this,"defaultStylePrefix");u(this,"cachedText");u(this,"cachedWidth");u(this,"cachedLines");this.text=e,this.paddingX=t,this.paddingY=s,this.theme=n,this.defaultTextStyle=r;}setText(e){this.text=e,this.invalidate();}invalidate(){this.cachedText=void 0,this.cachedWidth=void 0,this.cachedLines=void 0;}render(e){if(this.cachedLines&&this.cachedText===this.text&&this.cachedWidth===e)return this.cachedLines;let t=Math.max(1,e-this.paddingX*2);if(!this.text||this.text.trim()===""){let g=[];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=g,g}let s=this.text.replace(/\t/g," "),n=es.lexer(s),r=[];for(let g=0;g<n.length;g++){let p=n[g],b=n[g+1];if(p){let y=this.renderToken(p,t,b?.type);r.push(...y);}}let o=[];for(let g of r)le(g)?o.push(g):o.push(...Y(g,t));let a=" ".repeat(this.paddingX),l=" ".repeat(this.paddingX),c=this.defaultTextStyle?.bgColor,d=[];for(let g of o){if(le(g)){d.push(g);continue}let p=a+g+l;if(c)d.push(te(p,e,c));else {let b=S(p),y=Math.max(0,e-b);d.push(p+" ".repeat(y));}}let h=" ".repeat(e),f=[];for(let g=0;g<this.paddingY;g++){let p=c?te(h,e,c):h;f.push(p);}let m=[...f,...d,...f];return this.cachedText=this.text,this.cachedWidth=e,this.cachedLines=m,m.length>0?m:[""]}applyDefaultStyle(e){if(!this.defaultTextStyle)return e;let t=e;return this.defaultTextStyle.color&&(t=this.defaultTextStyle.color(t)),this.defaultTextStyle.bold&&(t=this.theme.bold(t)),this.defaultTextStyle.italic&&(t=this.theme.italic(t)),this.defaultTextStyle.strikethrough&&(t=this.theme.strikethrough(t)),this.defaultTextStyle.underline&&(t=this.theme.underline(t)),t}getDefaultStylePrefix(){if(!this.defaultTextStyle)return "";if(this.defaultStylePrefix!==void 0)return this.defaultStylePrefix;let e="\0",t=e;this.defaultTextStyle.color&&(t=this.defaultTextStyle.color(t)),this.defaultTextStyle.bold&&(t=this.theme.bold(t)),this.defaultTextStyle.italic&&(t=this.theme.italic(t)),this.defaultTextStyle.strikethrough&&(t=this.theme.strikethrough(t)),this.defaultTextStyle.underline&&(t=this.theme.underline(t));let s=t.indexOf(e);return this.defaultStylePrefix=s>=0?t.slice(0,s):"",this.defaultStylePrefix}getStylePrefix(e){let s=e("\0"),n=s.indexOf("\0");return n>=0?s.slice(0,n):""}getDefaultInlineStyleContext(){return {applyText:e=>this.applyDefaultStyle(e),stylePrefix:this.getDefaultStylePrefix()}}renderToken(e,t,s,n){let r=[];switch(e.type){case "heading":{let o=e.depth,a=`${"#".repeat(o)} `,l;o===1?l=f=>this.theme.heading(this.theme.bold(this.theme.underline(f))):l=f=>this.theme.heading(this.theme.bold(f));let c={applyText:l,stylePrefix:this.getStylePrefix(l)},d=this.renderInlineTokens(e.tokens||[],c),h=o>=3?l(a)+d:d;r.push(h),s&&s!=="space"&&r.push("");break}case "paragraph":{let o=this.renderInlineTokens(e.tokens||[],n);r.push(o),s&&s!=="list"&&s!=="space"&&r.push("");break}case "code":{let o=this.theme.codeBlockIndent??" ";if(r.push(this.theme.codeBlockBorder(`\`\`\`${e.lang||""}`)),this.theme.highlightCode){let a=this.theme.highlightCode(e.text,e.lang);for(let l of a)r.push(`${o}${l}`);}else {let a=e.text.split(`
|
|
35
|
+
`);for(let l of a)r.push(`${o}${this.theme.codeBlock(l)}`);}r.push(this.theme.codeBlockBorder("```")),s&&s!=="space"&&r.push("");break}case "list":{let o=this.renderList(e,0,n);r.push(...o);break}case "table":{let o=this.renderTable(e,t,s,n);r.push(...o);break}case "blockquote":{let o=m=>this.theme.quote(this.theme.italic(m)),a=this.getStylePrefix(o),l=m=>{if(!a)return o(m);let g=m.replace(/\x1b\[0m/g,`\x1B[0m${a}`);return o(g)},c=Math.max(1,t-2),d={applyText:m=>m,stylePrefix:a},h=e.tokens||[],f=[];for(let m=0;m<h.length;m++){let g=h[m],p=h[m+1];g&&f.push(...this.renderToken(g,c,p?.type,d));}for(;f.length>0&&f[f.length-1]==="";)f.pop();for(let m of f){let g=l(m),p=Y(g,c);for(let b of p)r.push(this.theme.quoteBorder("\u2502 ")+b);}s&&s!=="space"&&r.push("");break}case "hr":r.push(this.theme.hr("\u2500".repeat(Math.min(t,80)))),s&&s!=="space"&&r.push("");break;case "html":"raw"in e&&typeof e.raw=="string"&&r.push(this.applyDefaultStyle(e.raw.trim()));break;case "space":r.push("");break;default:"text"in e&&typeof e.text=="string"&&r.push(e.text);}return r}renderInlineTokens(e,t){let s="",n=t??this.getDefaultInlineStyleContext(),{applyText:r,stylePrefix:o}=n,a=l=>l.split(`
|
|
36
|
+
`).map(d=>r(d)).join(`
|
|
37
|
+
`);for(let l of e)switch(l.type){case "text":l.tokens&&l.tokens.length>0?s+=this.renderInlineTokens(l.tokens,n):s+=a(l.text);break;case "paragraph":s+=this.renderInlineTokens(l.tokens||[],n);break;case "strong":{let c=this.renderInlineTokens(l.tokens||[],n);s+=this.theme.bold(c)+o;break}case "em":{let c=this.renderInlineTokens(l.tokens||[],n);s+=this.theme.italic(c)+o;break}case "codespan":s+=this.theme.code(l.text)+o;break;case "link":{let c=this.renderInlineTokens(l.tokens||[],n),d=this.theme.link(this.theme.underline(c));if(se().hyperlinks)s+=rt(d,l.href)+o;else {let h=l.href.startsWith("mailto:")?l.href.slice(7):l.href;l.text===l.href||l.text===h?s+=d+o:s+=d+this.theme.linkUrl(` (${l.href})`)+o;}break}case "br":s+=`
|
|
38
|
+
`;break;case "del":{let c=this.renderInlineTokens(l.tokens||[],n);s+=this.theme.strikethrough(c)+o;break}case "html":"raw"in l&&typeof l.raw=="string"&&(s+=a(l.raw));break;default:"text"in l&&typeof l.text=="string"&&(s+=a(l.text));}for(;o&&s.endsWith(o);)s=s.slice(0,-o.length);return s}renderList(e,t,s){let n=[],r=" ".repeat(t),o=e.start??1;for(let a=0;a<e.items.length;a++){let l=e.items[a],c=e.ordered?`${o+a}. `:"- ",d=this.renderListItem(l.tokens||[],t,s);if(d.length>0){let h=d[0];h&&(/^\s+\x1b\[36m[-\d]/.test(h)?n.push(h):n.push(r+this.theme.listBullet(c)+h));for(let f=1;f<d.length;f++){let m=d[f];m&&(/^\s+\x1b\[36m[-\d]/.test(m)?n.push(m):n.push(`${r} ${m}`));}}else n.push(r+this.theme.listBullet(c));}return n}renderListItem(e,t,s){let n=[];for(let r of e)if(r.type==="list"){let o=this.renderList(r,t+1,s);n.push(...o);}else if(r.type==="text"){let o=r.tokens&&r.tokens.length>0?this.renderInlineTokens(r.tokens,s):r.text||"";n.push(o);}else if(r.type==="paragraph"){let o=this.renderInlineTokens(r.tokens||[],s);n.push(o);}else if(r.type==="code"){let o=this.theme.codeBlockIndent??" ";if(n.push(this.theme.codeBlockBorder(`\`\`\`${r.lang||""}`)),this.theme.highlightCode){let a=this.theme.highlightCode(r.text,r.lang);for(let l of a)n.push(`${o}${l}`);}else {let a=r.text.split(`
|
|
39
|
+
`);for(let l of a)n.push(`${o}${this.theme.codeBlock(l)}`);}n.push(this.theme.codeBlockBorder("```"));}else {let o=this.renderInlineTokens([r],s);o&&n.push(o);}return n}getLongestWordWidth(e,t){let s=e.split(/\s+/).filter(r=>r.length>0),n=0;for(let r of s)n=Math.max(n,S(r));return t===void 0?n:Math.min(n,t)}wrapCellText(e,t){return Y(e,Math.max(1,t))}renderTable(e,t,s,n){let r=[],o=e.header.length;if(o===0)return r;let a=3*o+1,l=t-a;if(l<o){let w=e.raw?Y(e.raw,t):[];return s&&s!=="space"&&w.push(""),w}let c=30,d=[],h=[];for(let w=0;w<o;w++){let A=this.renderInlineTokens(e.header[w].tokens||[],n);d[w]=S(A),h[w]=Math.max(1,this.getLongestWordWidth(A,c));}for(let w of e.rows)for(let A=0;A<w.length;A++){let $=this.renderInlineTokens(w[A].tokens||[],n);d[A]=Math.max(d[A]||0,S($)),h[A]=Math.max(h[A]||1,this.getLongestWordWidth($,c));}let f=h,m=f.reduce((w,A)=>w+A,0);if(m>l){f=new Array(o).fill(1);let w=l-o;if(w>0){let A=h.reduce((v,L)=>v+Math.max(0,L-1),0),$=h.map(v=>{let L=Math.max(0,v-1);return A>0?Math.floor(L/A*w):0});for(let v=0;v<o;v++){let L=$[v]??0;f[v]=(f[v]??1)+L;}let D=$.reduce((v,L)=>v+L,0),K=w-D;for(let v=0;K>0&&v<o;v++)f[v]=(f[v]??1)+1,K--;}m=f.reduce((A,$)=>A+$,0);}let g=d.reduce((w,A)=>w+A,0)+a,p;if(g<=t)p=d.map((w,A)=>Math.max(w,f[A]??1));else {let w=d.reduce((K,v,L)=>K+Math.max(0,v-(f[L]??1)),0),A=Math.max(0,l-m);p=f.map((K,v)=>{let L=d[v]??1,E=Math.max(0,L-K),O=0;return w>0&&(O=Math.floor(E/w*A)),K+O});let $=p.reduce((K,v)=>K+v,0),D=l-$;for(;D>0;){let K=false;for(let v=0;v<o&&D>0;v++){let L=p[v],E=d[v];L!==void 0&&E!==void 0&&L<E&&(p[v]=L+1,D--,K=true);}if(!K)break}}let b=p.map(w=>"\u2500".repeat(w));r.push(`\u250C\u2500${b.join("\u2500\u252C\u2500")}\u2500\u2510`);let y=e.header.map((w,A)=>{let $=this.renderInlineTokens(w.tokens||[],n);return this.wrapCellText($,p[A]??1)}),x=Math.max(...y.map(w=>w.length));for(let w=0;w<x;w++){let A=y.map(($,D)=>{let K=$[w]||"",v=p[D]??1,L=K+" ".repeat(Math.max(0,v-S(K)));return this.theme.bold(L)});r.push(`\u2502 ${A.join(" \u2502 ")} \u2502`);}let M=`\u251C\u2500${p.map(w=>"\u2500".repeat(w)).join("\u2500\u253C\u2500")}\u2500\u2524`;r.push(M);for(let w=0;w<e.rows.length;w++){let A=e.rows[w];if(A){let $=A.map((K,v)=>{let L=this.renderInlineTokens(K.tokens||[],n);return this.wrapCellText(L,p[v]??1)}),D=Math.max(...$.map(K=>K.length));for(let K=0;K<D;K++){let v=$.map((L,E)=>{let O=L[K]||"",ne=p[E]??1;return O+" ".repeat(Math.max(0,ne-S(O)))});r.push(`\u2502 ${v.join(" \u2502 ")} \u2502`);}}w<e.rows.length-1&&r.push(M);}let T=p.map(w=>"\u2500".repeat(w));return r.push(`\u2514\u2500${T.join("\u2500\u2534\u2500")}\u2500\u2518`),s&&s!=="space"&&r.push(""),r}};var mt=class{constructor(e,t,s,n,r,o={}){u(this,"items");u(this,"filteredItems");u(this,"theme");u(this,"selectedIndex",0);u(this,"maxVisible");u(this,"onChange");u(this,"onCancel");u(this,"searchInput");u(this,"searchEnabled");u(this,"submenuComponent",null);u(this,"submenuItemIndex",null);this.items=e,this.filteredItems=e,this.maxVisible=t,this.theme=s,this.onChange=n,this.onCancel=r,this.searchEnabled=o.enableSearch??false,this.searchEnabled&&(this.searchInput=new Se);}updateValue(e,t){let s=this.items.find(n=>n.id===e);s&&(s.currentValue=t);}invalidate(){this.submenuComponent?.invalidate?.();}render(e){return this.submenuComponent?this.submenuComponent.render(e):this.renderMainList(e)}renderMainList(e){let t=[];if(this.searchEnabled&&this.searchInput&&(t.push(...this.searchInput.render(e)),t.push("")),this.items.length===0)return t.push(this.theme.hint(" No settings available")),this.searchEnabled&&this.addHintLine(t,e),t;let s=this.searchEnabled?this.filteredItems:this.items;if(s.length===0)return t.push(_(this.theme.hint(" No matching settings"),e)),this.addHintLine(t,e),t;let n=Math.max(0,Math.min(this.selectedIndex-Math.floor(this.maxVisible/2),s.length-this.maxVisible)),r=Math.min(n+this.maxVisible,s.length),o=Math.min(30,Math.max(...this.items.map(l=>S(l.label))));for(let l=n;l<r;l++){let c=s[l];if(!c)continue;let d=l===this.selectedIndex,h=d?this.theme.cursor:" ",f=S(h),m=c.label+" ".repeat(Math.max(0,o-S(c.label))),g=this.theme.label(m,d),p=" ",b=f+o+S(p),y=e-b-2,x=this.theme.value(_(c.currentValue,y,""),d);t.push(_(h+g+p+x,e));}if(n>0||r<s.length){let l=` (${this.selectedIndex+1}/${s.length})`;t.push(this.theme.hint(_(l,e-2,"")));}let a=s[this.selectedIndex];if(a?.description){t.push("");let l=Y(a.description,e-4);for(let c of l)t.push(this.theme.description(` ${c}`));}return this.addHintLine(t,e),t}handleInput(e){if(this.submenuComponent){this.submenuComponent.handleInput?.(e);return}let t=G(),s=this.searchEnabled?this.filteredItems:this.items;if(t.matches(e,"tui.select.up")){if(s.length===0)return;this.selectedIndex=this.selectedIndex===0?s.length-1:this.selectedIndex-1;}else if(t.matches(e,"tui.select.down")){if(s.length===0)return;this.selectedIndex=this.selectedIndex===s.length-1?0:this.selectedIndex+1;}else if(t.matches(e,"tui.select.confirm")||e===" ")this.activateItem();else if(t.matches(e,"tui.select.cancel"))this.onCancel();else if(this.searchEnabled&&this.searchInput){let n=e.replace(/ /g,"");if(!n)return;this.searchInput.handleInput(n),this.applyFilter(this.searchInput.getValue());}}activateItem(){let e=this.searchEnabled?this.filteredItems[this.selectedIndex]:this.items[this.selectedIndex];if(e){if(e.submenu)this.submenuItemIndex=this.selectedIndex,this.submenuComponent=e.submenu(e.currentValue,t=>{t!==void 0&&(e.currentValue=t,this.onChange(e.id,t)),this.closeSubmenu();});else if(e.values&&e.values.length>0){let s=(e.values.indexOf(e.currentValue)+1)%e.values.length,n=e.values[s]??e.currentValue;e.currentValue=n,this.onChange(e.id,n);}}}closeSubmenu(){this.submenuComponent=null,this.submenuItemIndex!==null&&(this.selectedIndex=this.submenuItemIndex,this.submenuItemIndex=null);}applyFilter(e){this.filteredItems=ge(this.items,e,t=>t.label),this.selectedIndex=0;}addHintLine(e,t){e.push(""),e.push(_(this.theme.hint(this.searchEnabled?" Type to search \xB7 Enter/Space to change \xB7 Esc to cancel":" Enter/Space to change \xB7 Esc to cancel"),t));}};var gt=class{constructor(e=1){u(this,"lines");this.lines=e;}setLines(e){this.lines=e;}invalidate(){}render(e){let t=[];for(let s=0;s<this.lines;s++)t.push("");return t}};var bt=class{constructor(e,t=0,s=0){u(this,"text");u(this,"paddingX");u(this,"paddingY");this.text=e,this.paddingX=t,this.paddingY=s;}invalidate(){}render(e){let t=[],s=" ".repeat(e);for(let g=0;g<this.paddingY;g++)t.push(s);let n=Math.max(1,e-this.paddingX*2),r=this.text,o=this.text.indexOf(`
|
|
40
|
+
`);o!==-1&&(r=this.text.substring(0,o));let a=_(r,n),l=" ".repeat(this.paddingX),c=" ".repeat(this.paddingX),d=l+a+c,h=S(d),f=Math.max(0,e-h),m=d+" ".repeat(f);t.push(m);for(let g=0;g<this.paddingY;g++)t.push(s);return t}};var Z="\x1B",ts="\x1B[200~",Ve="\x1B[201~";function hi(i){if(!i.startsWith(Z))return "not-escape";if(i.length===1)return "incomplete";let e=i.slice(1);return e.startsWith("[")?e.startsWith("[M")?i.length>=6?"complete":"incomplete":di(i):e.startsWith("]")?fi(i):e.startsWith("P")?pi(i):e.startsWith("_")?mi(i):e.startsWith("O")?e.length>=2?"complete":"incomplete":(e.length===1,"complete")}function di(i){if(!i.startsWith(`${Z}[`))return "complete";if(i.length<3)return "incomplete";let e=i.slice(2),t=e[e.length-1];if(!t)return "incomplete";let s=t.charCodeAt(0);if(s>=64&&s<=126){if(e.startsWith("<")){if(/^<\d+;\d+;\d+[Mm]$/.test(e))return "complete";if(t==="M"||t==="m"){let r=e.slice(1,-1).split(";");if(r.length===3&&r.every(o=>/^\d+$/.test(o)))return "complete"}return "incomplete"}return "complete"}return "incomplete"}function fi(i){return !i.startsWith(`${Z}]`)||i.endsWith(`${Z}\\`)||i.endsWith("\x07")?"complete":"incomplete"}function pi(i){return !i.startsWith(`${Z}P`)||i.endsWith(`${Z}\\`)?"complete":"incomplete"}function mi(i){return !i.startsWith(`${Z}_`)||i.endsWith(`${Z}\\`)?"complete":"incomplete"}function gi(i){let e=i.match(/^\x1b\[(\d+)(?::\d*)?(?::\d+)?u$/);if(!e)return;let t=parseInt(e[1],10);return t>=32?t:void 0}function ss(i){let e=[],t=0;for(;t<i.length;){let s=i.slice(t);if(s.startsWith(Z)){let n=1;for(;n<=s.length;){let r=s.slice(0,n),o=hi(r);if(o==="complete"){e.push(r),t+=n;break}else if(o==="incomplete")n++;else {e.push(r),t+=n;break}}if(n>s.length)return {sequences:e,remainder:s}}else e.push(s[0]),t++;}return {sequences:e,remainder:""}}var ke=class extends events.EventEmitter{constructor(t={}){super();u(this,"buffer","");u(this,"timeout",null);u(this,"timeoutMs");u(this,"pasteMode",false);u(this,"pasteBuffer","");u(this,"pendingKittyPrintableCodepoint");this.timeoutMs=t.timeout??10;}process(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null);let s;if(Buffer.isBuffer(t))if(t.length===1&&t[0]>127){let o=t[0]-128;s=`\x1B${String.fromCharCode(o)}`;}else s=t.toString();else s=t;if(s.length===0&&this.buffer.length===0){this.emitDataSequence("");return}if(this.buffer+=s,this.pasteMode){this.pasteBuffer+=this.buffer,this.buffer="";let o=this.pasteBuffer.indexOf(Ve);if(o!==-1){let a=this.pasteBuffer.slice(0,o),l=this.pasteBuffer.slice(o+Ve.length);this.pasteMode=false,this.pasteBuffer="",this.pendingKittyPrintableCodepoint=void 0,this.emit("paste",a),l.length>0&&this.process(l);}return}let n=this.buffer.indexOf(ts);if(n!==-1){if(n>0){let a=this.buffer.slice(0,n),l=ss(a);for(let c of l.sequences)this.emitDataSequence(c);}this.pendingKittyPrintableCodepoint=void 0,this.buffer=this.buffer.slice(n+ts.length),this.pasteMode=true,this.pasteBuffer=this.buffer,this.buffer="";let o=this.pasteBuffer.indexOf(Ve);if(o!==-1){let a=this.pasteBuffer.slice(0,o),l=this.pasteBuffer.slice(o+Ve.length);this.pasteMode=false,this.pasteBuffer="",this.pendingKittyPrintableCodepoint=void 0,this.emit("paste",a),l.length>0&&this.process(l);}return}let r=ss(this.buffer);this.buffer=r.remainder;for(let o of r.sequences)this.emitDataSequence(o);this.buffer.length>0&&(this.timeout=setTimeout(()=>{let o=this.flush();for(let a of o)this.emitDataSequence(a);},this.timeoutMs));}emitDataSequence(t){let s=t.length===1?t.codePointAt(0):void 0;if(s!==void 0&&s===this.pendingKittyPrintableCodepoint){this.pendingKittyPrintableCodepoint=void 0;return}this.pendingKittyPrintableCodepoint=gi(t),this.emit("data",t);}flush(){if(this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.buffer.length===0)return [];let t=[this.buffer];return this.buffer="",this.pendingKittyPrintableCodepoint=void 0,t}clear(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.buffer="",this.pasteMode=false,this.pasteBuffer="",this.pendingKittyPrintableCodepoint=void 0;}getBuffer(){return this.buffer}destroy(){this.clear();}};var xi=module$1.createRequire(W),vi=1e3,is="\x1B]9;4;3\x07",ns="\x1B]9;4;0;\x07",xt=class{constructor(){u(this,"wasRaw",false);u(this,"inputHandler");u(this,"resizeHandler");u(this,"_kittyProtocolActive",false);u(this,"_modifyOtherKeysActive",false);u(this,"stdinBuffer");u(this,"stdinDataHandler");u(this,"progressInterval");u(this,"writeLogPath",(()=>{let e=process.env.PI_TUI_WRITE_LOG||"";if(!e)return "";try{if(ie__namespace.statSync(e).isDirectory()){let t=new Date,s=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}_${String(t.getHours()).padStart(2,"0")}-${String(t.getMinutes()).padStart(2,"0")}-${String(t.getSeconds()).padStart(2,"0")}`;return pe__namespace.join(e,`tui-${s}-${process.pid}.log`)}}catch{}return e})());}get kittyProtocolActive(){return this._kittyProtocolActive}start(e,t){this.inputHandler=e,this.resizeHandler=t,this.wasRaw=process.stdin.isRaw||false,process.stdin.setRawMode&&process.stdin.setRawMode(true),process.stdin.setEncoding("utf8"),process.stdin.resume(),process.stdout.write("\x1B[?2004h"),process.stdout.on("resize",this.resizeHandler),process.platform!=="win32"&&process.kill(process.pid,"SIGWINCH"),this.enableWindowsVTInput(),this.queryAndEnableKittyProtocol();}setupStdinBuffer(){this.stdinBuffer=new ke({timeout:10});let e=/^\x1b\[\?(\d+)u$/;this.stdinBuffer.on("data",t=>{if(!this._kittyProtocolActive&&t.match(e)){this._kittyProtocolActive=true,Ce(true),process.stdout.write("\x1B[>7u");return}this.inputHandler&&this.inputHandler(t);}),this.stdinBuffer.on("paste",t=>{this.inputHandler&&this.inputHandler(`\x1B[200~${t}\x1B[201~`);}),this.stdinDataHandler=t=>{this.stdinBuffer.process(t);};}queryAndEnableKittyProtocol(){this.setupStdinBuffer(),process.stdin.on("data",this.stdinDataHandler),process.stdout.write("\x1B[?u"),setTimeout(()=>{!this._kittyProtocolActive&&!this._modifyOtherKeysActive&&(process.stdout.write("\x1B[>4;2m"),this._modifyOtherKeysActive=true);},150);}enableWindowsVTInput(){if(process.platform==="win32")try{let t=xi("koffi").load("kernel32.dll"),s=t.func("void* __stdcall GetStdHandle(int)"),n=t.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)"),r=t.func("bool __stdcall SetConsoleMode(void*, uint32_t)"),o=-10,a=512,l=s(o),c=new Uint32Array(1);n(l,c),r(l,c[0]|a);}catch{}}async drainInput(e=1e3,t=50){this._kittyProtocolActive&&(process.stdout.write("\x1B[<u"),this._kittyProtocolActive=false,Ce(false)),this._modifyOtherKeysActive&&(process.stdout.write("\x1B[>4;0m"),this._modifyOtherKeysActive=false);let s=this.inputHandler;this.inputHandler=void 0;let n=Date.now(),r=()=>{n=Date.now();};process.stdin.on("data",r);let o=Date.now()+e;try{for(;;){let a=Date.now(),l=o-a;if(l<=0||a-n>=t)break;await new Promise(c=>setTimeout(c,Math.min(t,l)));}}finally{process.stdin.removeListener("data",r),this.inputHandler=s;}}stop(){this.clearProgressInterval()&&process.stdout.write(ns),process.stdout.write("\x1B[?2004l"),this._kittyProtocolActive&&(process.stdout.write("\x1B[<u"),this._kittyProtocolActive=false,Ce(false)),this._modifyOtherKeysActive&&(process.stdout.write("\x1B[>4;0m"),this._modifyOtherKeysActive=false),this.stdinBuffer&&(this.stdinBuffer.destroy(),this.stdinBuffer=void 0),this.stdinDataHandler&&(process.stdin.removeListener("data",this.stdinDataHandler),this.stdinDataHandler=void 0),this.inputHandler=void 0,this.resizeHandler&&(process.stdout.removeListener("resize",this.resizeHandler),this.resizeHandler=void 0),process.stdin.pause(),process.stdin.setRawMode&&process.stdin.setRawMode(this.wasRaw);}write(e){if(process.stdout.write(e),this.writeLogPath)try{ie__namespace.appendFileSync(this.writeLogPath,e,{encoding:"utf8"});}catch{}}get columns(){return process.stdout.columns||Number(process.env.COLUMNS)||80}get rows(){return process.stdout.rows||Number(process.env.LINES)||24}moveBy(e){e>0?process.stdout.write(`\x1B[${e}B`):e<0&&process.stdout.write(`\x1B[${-e}A`);}hideCursor(){process.stdout.write("\x1B[?25l");}showCursor(){process.stdout.write("\x1B[?25h");}clearLine(){process.stdout.write("\x1B[K");}clearFromCursor(){process.stdout.write("\x1B[J");}clearScreen(){process.stdout.write("\x1B[2J\x1B[H");}setTitle(e){process.stdout.write(`\x1B]0;${e}\x07`);}setProgress(e){e?(process.stdout.write(is),this.progressInterval||(this.progressInterval=setInterval(()=>{process.stdout.write(is);},vi))):(this.clearProgressInterval(),process.stdout.write(ns));}clearProgressInterval(){return this.progressInterval?(clearInterval(this.progressInterval),this.progressInterval=void 0,true):false}};exports.Box=Qe;exports.CURSOR_MARKER=ce;exports.CancellableLoader=tt;exports.CombinedAutocompleteProvider=ze;exports.Container=Fe;exports.Editor=ht;exports.Image=dt;exports.Input=Se;exports.Key=$s;exports.KeybindingsManager=Be;exports.Loader=Le;exports.Markdown=pt;exports.ProcessTerminal=xt;exports.SelectList=we;exports.SettingsList=mt;exports.Spacer=gt;exports.StdinBuffer=ke;exports.TUI=ct;exports.TUI_KEYBINDINGS=Ot;exports.Text=ye;exports.TruncatedText=bt;exports.allocateImageId=Ys;exports.calculateImageRows=zt;exports.decodeKittyPrintable=We;exports.deleteAllKittyImages=Qs;exports.deleteKittyImage=Xs;exports.detectCapabilities=Ht;exports.encodeITerm2=qt;exports.encodeKitty=Nt;exports.fuzzyFilter=ge;exports.fuzzyMatch=Ct;exports.getCapabilities=se;exports.getCellDimensions=Ut;exports.getGifDimensions=Yt;exports.getImageDimensions=it;exports.getJpegDimensions=Gt;exports.getKeybindings=G;exports.getPngDimensions=jt;exports.getWebpDimensions=Xt;exports.hyperlink=rt;exports.imageFallback=De;exports.isFocusable=at;exports.isKeyRelease=Je;exports.isKeyRepeat=Ds;exports.isKittyProtocolActive=Ks;exports.matchesKey=X;exports.parseKey=Us;exports.renderImage=nt;exports.resetCapabilitiesCache=js;exports.setCapabilities=Gs;exports.setCellDimensions=st;exports.setKeybindings=zs;exports.setKittyProtocolActive=Ce;exports.truncateToWidth=_;exports.visibleWidth=S;exports.wrapTextWithAnsi=Y;
|