@preventive/triage 1.0.0-alpha.12 → 1.0.0-alpha.14
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/out/graph.js +5 -5
- package/out/terminal.js +29 -27
- package/out/view.css +1 -1
- package/out/view.js +111 -89
- package/package.json +2 -2
package/out/terminal.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ot=globalThis[Symbol.for("@rray/frontend")];if(!ot)throw new Error("@rray/frontend global not installed; view.js must run before lazy bundles import this wrapper");var{LitElement:it,html:D,nothing:z,unsafeCSS:ut,render:xr,StateElement:Sr,classMap:br,repeat:vr,styleMap:yr}=ot;function ct(t,e){if(t.length===0)return{argv:[],quoted:new Set};let r=[t[0]],n=new Set;e.has(0)&&n.add(0);for(let s=1;s<t.length;s++){let o=t[s];if(e.has(s)){n.add(r.length),r.push(o);continue}for(let i of lt(o))r.push(i)}return{argv:r,quoted:n}}function lt(t){for(let e=0;e<t.length;e++){if(t[e]!=="{")continue;let r=ie(t,e);if(r===-1)continue;let n=ue(t.slice(e+1,r));if(n.length<2)continue;let s=t.slice(0,e),o=t.slice(r+1),i=[];for(let u of n)i.push(...lt(s+u+o));return i}return[t]}function ie(t,e){let r=1;for(let n=e+1;n<t.length;n++)if(t[n]==="{")r++;else if(t[n]==="}"&&(r--,r===0))return n;return-1}function ue(t){let e=[],r=0,n=0;for(let s=0;s<t.length;s++)t[s]==="{"?r++:t[s]==="}"?r--:t[s]===","&&r===0&&(e.push(t.slice(n,s)),n=s+1);return e.push(t.slice(n)),e}function at(t){let e=de(t);for(let s of e)if(s.kind==="amp")throw new Error("background processes (`&`) are not supported");for(;e.length>0&&e.at(-1).kind==="semi";)e.pop();let{steps:r,consumed:n}=dt(e,0,!1);if(n!==e.length)throw new Error("unexpected `)`");return ft(r),r}function ft(t){for(let e of t){if(e.stages.length===0)throw new Error("empty pipeline stage");for(let r of e.stages)if(r.group)ft(r.group);else if(r.argv.length===0)throw new Error("empty pipeline stage")}}function dt(t,e,r){let n=[{gate:"first",stages:[]}],s={argv:[],quoted:new Set},o=e;for(;o<t.length;){let i=t[o];if(i.kind==="paren_close"){if(!r)throw new Error("unexpected `)`");return ce(n,s,o+1)}if(i.kind==="paren_open"){if(s.group||s.argv.length>0)throw new Error("unexpected `(`");let u=dt(t,o+1,!0);s.group=u.steps,o=u.consumed;continue}if(i.kind==="pipe"||i.kind==="and"||i.kind==="or"||i.kind==="semi"){n.at(-1).stages.push(s),s={argv:[],quoted:new Set},i.kind==="and"?n.push({gate:"and",stages:[]}):i.kind==="or"?n.push({gate:"or",stages:[]}):i.kind==="semi"&&n.push({gate:"seq",stages:[]}),o++;continue}if(i.kind==="redir"){o=ae(s,t,o)+1;continue}if(s.group)throw new Error("unexpected token after `)`");i.quoted&&s.quoted.add(s.argv.length),s.argv.push(i.value),o++}if(r)throw new Error("unmatched `(`");return n.at(-1).stages.push(s),{steps:n,consumed:o}}function ce(t,e,r){let n=t.at(-1);if(!e.group&&e.argv.length===0&&!le(e)&&n.stages.length===0){if(t.length===1)throw new Error("empty subshell `()`");t.pop()}else n.stages.push(e);return{steps:t,consumed:r}}function le(t){return!!(t.stdoutToNull||t.stderrToNull||t.mergeStderrToStdout||t.mergeStdoutToStderr)}function ae(t,e,r){let n=e[r],s=n.fd==="1"?"":n.fd;if(n.toFd)return n.fd==="2"&&n.toFd==="1"?t.mergeStderrToStdout=!0:n.fd==="1"&&n.toFd==="2"&&(t.mergeStdoutToStderr=!0),r;let o=e[r+1],i=s+">"+(n.append?">":"");if(n.append)throw new Error(`filesystem is read-only \u2014 \`${i}\` append is not supported; use \`|\` to pipe or \`${s}>/dev/null\` to discard`);if(!o||o.kind!=="word")throw new Error(`redirect \`${i}\` requires a target`);if(o.value!=="/dev/null")throw new Error(`filesystem is read-only \u2014 use \`|\` to pipe between commands, or \`${i}/dev/null\` to discard`);return n.fd==="1"?t.stdoutToNull=!0:t.stderrToNull=!0,r+1}var fe=new Set(["semi","and","or","pipe","paren_open"]);function de(t){let e=[],r="",n=null,s=!1,o=!1,i=()=>{s&&e.push({kind:"word",value:r,quoted:o}),r="",s=!1,o=!1};for(let u=0;u<t.length;u++){let c=t[u];if(n){c===n?n=null:r+=c;continue}if(c==="'"||c==='"'){n=c,s=!0,o=!0;continue}if(!s&&(c==="1"||c==="2")&&t[u+1]===">"){if(i(),t[u+2]==="&"){let l=t[u+3],a=t[u+4];if((l==="1"||l==="2")&&(a===void 0||/[\s|&>;()]/u.test(a))){e.push({kind:"redir",fd:c,toFd:l}),u+=3;continue}throw new Error(`redirect \`${c}>&\` requires fd 1 or 2 followed by a token boundary`)}t[u+2]===">"?(e.push({kind:"redir",fd:c,append:!0}),u+=2):(e.push({kind:"redir",fd:c,append:!1}),u+=1);continue}if(c==="|"){i(),t[u+1]==="|"?(e.push({kind:"or"}),u++):e.push({kind:"pipe"});continue}if(c==="&"){i(),t[u+1]==="&"?(e.push({kind:"and"}),u++):e.push({kind:"amp"});continue}if(c===">"){i(),t[u+1]===">"?(e.push({kind:"redir",fd:"1",append:!0}),u++):e.push({kind:"redir",fd:"1",append:!1});continue}if(c===";"){i(),e.push({kind:"semi"});continue}if(c==="("){i(),e.push({kind:"paren_open"});continue}if(c===")"){i(),e.push({kind:"paren_close"});continue}if(c===`
|
|
2
|
+
`){i();let l=e.at(-1);l&&!fe.has(l.kind)&&e.push({kind:"semi"});continue}if(/\s/u.test(c)){i();continue}r+=c,s=!0}if(n)throw new Error(`unterminated ${n==="'"?"single":"double"} quote`);return i(),e}function g(t,e={}){let r=W(e.short),n=W(e.long),s=W(e.valueShort),o=W(e.valueLong),i=W(e.repeatable),u=e.stopAtFirstPositional??!1,c=new Set,l=new Map,a=[],f=[];for(let d=0;d<t.length;d++){let p=t[d];if(p==="--"){a.push(...t.slice(d+1));break}if(/^-+$/u.test(p)){a.push(p);continue}if(/\s/u.test(p)){a.push(p);continue}if(p.startsWith("--")&&p.length>2){let m=p.indexOf("="),w=m===-1?p.slice(2):p.slice(2,m),b=m===-1?null:p.slice(m+1);if(o.has(w)||i.has(w)){let y=b??ht(t,++d,`--${w}`);Y(l,i,w,y),f.push({name:w,value:y})}else if(n.has(w)){if(b!==null)throw new Error(`option --${w} doesn't allow an argument`);c.add(w)}else throw new Error(`unknown option: --${w}`);continue}if(p.startsWith("-")&&p.length>1&&!/^-\d/u.test(p)){d=he(t,d,r,s,i,c,l);continue}if(u){a.push(...t.slice(d));break}a.push(p)}return{flags:c,values:l,positional:a,order:f}}function W(t){return t instanceof Set?t:new Set(t??[])}function ht(t,e,r){if(e>=t.length)throw new Error(`${r} requires an argument`);return t[e]}function Y(t,e,r,n){if(!e.has(r)){t.set(r,n);return}let s=t.get(r);s?s.push(n):t.set(r,[n])}function he(t,e,r,n,s,o,i){let u=t[e].slice(1);for(let c=0;c<u.length;c++){let l=u[c];if(n.has(l)||s.has(l))return c+1<u.length?(Y(i,s,l,u.slice(c+1)),e):(Y(i,s,l,ht(t,++e,`-${l}`)),e);if(!r.has(l))throw new Error(`unknown option: -${l}`);o.add(l)}return e}function O(t){let e=t.startsWith("/"),r=t.split("/").filter(Boolean),n=[];for(let s of r)if(s!=="."){if(s===".."){n.length>0&&n.at(-1)!==".."?n.pop():e||n.push("..");continue}n.push(s)}return e?"/"+n.join("/"):n.length===0?".":n.join("/")}function x(t,e){return e.startsWith("/")?O(e):O(t+"/"+e)}function L(t){let e=O(t);if(e==="/")return"/";let r=e.lastIndexOf("/");return r<0?".":r===0?"/":e.slice(0,r)}function A(t){let e=O(t);if(e==="/")return"/";let r=e.lastIndexOf("/");return e.slice(r+1)}function M(t,e){return t==="/"?"/"+e:t+"/"+e}function R(t,e){return t==="/"?e.slice(1):e.slice(t.length+1)}function pt(t){let e=new Map,r=t instanceof Map?t.entries():Object.entries(t??{});for(let[o,i]of r)typeof i=="string"&&e.set(O("/"+String(o)),i);let n=new Map([["/",{dirs:[],files:[]}]]);for(let o of e.keys()){let i=L(o);me(n,i),n.get(i).files.push(A(o))}for(let o of n.values())o.dirs.sort(),o.files.sort();let s={isFile:o=>e.has(o),isDir:o=>n.has(o),readFile:o=>e.get(o),listDir:o=>{let i=n.get(o);if(!i)throw new Error(`not a directory: ${o}`);return i},walkFiles:o=>pe(s,o)};return s}function*V(t,e,r=Number.POSITIVE_INFINITY){if(t.isFile(e)){yield{path:e,kind:"file",depth:0};return}if(!t.isDir(e))return;yield{path:e,kind:"dir",depth:0};let n=[{path:e,depth:0}];for(let s=0;s<n.length;s++){let o=n[s];if(o.depth>=r)continue;let{dirs:i,files:u}=t.listDir(o.path),c=o.depth+1;for(let l of i){let a=M(o.path,l);yield{path:a,kind:"dir",depth:c},n.push({path:a,depth:c})}for(let l of u)yield{path:M(o.path,l),kind:"file",depth:c}}}function*pe(t,e){for(let r of V(t,e))r.kind==="file"&&(yield r.path)}function me(t,e){let r=[],n=e;for(;n!=="/"&&!t.has(n);)r.push(n),n=L(n);for(let s=r.length-1;s>=0;s--){let o=r[s];t.set(o,{dirs:[],files:[]}),t.get(L(o)).dirs.push(A(o))}}var S=(t="")=>({stdout:t,stderr:"",exitCode:0}),h=(t,e=1)=>({stdout:"",stderr:t.endsWith(`
|
|
2
3
|
`)?t:t+`
|
|
3
|
-
`,exitCode:e}),
|
|
4
|
-
`);return e.at(-1)===""&&e.pop(),e}var
|
|
4
|
+
`,exitCode:e}),E=t=>h(`usage: ${t}`,2);function $(t){if(t==="")return[];let e=t.split(`
|
|
5
|
+
`);return e.at(-1)===""&&e.pop(),e}var k=t=>t.length===0?"":t.join(`
|
|
5
6
|
`)+`
|
|
6
|
-
`;function
|
|
7
|
+
`;function Z(t,e,r){let n=[],s="",o=!1;for(let i of e){let u=x(r.cwd,i);if(r.fs.isDir(u)){s+=`${t}: ${i}: is a directory
|
|
7
8
|
`,o=!0;continue}if(!r.fs.isFile(u)){s+=`${t}: ${i}: no such file or directory
|
|
8
|
-
`,o=!0;continue}n.push({name:i,content:r.fs.readFile(u)})}return{inputs:n,stderr:s,failed:o}}function
|
|
9
|
-
`:o==="t"?" ":o==="\\"?"\\":o==="0"?"\0":o};for(;n<e.length;){let o=s();if(o===null)return{error:d("tr: trailing backslash in set")};if(e[n]==="-"&&n+1<e.length){n++;let i=s();if(i===null)return{error:d("tr: trailing backslash in set")};let u=o.codePointAt(0),c=i.codePointAt(0);if(c<u)return{error:d(`tr: reversed range: ${o}-${i}`)};for(let a=u;a<=c;a++)r.push(String.fromCodePoint(a))}else r.push(o)}return{chars:r}}function ie(t,e){let r="",n=null;for(let s of t)e.has(s)&&s===n||(r+=s,n=s);return r}function ue(t,e,r){let{positional:n}=m(e);if(n.length===0)return k("which COMMAND...");let s=[],o=0;for(let i of n)r.hasCommand(i)?s.push(`/usr/bin/${i}`):(s.push(`${i} not found`),o=1);return{stdout:$(s),stderr:"",exitCode:o}}function ce(t,e,r){let{positional:n}=m(e);return n.length>0?d(`whoami: extra operand: ${n[0]}`):w((r.user??"user")+`
|
|
10
|
-
`)}function ae(t,e){let{flags:r,positional:n}=m(e,{short:["u"]});if(n.length>1)return d(`date: at most one +FORMAT argument is supported (got: ${n[1]})`);let s="%a %b %e %T %Z %Y";if(n.length===1){if(!n[0].startsWith("+"))return k("date [-u] [+FORMAT]");s=n[0].slice(1)}return w(pe(new Date,s,r.has("u"))+`
|
|
11
|
-
`)}var le=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],fe=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],he=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],de=["January","February","March","April","May","June","July","August","September","October","November","December"];function pe(t,e,r){let n=r?{Y:t.getUTCFullYear(),M:t.getUTCMonth(),D:t.getUTCDate(),h:t.getUTCHours(),m:t.getUTCMinutes(),s:t.getUTCSeconds(),w:t.getUTCDay()}:{Y:t.getFullYear(),M:t.getMonth(),D:t.getDate(),h:t.getHours(),m:t.getMinutes(),s:t.getSeconds(),w:t.getDay()},s=(o,i="0")=>String(o).padStart(2,i);return e.replace(/%./gu,o=>{switch(o[1]){case"Y":return String(n.Y);case"m":return s(n.M+1);case"d":return s(n.D);case"e":return s(n.D," ");case"H":return s(n.h);case"M":return s(n.m);case"S":return s(n.s);case"T":return`${s(n.h)}:${s(n.m)}:${s(n.s)}`;case"F":return`${n.Y}-${s(n.M+1)}-${s(n.D)}`;case"s":return String(Math.floor(t.getTime()/1e3));case"a":return le[n.w];case"A":return fe[n.w];case"b":return he[n.M];case"B":return de[n.M];case"Z":return me(t,r);case"z":return ge(t,r);case"n":return`
|
|
12
|
-
`;case"t":return" ";case"%":return"%";default:return o}})}function me(t,e){if(e)return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZoneName:"short"}).formatToParts(t).find(s=>s.type==="timeZoneName")?.value??"Local"}catch{return"Local"}}function ge(t,e){if(e)return"+0000";let r=-t.getTimezoneOffset(),n=r>=0?"+":"-",s=Math.abs(r);return`${n}${String(Math.floor(s/60)).padStart(2,"0")}${String(s%60).padStart(2,"0")}`}var ht={cut:ne,tac:Qt,tr:oe,seq:te,nl:ee,which:ue},dt={whoami:ce,date:ae};var mt=/[*?]/u,pt=/[.+*?^${}()|[\]\\]/u;function Y(t){let e="^";for(let r=0;r<t.length;r++){let n=t[r];if(n==="\\"&&r+1<t.length){let s=t[r+1];e+=pt.test(s)?"\\"+s:s,r++}else n==="*"?e+=".*":n==="?"?e+=".":pt.test(n)?e+="\\"+n:e+=n}return new RegExp(e+"$","u")}function gt(t,e,r){if(t.length===0)return[];let n=[t[0]];for(let s=1;s<t.length;s++){let o=t[s];if(e.has(s)||!mt.test(o)){n.push(o);continue}let i=we(o,r);i.length>0?n.push(...i):n.push(o)}return n}function we(t,e){let r=t.startsWith("/"),n=t.startsWith("./"),s=t.endsWith("/")&&t.length>1,o=t.split("/").filter(Boolean);if(o.length===0)return r?["/"]:[];let i=[r?"/":"."];for(let u=0;u<o.length;u++){let c=o[u];if(!mt.test(c)){i=i.map(a=>z(a,c));continue}i=be(i,c,u===o.length-1,e)}return s?i=i.filter(u=>e.fs.isDir(x(e.cwd,u))).map(u=>u==="/"?u:u+"/"):i=i.filter(u=>xe(u,e)),n&&(i=i.map(u=>u.startsWith("./")?u:"./"+u)),i.sort(),i}function xe(t,e){let r=x(e.cwd,t);return e.fs.isFile(r)||e.fs.isDir(r)}function be(t,e,r,n){let s=Y(e),o=e.startsWith("."),i=c=>!o&&c.startsWith(".")?!1:s.test(c),u=[];for(let c of t){let a=x(n.cwd,c);if(!n.fs.isDir(a))continue;let{dirs:l,files:f}=n.fs.listDir(a);for(let h of l)i(h)&&u.push(z(c,h));if(r)for(let h of f)i(h)&&u.push(z(c,h))}return u}function z(t,e){return t==="."?e:A(t,e)}var wt=new Set(["name","type","path","mindepth","maxdepth"]);function xt(t,e,r){let n=Se(e);if(n.error)return n.error;let{starts:s,minDepth:o,maxDepth:i,groups:u,hasExec:c,batches:a}=n,l=[],f="",h="",p=0;for(let g of s){let y=x(r.cwd,g);if(!r.fs.isDir(y)&&!r.fs.isFile(y)){h+=`find: ${g}: no such file or directory
|
|
13
|
-
`,p=1;continue}for(let S of G(r.fs,y,i)){if(S.depth<o)continue;let C=Ae(g,y,S.path),N=Ce(u,{kind:S.kind,path:C},r);f+=N.stdout,h+=N.stderr,N.matched&&!c&&l.push(C)}}for(let g of a){if(g.collected.length===0)continue;let y=g.args.slice(0,-1).concat(g.collected),S=r.dispatch(g.cmd,y,"");f+=S.stdout,h+=S.stderr,S.exitCode!==0&&(p=1)}return{stdout:(l.length===0?"":l.join(`
|
|
9
|
+
`,o=!0;continue}n.push({name:i,content:r.fs.readFile(u)})}return{inputs:n,stderr:s,failed:o}}function _(t,e,r,n){return e.length===0?{inputs:[{name:null,content:r}],stderr:"",failed:!1}:Z(t,e,n)}function N(t,e,r,n){let s=_(t,e,r,n);return{content:s.inputs.map(o=>o.content).join(""),stderr:s.stderr,failed:s.failed}}var v=(t,e)=>({stdout:t,stderr:e.stderr,exitCode:e.failed?1:0});function T(t,e){if(typeof t!="string"||!/^\d+$/u.test(t))return{error:h(`${e}: invalid count: ${t}`)};let r=Number(t);return Number.isSafeInteger(r)?{value:r}:{error:h(`${e}: out of range: ${t}`)}}var ge=new TextEncoder,P=16,we=47,xe=39;function wt(t,e,r){let{flags:n,values:s,positional:o}=g(e,{short:["C","v"],valueShort:["n","s"]}),i=K("hexdump",o,t,r,{skip:s.get("s"),len:s.get("n"),skipFlag:"-s",lenFlag:"-n"});return i.error?i.error:v(Q(i.bytes,i.start,n.has("v"),n.has("C")?be:Se),i.r)}function xt(t,e,r){let{flags:n,values:s,positional:o}=g(e,{short:["v"],valueShort:["j","N"]}),i=K("od",o,t,r,{skip:s.get("j"),len:s.get("N"),skipFlag:"-j",lenFlag:"-N",skipPastEofErrors:!0});return i.error?i.error:v(Q(i.bytes,i.start,n.has("v"),ve),i.r)}function St(t,e,r){let{values:n,positional:s}=g(e,{valueShort:["s","l"]}),o=K("xxd",s,t,r,{skip:n.get("s"),len:n.get("l"),skipFlag:"-s",lenFlag:"-l"});return o.error?o.error:v(Q(o.bytes,o.start,!1,ye),o.r)}function K(t,e,r,n,s){let o=N(t,e,r,n),i=ge.encode(o.content),u=0;if(s.skip!==void 0){let l=T(s.skip,`${t}: ${s.skipFlag}`);if(l.error)return{error:l.error};if(s.skipPastEofErrors&&l.value>i.length)return{error:h(`${t}: cannot skip past end of combined input`)};u=Math.min(l.value,i.length)}let c=i.subarray(u);if(s.len!==void 0){let l=T(s.len,`${t}: ${s.lenFlag}`);if(l.error)return{error:l.error};c=c.subarray(0,l.value)}return{bytes:c,start:u,r:o}}function Q(t,e,r,n){let s=[],o=null,i=!1;for(let c=0;c<t.length;c+=P){let l=t.subarray(c,c+P);n.compress&&!r&&o!==null&&l.length===P&&Te(l,o)?i||(s.push("*"),i=!0):(s.push(n.row(e+c,l)),i=!1),o=l}let u=e+t.length;return(n.trailer==="always"||n.trailer==="nonzero"&&u>0)&&s.push(n.addr(u)),s.length===0?"":s.join(`
|
|
14
10
|
`)+`
|
|
15
|
-
`)+
|
|
16
|
-
|
|
11
|
+
`}var Se={compress:!0,trailer:"nonzero",addr:mt,row:(t,e)=>(mt(t)+" "+bt(e).map(Ee).join(" ")).padEnd(we)},be={compress:!0,trailer:"nonzero",addr:q,row:$e},ve={compress:!0,trailer:"always",addr:gt,row:(t,e)=>gt(t)+" "+bt(e).map(_e).join(" ")},ye={compress:!1,trailer:"never",addr:q,row:(t,e)=>`${q(t)}: ${ke(e).join(" ").padEnd(xe)} ${vt(e)}`};function mt(t){return t.toString(16).padStart(7,"0")}function q(t){return t.toString(16).padStart(8,"0")}function gt(t){return t.toString(8).padStart(7,"0")}function $e(t,e){let r=[];for(let o=0;o<P;o++)r.push(o<e.length?J(e[o]):" ");let n=r.slice(0,8).join(" "),s=r.slice(8).join(" ");return`${q(t)} ${n} ${s} |${vt(e)}|`}function bt(t){let e=[];for(let r=0;r<t.length;r+=2)e.push(r+1<t.length?t[r]|t[r+1]<<8:t[r]);return e}function ke(t){let e=[];for(let r=0;r<t.length;r+=2)e.push(J(t[r])+(r+1<t.length?J(t[r+1]):""));return e}function vt(t){let e="";for(let r of t)e+=r>=32&&r<=126?String.fromCodePoint(r):".";return e}function Te(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}var J=t=>t.toString(16).padStart(2,"0"),Ee=t=>t.toString(16).padStart(4,"0"),_e=t=>t.toString(8).padStart(6,"0");function Ce(t,e,r){let{positional:n}=g(e),s=_("tac",n,t,r),o=[];for(let{content:i}of s.inputs)o.push(...$(i).toReversed());return v(k(o),s)}var yt=1e6;function De(t,e){let{positional:r}=g(e);if(r.length===0||r.length>3)return E("seq LAST | seq FIRST LAST | seq FIRST INCR LAST");let n=[];for(let a of r){if(!/^-?\d+$/u.test(a))return h(`seq: invalid integer: ${a}`);n.push(Number(a))}let s,o,i;if(n.length===1?(s=1,o=1,i=n[0]):n.length===2?(s=n[0],i=n[1],o=s<=i?1:-1):[s,o,i]=n,o===0)return h("seq: increment must be non-zero");let c=(o>0?s<=i:s>=i)?Math.floor(Math.abs(i-s)/Math.abs(o))+1:0;if(c>yt)return h(`seq: range too large: ${c} elements exceeds limit of ${yt}`);let l=[];if(o>0)for(let a=s;a<=i;a+=o)l.push(String(a));else for(let a=s;a>=i;a+=o)l.push(String(a));return S(k(l))}function Me(t,e,r){let{values:n,positional:s}=g(e,{valueShort:["b"]}),o=n.get("b")??"t";if(o!=="a"&&o!=="t")return h(`nl: -b: only \`a\` and \`t\` are supported (got \`${o}\`)`);let i=_("nl",s,t,r),u=[],c=0;for(let{content:l}of i.inputs)for(let a of $(l))o==="a"||a!==""?(c++,u.push(`${String(c).padStart(6)} ${a}`)):u.push(a);return v(k(u),i)}function Ae(t,e,r){let{values:n,positional:s}=g(e,{valueShort:["d","f","c"]}),o=n.has("f"),i=n.has("c");if(o===i)return E("cut -f LIST [-d DELIM] [file...] | cut -c LIST [file...]");if(i&&n.has("d"))return h("cut: -d is only valid with -f");let u=Ne(o?n.get("f"):n.get("c"));if(u.error)return u.error;let c=n.get("d")??" ";if(o&&c.length!==1)return h("cut: -d delimiter must be a single character");let l=_("cut",s,t,r),a=[];for(let{content:f}of l.inputs)for(let d of $(f))a.push(o?Fe(d,c,u.ranges):kt([...d],u.ranges).join(""));return v(k(a),l)}function Ne(t){let e=[];for(let r of t.split(",")){if(r==="")return{error:h(`cut: empty list item in \`${t}\``)};if(/^\d+$/u.test(r)){let i=Number(r);if(i<1)return{error:h("cut: list items must be >= 1")};e.push([i,i]);continue}let n=r.match(/^(\d*)-(\d*)$/u);if(!n||n[1]===""&&n[2]==="")return{error:h(`cut: invalid list item: ${r}`)};let s=n[1]===""?1:Number(n[1]),o=n[2]===""?Number.POSITIVE_INFINITY:Number(n[2]);if(s<1)return{error:h("cut: list items must be >= 1")};if(o<s)return{error:h(`cut: reversed range: ${r}`)};e.push([s,o])}return{ranges:e}}function kt(t,e){let r=new Set,n=[];for(let[s,o]of e)for(let i=s;i<=Math.min(o,t.length);i++)r.has(i)||(r.add(i),n.push(i));return n.sort((s,o)=>s-o),n.map(s=>t[s-1])}function Fe(t,e,r){let n=t.split(e);return n.length===1?t:kt(n,r).join(e)}function Ie(t,e){let{flags:r,positional:n}=g(e,{short:["d","s"]}),s=r.has("d"),o=r.has("s");if(s&&o)return h("tr: -d combined with -s is not supported");let i=s||o?1:2;if(n.length!==i)return E("tr SET1 SET2 | tr -d SET | tr -s SET");let u=$t(n[0]);if(u.error)return u.error;if(s){let f=new Set(u.chars);return S([...t].filter(d=>!f.has(d)).join(""))}if(o)return S(We(t,new Set(u.chars)));let c=$t(n[1]);if(c.error)return c.error;if(c.chars.length===0)return h("tr: SET2 must not be empty");let l=new Map,a=c.chars.at(-1);for(let f=0;f<u.chars.length;f++)l.set(u.chars[f],c.chars[f]??a);return S([...t].map(f=>l.get(f)??f).join(""))}function $t(t){let e=[...t],r=[],n=0,s=()=>{if(e[n]!=="\\")return e[n++];if(n+1>=e.length)return null;let o=e[n+1];return n+=2,o==="n"?`
|
|
12
|
+
`:o==="t"?" ":o==="\\"?"\\":o==="0"?"\0":o};for(;n<e.length;){let o=s();if(o===null)return{error:h("tr: trailing backslash in set")};if(e[n]==="-"&&n+1<e.length){n++;let i=s();if(i===null)return{error:h("tr: trailing backslash in set")};let u=o.codePointAt(0),c=i.codePointAt(0);if(c<u)return{error:h(`tr: reversed range: ${o}-${i}`)};for(let l=u;l<=c;l++)r.push(String.fromCodePoint(l))}else r.push(o)}return{chars:r}}function We(t,e){let r="",n=null;for(let s of t)e.has(s)&&s===n||(r+=s,n=s);return r}function Oe(t,e,r){let{positional:n}=g(e);if(n.length===0)return E("which COMMAND...");let s=[],o=0;for(let i of n)r.hasCommand(i)?s.push(`/usr/bin/${i}`):(s.push(`${i} not found`),o=1);return{stdout:k(s),stderr:"",exitCode:o}}function Le(t,e,r){let{positional:n}=g(e);return n.length>0?h(`whoami: extra operand: ${n[0]}`):S((r.user??"user")+`
|
|
13
|
+
`)}function Re(t,e){let{flags:r,positional:n}=g(e,{short:["u"]});if(n.length>1)return h(`date: at most one +FORMAT argument is supported (got: ${n[1]})`);let s="%a %b %e %T %Z %Y";if(n.length===1){if(!n[0].startsWith("+"))return E("date [-u] [+FORMAT]");s=n[0].slice(1)}return S(He(new Date,s,r.has("u"))+`
|
|
14
|
+
`)}var je=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Pe=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],qe=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Be=["January","February","March","April","May","June","July","August","September","October","November","December"];function He(t,e,r){let n=r?{Y:t.getUTCFullYear(),M:t.getUTCMonth(),D:t.getUTCDate(),h:t.getUTCHours(),m:t.getUTCMinutes(),s:t.getUTCSeconds(),w:t.getUTCDay()}:{Y:t.getFullYear(),M:t.getMonth(),D:t.getDate(),h:t.getHours(),m:t.getMinutes(),s:t.getSeconds(),w:t.getDay()},s=(o,i="0")=>String(o).padStart(2,i);return e.replace(/%./gu,o=>{switch(o[1]){case"Y":return String(n.Y);case"m":return s(n.M+1);case"d":return s(n.D);case"e":return s(n.D," ");case"H":return s(n.h);case"M":return s(n.m);case"S":return s(n.s);case"T":return`${s(n.h)}:${s(n.m)}:${s(n.s)}`;case"F":return`${n.Y}-${s(n.M+1)}-${s(n.D)}`;case"s":return String(Math.floor(t.getTime()/1e3));case"a":return je[n.w];case"A":return Pe[n.w];case"b":return qe[n.M];case"B":return Be[n.M];case"Z":return Ge(t,r);case"z":return Xe(t,r);case"n":return`
|
|
15
|
+
`;case"t":return" ";case"%":return"%";default:return o}})}function Ge(t,e){if(e)return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZoneName:"short"}).formatToParts(t).find(s=>s.type==="timeZoneName")?.value??"Local"}catch{return"Local"}}function Xe(t,e){if(e)return"+0000";let r=-t.getTimezoneOffset(),n=r>=0?"+":"-",s=Math.abs(r);return`${n}${String(Math.floor(s/60)).padStart(2,"0")}${String(s%60).padStart(2,"0")}`}var Tt={cut:Ae,tac:Ce,tr:Ie,seq:De,nl:Me,which:Oe,hexdump:wt},Et={whoami:Le,date:Re,od:xt,xxd:St};var Ct=/[*?]/u,_t=/[.+*?^${}()|[\]\\]/u;function F(t){let e="^";for(let r=0;r<t.length;r++){let n=t[r];if(n==="\\"&&r+1<t.length){let s=t[r+1];e+=_t.test(s)?"\\"+s:s,r++}else n==="*"?e+=".*":n==="?"?e+=".":_t.test(n)?e+="\\"+n:e+=n}return new RegExp(e+"$","u")}function Dt(t,e,r){if(t.length===0)return[];let n=[t[0]];for(let s=1;s<t.length;s++){let o=t[s];if(e.has(s)||!Ct.test(o)){n.push(o);continue}let i=Ue(o,r);i.length>0?n.push(...i):n.push(o)}return n}function Ue(t,e){let r=t.startsWith("/"),n=t.startsWith("./"),s=t.endsWith("/")&&t.length>1,o=t.split("/").filter(Boolean);if(o.length===0)return r?["/"]:[];let i=[r?"/":"."];for(let u=0;u<o.length;u++){let c=o[u];if(!Ct.test(c)){i=i.map(l=>tt(l,c));continue}i=Ye(i,c,u===o.length-1,e)}return s?i=i.filter(u=>e.fs.isDir(x(e.cwd,u))).map(u=>u==="/"?u:u+"/"):i=i.filter(u=>ze(u,e)),n&&(i=i.map(u=>u.startsWith("./")?u:"./"+u)),i.sort(),i}function ze(t,e){let r=x(e.cwd,t);return e.fs.isFile(r)||e.fs.isDir(r)}function Ye(t,e,r,n){let s=F(e),o=e.startsWith("."),i=c=>!o&&c.startsWith(".")?!1:s.test(c),u=[];for(let c of t){let l=x(n.cwd,c);if(!n.fs.isDir(l))continue;let{dirs:a,files:f}=n.fs.listDir(l);for(let d of a)i(d)&&u.push(tt(c,d));if(r)for(let d of f)i(d)&&u.push(tt(c,d))}return u}function tt(t,e){return t==="."?e:M(t,e)}var Mt=new Set(["name","type","path","mindepth","maxdepth"]),I=(t,e)=>t==="-"+e||t==="--"+e;function At(t,e,r){let n=Ve(e);if(n.error)return n.error;let{starts:s,minDepth:o,maxDepth:i,groups:u,batches:c}=n,l="",a="",f=0;for(let d of s){let p=x(r.cwd,d);if(!r.fs.isDir(p)&&!r.fs.isFile(p)){a+=`find: ${d}: no such file or directory
|
|
16
|
+
`,f=1;continue}for(let m of V(r.fs,p,i)){if(m.depth<o)continue;let w=on(d,p,m.path),b=en(u,{kind:m.kind,path:w},r);l+=b.stdout,a+=b.stderr}}for(let d of c){if(d.collected.length===0)continue;let p=d.args.slice(0,-1).concat(d.collected),m=r.dispatch(d.cmd,p,"");l+=m.stdout,a+=m.stderr,m.exitCode!==0&&(f=1)}return{stdout:l,stderr:a,exitCode:f}}function Ve(t){let e=Ze(t);if(e.error)return e;let r=Je(e.tokens,e.minDepth,e.maxDepth);if(r.error)return r;if(!r.hasAction)for(let n of r.groups)n.push({kind:"print",negate:!1});return r}function Ze(t){let e=[],r=0,n=Number.POSITIVE_INFINITY;for(let s=0;s<t.length;s++){let o=t[s],i=I(o,"mindepth")?"mindepth":I(o,"maxdepth")?"maxdepth":null;if(i){if(s+1>=t.length)return{error:h(`find: -${i} requires a value`)};let u=T(t[s+1],`find: -${i}`);if(u.error)return u;i==="mindepth"?r=u.value:n=u.value,s++;continue}if(o==="--"){e.push(...t.slice(s));break}e.push(o)}return{tokens:e,minDepth:r,maxDepth:n}}function Je(t,e,r){let n=[[]],s=[],o=!1,i=!1,u=!1,c=null,l=!1,a=[];for(let f=0;f<t.length;f++){let d=t[f];if(i){s.push(d);continue}if(d==="-not"||d==="!"){if(o)return{error:h("find: `-not` cannot precede another `-not`")};o=!0,u=!0;continue}if(d==="-a"||I(d,"and")){if(o)return{error:h("find: `-not` must be followed by a primary")};if(c)return{error:h(`find: \`${c}\` with no right-hand expression`)};if(n.at(-1).length===0)return{error:h("find: `-a` with no left-hand expression")};c="-a",u=!0;continue}if(d==="-o"||I(d,"or")){if(o)return{error:h("find: `-not` must be followed by a primary")};if(c)return{error:h(`find: \`${c}\` with no right-hand expression`)};if(n.at(-1).length===0)return{error:h("find: `-o` with no left-hand expression")};n.push([]),c="-o",u=!0;continue}if(I(d,"print")){n.at(-1).push({kind:"print",negate:o}),l=!0,o=!1,c=null,u=!0;continue}if(I(d,"exec")){let m=tn(t,f,o);if(m.error)return m;n.at(-1).push(m.pred),l=!0,m.pred.mode==="batch"&&a.push(m.pred),o=!1,c=null,u=!0,f=m.nextI;continue}let p=Ke(d);if(p!==null){if(f+1>=t.length)return{error:h(`find: ${d} requires a value`)};let m=t[f+1],w=Qe(p,m);if(w.error)return w;let b={kind:p,value:m,negate:o};(p==="name"||p==="path")&&(b.re=F(m)),n.at(-1).push(b),o=!1,c=null,u=!0,f++;continue}if(d==="--"){i=!0;continue}if(o)return{error:h(`find: \`-not\` must be followed by a primary, got: ${d}`)};if(d.startsWith("-")&&d!=="-"&&!/^-\d/u.test(d))return{error:h(`find: unknown option: ${d}`)};if(u)return{error:h(`find: paths must precede expression: ${d}`)};s.push(d)}return o?{error:h("find: trailing `-not` with no primary")}:c?{error:h(`find: \`${c}\` with no right-hand expression`)}:{starts:s.length>0?s:["."],minDepth:e,maxDepth:r,groups:n,hasAction:l,batches:a}}function Ke(t){return/^--?(?:min|max)depth$/u.test(t)?null:t.startsWith("--")&&Mt.has(t.slice(2))?t.slice(2):t.startsWith("-")&&Mt.has(t.slice(1))?t.slice(1):null}function Qe(t,e){return t==="type"&&e!=="f"&&e!=="d"?{error:h(`find: -type/--type expects 'f' or 'd', got: ${e}`)}:{}}function tn(t,e,r){let n=e+1;for(;n<t.length&&t[n]!==";"&&t[n]!=="+";)n++;if(n>=t.length)return{error:h("find: -exec: missing terminator (`;` or `+`); use `';'` (quoted) \u2014 bare `\\;` is consumed by the shell as a step separator")};if(n===e+1)return{error:h("find: -exec: requires a command")};let s=t.slice(e+1,n),o=t[n]===";"?"each":"batch";if(o==="batch"){if(s.at(-1)!=="{}")return{error:h("find: -exec ... +: `{}` must be the last argument before `+`")};if(s.slice(0,-1).includes("{}"))return{error:h("find: -exec ... +: only one instance of `{}` is supported")};if(r)return{error:h("find: `-not -exec ... +` is not supported (the `+` form has no meaningful negation)")}}let i={kind:"exec",mode:o,cmd:s[0],args:s.slice(1),negate:r};return o==="batch"&&(i.collected=[]),{pred:i,nextI:n}}function en(t,e,r){let n="",s="";for(let o of t){let i=!0;for(let u of o){let c=nn(u,e,r);if(n+=c.stdout,s+=c.stderr,!c.matched){i=!1;break}}if(i)break}return{stdout:n,stderr:s}}function nn(t,e,r){let n=rn(t,e,r);return t.negate?{...n,matched:!n.matched}:n}function rn(t,e,r){if(t.kind==="type")return B(t.value==="f"?e.kind==="file":e.kind==="dir");if(t.kind==="name")return B(t.re.test(A(e.path)));if(t.kind==="path")return B(t.re.test(e.path));if(t.kind==="print")return{matched:!0,stdout:e.path+`
|
|
17
|
+
`,stderr:""};if(t.kind==="exec")return sn(t,e,r)}function B(t){return{matched:t,stdout:"",stderr:""}}function sn(t,e,r){if(t.mode==="batch")return t.collected.push(e.path),B(!0);let n=t.args.map(o=>o.replaceAll("{}",e.path)),s=r.dispatch(t.cmd,n,"");return{matched:s.exitCode===0,stdout:s.stdout,stderr:s.stderr}}function on(t,e,r){if(r===e)return t;let n=R(e,r);return t.endsWith("/")?t+n:t+"/"+n}function un(t,e,r){return g(e),S(r.cwd+`
|
|
18
|
+
`)}function cn(t,e,r){let{positional:n}=g(e),s=n[0]??"/",o=x(r.cwd,s);return r.fs.isDir(o)?(r.cwd=o,S()):h(`cd: not a directory: ${s}`)}function ln(t,e,r){let{flags:n,positional:s}=g(dn(e),{short:["l","a","R"]}),o={long:n.has("l"),all:n.has("a"),recursive:n.has("R")},i=s.length>0?s:["."],u=o.recursive?an(i,o.all,r):i,c=[],l=[],a=0;for(let f=0;f<u.length;f++){let d=hn(u[f],u.length>1,o,r);if(d.error){a=1,l.push(d.error);continue}f>0&&u.length>1&&c.push(""),c.push(...d.lines)}return{stdout:c.length===0?"":c.join(`
|
|
17
19
|
`)+`
|
|
18
|
-
`,stderr:
|
|
20
|
+
`,stderr:l.length===0?"":l.join(`
|
|
19
21
|
`)+`
|
|
20
|
-
`,exitCode:
|
|
22
|
+
`,exitCode:a}}function an(t,e,r){let n=[];for(let s of t){let o=x(r.cwd,s);if(!r.fs.isDir(o)){n.push(s);continue}let i=[{display:s,abs:o}];for(;i.length>0;){let{display:u,abs:c}=i.pop();n.push(u);let{dirs:l}=r.fs.listDir(c);for(let a=l.length-1;a>=0;a--){let f=l[a];!e&&f.startsWith(".")||i.push({display:fn(u,f),abs:M(c,f)})}}}return n}function fn(t,e){return t.endsWith("/")?t+e:t+"/"+e}function dn(t){let e=[],r=!1;for(let n of t){if(r){e.push(n);continue}if(n==="--"){e.push(n),r=!0;continue}if(n!=="-1"){if(/^-[a-zA-Z0-9]+$/u.test(n)&&n.includes("1")&&/[a-zA-Z]/u.test(n)){e.push("-"+n.slice(1).replaceAll("1",""));continue}e.push(n)}}return e}function hn(t,e,r,n){let s=x(n.cwd,t);if(n.fs.isFile(s))return{lines:[et(t,n.fs.readFile(s).length,!1,r.long)]};if(!n.fs.isDir(s))return{error:`ls: ${t}: no such file or directory`};let o=e||r.recursive?[`${t}:`]:[];r.all&&(o.push(Nt(".",r.long)),o.push(Nt("..",r.long)));let{dirs:i,files:u}=n.fs.listDir(s);for(let c of i)!r.all&&c.startsWith(".")||o.push(et(c,0,!0,r.long));for(let c of u){if(!r.all&&c.startsWith("."))continue;let l=M(s,c);o.push(et(c,n.fs.readFile(l).length,!1,r.long))}return{lines:o}}function Nt(t,e){return e?`d ${String(0).padStart(8)} ${t}`:t}function et(t,e,r,n){let s=t+(r?"/":"");return n?`${r?"d":"-"} ${String(e).padStart(8)} ${s}`:s}function pn(t,e,r){let{positional:n}=g(e),s=n[0]??".",o=x(r.cwd,s);if(!r.fs.isDir(o))return h(`tree: ${s}: not a directory`);let i=[s];return mn(r.fs,o,i),S(i.join(`
|
|
21
23
|
`)+`
|
|
22
|
-
`)}function
|
|
23
|
-
`)}function
|
|
24
|
-
`)}var
|
|
24
|
+
`)}function mn(t,e,r){let n=[{dir:e,prefix:"",items:Ft(t,e),i:0}];for(;n.length>0;){let s=n.at(-1);if(s.i>=s.items.length){n.pop();continue}let{n:o,isDir:i}=s.items[s.i],u=s.i===s.items.length-1;if(r.push(s.prefix+(u?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ")+o+(i?"/":"")),s.i++,!i)continue;let c=M(s.dir,o);n.push({dir:c,prefix:s.prefix+(u?" ":"\u2502 "),items:Ft(t,c),i:0})}}function Ft(t,e){let{dirs:r,files:n}=t.listDir(e);return[...r.map(s=>({n:s,isDir:!0})),...n.map(s=>({n:s,isDir:!1}))]}function gn(t,e){let{positional:r}=g(e);return r.length===0?E("basename PATH"):S(A(r[0])+`
|
|
25
|
+
`)}function wn(t,e){let{positional:r}=g(e);return r.length===0?E("dirname PATH"):S(L(r[0])+`
|
|
26
|
+
`)}var It={pwd:un,cd:cn,ls:ln,find:At,tree:pn,basename:gn,dirname:wn};var xn=/^(\d+)(?:,(\d+))?p$/u;function Wt(t,e,r){let n;try{n=g(e,{short:["n"]})}catch{return H()}let{flags:s,positional:o}=n;if(!s.has("n")||o.length===0)return H();let i=Sn(o[0]);if(i.error)return i.error;let{ranges:u}=i;if(u.length===0)return H();let c=o.slice(1),l=_("sed",c,t,r),a=l.inputs.flatMap(d=>$(d.content)),f=[];for(let d=0;d<a.length;d++){let p=d+1;for(let{start:m,end:w}of u)p>=m&&p<=w&&f.push(a[d])}return v(f.length>0?f.join(`
|
|
25
27
|
`)+`
|
|
26
|
-
`:"",
|
|
27
|
-
or: grep ${
|
|
28
|
-
`,
|
|
28
|
+
`:"",l)}function Sn(t){let e=[];for(let r of t.split(";")){if(r==="")continue;let n=xn.exec(r);if(!n)return{error:H()};let s=Number(n[1]),o=n[2]===void 0?s:Number(n[2]);if(s<1)return{error:h("sed: line numbers must be >= 1")};if(o<s)return{error:h(`sed: reversed range: ${s},${o}`)};e.push({start:s,end:o})}return{ranges:e}}function H(){return h("sed: only `-n 'X[,Y]p'` (optionally `;`-joined into multi-range scripts) is supported")}function Ot(t,e){let r=t[e+1];if(r===void 0)return-1;if("^$\\.*+?()[]{}|/bBdDsSwW".includes(r)||r>="1"&&r<="9")return 2;let n=o=>o!==void 0&&/[0-9A-Fa-f]/u.test(o),s=(o,i)=>{if(t[e+2]!==o)return 0;let u=t.indexOf(i,e+3);return u>e+3?u-e+1:0};if(r==="x")return n(t[e+2])&&n(t[e+3])?4:0;if(r==="u"){if(t[e+2]==="{"){let o=s("{","}"),i=o?t.slice(e+3,e+o-1):"";return i.length>=1&&i.length<=6&&[...i].every(n)&&parseInt(i,16)<=1114111?o:0}return[2,3,4,5].every(o=>n(t[e+o]))?6:0}return r==="p"||r==="P"?s("{","}"):r==="c"?/[A-Za-z]/u.test(t[e+2]??"")?3:0:r==="k"?s("<",">"):0}function Rt(t){let e="(){}+?|",r="",n=!1;for(let s=0;s<t.length;s++){let o=t[s];if(n){if(o==="\\"){let i=Ot(t,s);if(i===-1)return{error:"trailing backslash (\\)"};if(i>0){r+=t.slice(s,s+i),s+=i-1;continue}r+=t[s+1],s++;continue}r+=o,o==="]"&&(n=!1);continue}if(o==="["){r+=o,n=!0,t[s+1]==="^"&&(r+="^",s++),t[s+1]==="]"&&(r+="\\]",s++);continue}if(o==="\\"){if(s+1>=t.length)return{error:"trailing backslash (\\)"};let i=t[s+1];if(e.includes(i)){r+=i,s++;continue}if(i==="<"||i===">"){r+="\\b",s++;continue}let u=Ot(t,s);if(u>0){r+=t.slice(s,s+u),s+=u-1;continue}r+=i,s++;continue}if(o==="*"&&(s===0||t[s-1]==="^"&&Lt(t,s-1))){r+="\\*";continue}if(o==="^"&&!Lt(t,s)){r+="\\^";continue}if(o==="$"&&!(s===t.length-1||t[s+1]==="\\"&&(t[s+2]===")"||t[s+2]==="|"))){r+="\\$";continue}if(e.includes(o)){r+="\\"+o;continue}r+=o}return{source:r}}function Lt(t,e){return e===0?!0:e>=2&&t[e-2]==="\\"&&(t[e-1]==="("||t[e-1]==="|")}var jt="[-i] [-v] [-n] [-r|-R] [-w] [-o] [-E|-F|-G] [-l] [-L] [-c] [-h] [-H] [-A N] [-B N] [-C N] [--include=GLOB] [--exclude=GLOB] [--exclude-dir=GLOB]",bn=`grep ${jt} PATTERN [PATH...]
|
|
29
|
+
or: grep ${jt} -e PATTERN ... [PATH...]`,vn=["i","v","n","r","R","l","L","c","w","h","H","o","E","F","G"],yn=["A","B","C"];function qt(t,e,r){let n;try{n=g(e,{short:vn,valueShort:yn,repeatable:["e","include","exclude","exclude-dir"]})}catch(j){return h(`grep: ${j.message}`,2)}let{flags:s,values:o,positional:i}=n,u=o.get("e")??[],c,l;if(u.length>0)c=u,l=i;else if(i.length>0)c=[i[0]],l=i.slice(1);else return E(bn);let a=$n(s);if(a)return a;let f=kn(c,s);if(f.error)return f.error;let d=Tn(o);if(d.error)return d.error;let p=s.has("r")||s.has("R"),m=Dn(n),w=_n(p,t,l,r,m),b=w.inputs.filter(j=>j.name===null||Mn(A(j.name),m.name)),y=En(s,p,l.length),C=s.has("v"),oe={showName:y,invert:C,showLine:s.has("n"),only:s.has("o"),after:d.after,before:d.before},U=s.has("l")?Pt(b,f.res,C,!1):s.has("L")?Pt(b,f.res,C,!0):s.has("c")?Ln(b,f.res,C,y):In(b,f.res,oe);return w.failed?{stdout:U.stdout,stderr:w.stderr+U.stderr,exitCode:2}:U}function $n(t){if(t.has("h")&&t.has("H"))return h("grep: -h and -H are mutually exclusive");let e=["l","L","c"].filter(n=>t.has(n));if(e.length>1)return h(`grep: ${e.map(n=>`-${n}`).join(" / ")} are mutually exclusive`);let r=["E","F","G"].filter(n=>t.has(n));return r.length>1?h(`grep: ${r.map(n=>`-${n}`).join(" / ")} are mutually exclusive`):null}function kn(t,e){let r=[],n=e.has("i")?"iu":"u";for(let s of t){let o;if(e.has("F"))o=RegExp.escape(s);else if(e.has("E"))o=s;else{let i=Rt(s);if(i.error)return{error:h(`grep: ${i.error}`,2)};o=i.source}e.has("w")&&(o=`\\b(?:${o})\\b`);try{r.push(new RegExp(o,n))}catch(i){let u=e.has("F")?`fixed-string /${n}`:e.has("E")?`ERE / ECMAScript /${n}`:`BRE /${n}`;return{error:h(`grep: invalid pattern (${u}): ${i.message}`,2)}}}return{res:r}}function G(t,e){return t.some(r=>r.test(e))}var Bt=()=>({stdout:"",stderr:"",exitCode:1});function Tn(t){let e=t.get("C"),r=e===void 0?null:T(e,"grep: -C");if(r?.error)return r;let n=T(t.get("A")??e??"0","grep: -A");if(n.error)return n;let s=T(t.get("B")??e??"0","grep: -B");return s.error?s:{after:n.value,before:s.value}}function En(t,e,r){return t.has("h")?!1:t.has("H")?!0:e||r>1}function _n(t,e,r,n,s){return t?Cn("grep",r.length>0?r:["."],n,s.dir):r.length>0?Z("grep",r,n):{inputs:[{name:null,content:e}],stderr:"",failed:!1}}function Cn(t,e,r,n){let s=[],o="",i=!1;for(let u of e){let c=x(r.cwd,u);if(r.fs.isFile(c)){s.push({name:u,content:r.fs.readFile(c)});continue}if(!r.fs.isDir(c)){o+=`${t}: ${u}: no such file or directory
|
|
30
|
+
`,i=!0;continue}if(!Nn(u,n))for(let l of r.fs.walkFiles(c))An(l,c,n)||s.push({name:Fn(u,c,l),content:r.fs.readFile(l)})}return{inputs:s,stderr:o,failed:i}}function Dn(t){let e=t.order.filter(n=>n.name==="include"||n.name==="exclude").map(n=>({include:n.name==="include",re:F(n.value)})),r=(t.values.get("exclude-dir")??[]).map(F);return{name:e,dir:r}}function Ht(t,e){return t.some(r=>r.test(e))}function Mn(t,e){if(e.length===0)return!0;let r=null;for(let n of e)n.re.test(t)&&(r=n);return r?r.include:!e[0].include}function An(t,e,r){if(r.length===0)return!1;let n=R(e,t).split("/");return n.pop(),n.some(s=>Ht(r,s))}function Nn(t,e){return e.length===0||t.endsWith("/")?!1:Ht(e,t.slice(t.lastIndexOf("/")+1))}function Fn(t,e,r){let n=R(e,r);return t==="."?n:t.endsWith("/")?t+n:t+"/"+n}function In(t,e,r){let n=[],s=!1;for(let{name:i,content:u}of t){let c=$(u),l=Wn(c,e,i,r);l.matched&&(s=!0),l.lines.length>0&&n.push(l.lines.join(`
|
|
29
31
|
`))}let o=n.join(`
|
|
30
|
-
`);return s?
|
|
31
|
-
`:"")):
|
|
32
|
+
`);return s?S(o+(o?`
|
|
33
|
+
`:"")):Bt()}function Wn(t,e,r,n){let{invert:s,after:o,before:i,only:u}=n,c=i>0||o>0,l=[],a=!1,f=-1;for(let d=0;d<t.length;d++){if(G(e,t[d])===s)continue;if(a=!0,u){l.push(...On(t[d],r,d+1,e,n));continue}let p=Math.max(0,d-i),m=Math.min(t.length-1,d+o);c&&f>=0&&p>f+1&&l.push("--");for(let w=Math.max(p,f+1);w<=m;w++){let b=w===d||G(e,t[w])!==s;l.push(Gt(t[w],r,w+1,b,n))}f=m}return{lines:l,matched:a}}function On(t,e,r,n,s){let o=[];for(let c of n){let l=new RegExp(c.source,c.flags+"g");for(let a of t.matchAll(l))a[0].length>0&&o.push({index:a.index,text:a[0]})}o.sort((c,l)=>c.index-l.index||l.text.length-c.text.length);let i=[],u=0;for(let c of o)c.index<u||(i.push(Gt(c.text,e,r,!0,s)),u=c.index+c.text.length);return i}function Gt(t,e,r,n,s){let{showName:o,showLine:i}=s,u=n?":":"-",c=[];return o&&c.push(e??"(standard input)"),i&&c.push(String(r)),c.length>0?c.join(u)+u+t:t}function Pt(t,e,r,n){let s=[],o=!1;for(let{name:i,content:u}of t){let l=$(u).some(a=>G(e,a)!==r);l&&(o=!0),(n?!l:l)&&s.push(i??"(standard input)")}return{stdout:k(s),stderr:"",exitCode:o?0:1}}function Ln(t,e,r,n){let s=[],o=!1;for(let{name:i,content:u}of t){let c=$(u),l=0;for(let a of c)G(e,a)!==r&&l++;l>0&&(o=!0),n?s.push(`${i??"(standard input)"}:${l}`):s.push(String(l))}return s.length===0?Bt():{stdout:k(s),stderr:"",exitCode:o?0:1}}function Rn(t,e,r){let{flags:n,positional:s}=g(e,{short:["n"]}),o=N("cat",s,t,r);return v(n.has("n")?jn(o.content):o.content,o)}function jn(t){if(t==="")return"";let e=t.endsWith(`
|
|
32
34
|
`)?`
|
|
33
35
|
`:"";return(e?t.slice(0,-1).split(`
|
|
34
36
|
`):t.split(`
|
|
35
37
|
`)).map((n,s)=>`${String(s+1).padStart(6)} ${n}`).join(`
|
|
36
|
-
`)+e}function
|
|
38
|
+
`)+e}function Pn(t,e,r){let{values:n,positional:s}=g(e,{valueShort:["n"]});zt(n,s);let o=T(n.get("n")??"10","head: -n");return o.error?o.error:Yt("head",t,s,r,i=>i.slice(0,o.value))}function qn(t,e,r){let{values:n,positional:s}=g(e,{valueShort:["n"]});zt(n,s);let o=T(n.get("n")??"10","tail: -n");return o.error?o.error:Yt("tail",t,s,r,i=>o.value===0?[]:i.slice(-o.value))}function zt(t,e){t.has("n")||e[0]&&/^-\d+$/u.test(e[0])&&t.set("n",e.shift().slice(1))}function Yt(t,e,r,n,s){let o=_(t,r,e,n),i=o.inputs.length>1,u=[];for(let c=0;c<o.inputs.length;c++){let{name:l,content:a}=o.inputs[c],f=s($(a)).join(`
|
|
37
39
|
`);i?u.push(`${c>0?`
|
|
38
|
-
`:""}==> ${
|
|
40
|
+
`:""}==> ${l} <==
|
|
39
41
|
${f}${f?`
|
|
40
42
|
`:""}`):f.length>0&&u.push(f+`
|
|
41
|
-
`)}return
|
|
42
|
-
`:s)}function
|
|
43
|
-
`;function
|
|
43
|
+
`)}return v(u.join(""),o)}function Bn(t,e,r){let{flags:n,positional:s}=g(e,{short:["l","w","c"]}),o=Gn(n),i=_("wc",s,t,r),u=[],c={l:0,w:0,c:0};for(let{name:a,content:f}of i.inputs){let d=Un(f);u.push({counts:d,name:a}),c.l+=d.l,c.w+=d.w,c.c+=d.c}i.inputs.length>1&&u.push({counts:c,name:"total"});let l=Hn(u,o);return v(k(u.map(a=>zn(a.counts,a.name,o,l))),i)}function Hn(t,e){let r=0;for(let{counts:n}of t)e.l&&(r=Math.max(r,String(n.l).length)),e.w&&(r=Math.max(r,String(n.w).length)),e.c&&(r=Math.max(r,String(n.c).length));return r}function Gn(t){return t.has("l")||t.has("w")||t.has("c")?{l:t.has("l"),w:t.has("w"),c:t.has("c")}:{l:!0,w:!0,c:!0}}var Xn=new TextEncoder;function Un(t){return{l:(t.match(/\n/gu)??[]).length,w:(t.match(/\S+/gu)??[]).length,c:Xn.encode(t).length}}function zn(t,e,r,n){let s=[];return r.l&&s.push(String(t.l).padStart(n)),r.w&&s.push(String(t.w).padStart(n)),r.c&&s.push(String(t.c).padStart(n)),s.join(" ")+(e?" "+e:"")}function Yn(t,e,r){let{flags:n,positional:s}=g(e,{short:["n","r","u"]}),o=N("sort",s,t,r),i=$(o.content),u=n.has("n"),c=n.has("u");if(u){let l=i.map(a=>({line:a,key:Xt(a)}));l.sort(c?(a,f)=>a.key-f.key:(a,f)=>a.key-f.key||(a.line<f.line?-1:a.line>f.line?1:0)),i=l.map(a=>a.line)}else i.sort();if(c){let l=new Set;i=i.filter(a=>{let f=u?Xt(a):a;return l.has(f)?!1:(l.add(f),!0)})}return n.has("r")&&i.reverse(),v(k(i),o)}function Xt(t){let e=/^[ \t]*(-?(?:\d+\.?\d*|\.\d+))/u.exec(t);return e?Number(e[1]):0}function Vn(t,e,r){let{flags:n,positional:s}=g(e,{short:["c","d","u","i"]}),o=N("uniq",s,t,r),i=n.has("c"),u=n.has("d"),c=n.has("u"),l=n.has("i"),a=y=>l?y.toLowerCase():y,f=$(o.content),d=[],p=null,m=null,w=0,b=()=>{if(p===null)return;let y=w>=2;!(u&&c)&&(u?y:!c||!y)&&d.push(i?`${String(w).padStart(7)} ${p}`:p)};for(let y of f){let C=a(y);if(C===m){w++;continue}b(),p=y,m=C,w=1}return b(),v(k(d),o)}function Zn(t,e){let{flags:r,positional:n}=g(e,{short:["n","e","E"]}),s=n.join(" "),o=!r.has("n");if(r.has("e")){let i=Jn(s);s=i.text,i.stop&&(o=!1)}return S(o?s+`
|
|
44
|
+
`:s)}function Jn(t){let e={a:7,b:8,e:27,f:12,n:10,r:13,t:9,v:11,"\\":92},r="";for(let n=0;n<t.length;n++){if(t[n]!=="\\"||n+1>=t.length){r+=t[n];continue}let s=t[++n];if(s==="c")return{text:r,stop:!0};if(s in e){r+=String.fromCodePoint(e[s]);continue}if(s==="0"){let o="";for(;o.length<3&&/[0-7]/u.test(t[n+1]??"");)o+=t[++n];r+=String.fromCodePoint(o===""?0:parseInt(o,8));continue}if(s==="x"&&/[0-9a-fA-F]/u.test(t[n+1]??"")){let o="";for(;o.length<2&&/[0-9a-fA-F]/u.test(t[n+1]??"");)o+=t[++n];r+=String.fromCodePoint(parseInt(o,16));continue}r+="\\"+s}return{text:r,stop:!1}}function Kn(t,e,r){let{flags:n,values:s,positional:o}=g(e,{short:["r"],valueShort:["n"],stopAtFirstPositional:!0}),[i="echo",...u]=o,c=t.split(/\s+/u).filter(Boolean);if(c.length===0)return n.has("r")?S():r.dispatch(i,u,"");let l=s.has("n")?T(s.get("n"),"xargs: -n"):{value:c.length};return l.error?l.error:s.has("n")&&l.value===0?h("xargs: -n: must be at least 1"):Qn(r,i,u,c,l.value)}function Qn(t,e,r,n,s){let o="",i="",u=0;for(let c=0;c<n.length;c+=s){let l=t.dispatch(e,[...r,...n.slice(c,c+s)],"");o+=l.stdout,i+=l.stderr,l.exitCode!==0&&(u=l.exitCode)}return{stdout:o,stderr:i,exitCode:u}}function Ut(){return S()}function tr(){return{stdout:"",stderr:"",exitCode:1}}var Vt={cat:Rn,grep:qt,head:Pn,tail:qn,wc:Bn,sort:Yn,uniq:Vn,echo:Zn,xargs:Kn},Zt={true:Ut,false:tr,":":Ut};function Jt(t,e,r){let{index:n,pipe:s}=nr(t),o=t.slice(n),i=rr(o),u=o.slice(i),c=o.slice(0,i).trim(),l=c==="",a=l?"":r.resolveCommand(c.split(/\s+/u)[0]),f=t.slice(0,n+i),d=s&&f.endsWith("|")?" ":"";return er(u,l,s,a,e,r).map(p=>f+d+p)}function er(t,e,r,n,s,o){if(!e)return r?[]:sr(t,s,n==="cd");let i=r?o.pipeNames:o.names;for(let u of o.binPrefixes)if(t.startsWith(u)){let c=t.slice(u.length);return i.filter(l=>l.startsWith(c)).map(l=>u+l)}return t.startsWith("/")||t.startsWith("./")?[]:i.filter(u=>u.startsWith(t))}function nr(t){let e=0,r=!1,n=0;for(;n<t.length;){let s=t[n];if(s==="|"){let o=t[n+1]==="|";n+=o?2:1,e=n,r=!o}else s==="&"&&t[n+1]==="&"?(n+=2,e=n,r=!1):s===";"?(n++,e=n,r=!1):n++}return{index:e,pipe:r}}function rr(t){for(let e=t.length-1;e>=0;e--)if(/\s/u.test(t[e]))return e+1;return 0}function sr(t,e,r=!1){let n=t.lastIndexOf("/"),s=t.slice(0,n+1),o=t.slice(n+1),i=x(e.cwd,s);if(!e.fs.isDir(i))return[];let{dirs:u,files:c}=e.fs.listDir(i),l=o.startsWith("."),a=[];for(let f of u)!l&&f.startsWith(".")||f.startsWith(o)&&a.push(s+f+"/");if(r)return a;for(let f of c)!l&&f.startsWith(".")||f.startsWith(o)&&a.push(s+f);return a}var X={__proto__:null,...Vt,...It,...Tt},nt={__proto__:null,sed:Wt,...Et,...Zt},or=["ls","cd","cat","grep","find","head","tail","wc","tree","sort","uniq","cut","tr","nl","tac","hexdump","xargs","echo","pwd","seq","which","basename","dirname"],Kt=cr(),ir=Kt.join(", "),ur=["grep","head","tail","wc","sort","uniq","cut","xargs","tr","nl","tac","hexdump","cat"];function cr(){let t=new Set(Object.keys(X)),e=[];for(let r of or)t.delete(r)&&e.push(r);return e.push(...[...t].sort()),e}function Qt(t,e={}){let r=pt(t),s={cwd:e.cwd===void 0?"/":x("/",e.cwd),fs:r,user:e.user??"user"};if(s.dispatch=(o,i,u)=>ne(o,i,u,s),s.hasCommand=o=>!!(X[o]||nt[o]),!r.isDir(s.cwd))throw new Error(`createTerminal: cwd is not a directory: ${s.cwd}`);return{run:o=>lr(o,s),cwd:()=>s.cwd,complete:o=>Jt(o,s,{names:Kt,pipeNames:ur,binPrefixes:te,resolveCommand:ee})}}var te=["/usr/local/bin/","/usr/bin/","/bin/","/sbin/"];function ee(t){for(let e of te)if(t.startsWith(e)){let r=t.slice(e.length);if(X[r]||nt[r])return r}return t}function ne(t,e,r,n){let s=ee(t),o=X[s]??nt[s];if(!o)return hr(t);try{return o(r,e,n)}catch(i){return h(`${t}: ${i.message}`)}}function lr(t,e){try{let r=t.trim();if(r==="")return{stdout:"",stderr:"",exitCode:0,cwd:e.cwd};let n=at(r);return{...re(n,e,""),cwd:e.cwd}}catch(r){return{...h(`error: ${r.message}`),cwd:e.cwd}}}function re(t,e,r){let n="",s="",o=0,i=!1;for(let u=0;u<t.length;u++){let c=t[u];if(c.gate==="and"&&o!==0||c.gate==="or"&&o===0)continue;let l=ar(c.stages,e,u===0?r:"");n+=l.stdout,s+=l.stderr,o=l.exitCode,i=!0}return i||(o=0),{stdout:n,stderr:s,exitCode:o}}function ar(t,e,r){let n=r,s="";for(let o=0;o<t.length;o++){let i=t[o],u=i.group?dr(i.group,e,n):fr(i,e,n),c=u.stdout,l=u.stderr;if(i.mergeStderrToStdout&&(c+=l,l=""),i.mergeStdoutToStderr&&(l+=c,c=""),i.stdoutToNull&&(c=""),i.stderrToNull&&(l=""),s+=l,o===t.length-1)return{stdout:c,stderr:s,exitCode:u.exitCode};n=c}return{stdout:"",stderr:s,exitCode:0}}function fr(t,e,r){let n=ct(t.argv,t.quoted??new Set),s=Dt(n.argv,n.quoted,e);return ne(s[0],s.slice(1),r,e)}function dr(t,e,r){let n=e.cwd;try{return re(t,e,r)}finally{e.cwd=n}}function hr(t){return h(`${t}: command not found. Available: ${ir}`,127)}var se=`:host{display:flex;flex-direction:column;height:100%;min-height:0;background:var(--bg, #0c0c0c);color:var(--text, #e6edf3);font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace;font-size:13px;line-height:1.45}.output{flex:1 1 auto;overflow-y:auto;overscroll-behavior:none;-webkit-app-region:no-drag;app-region:no-drag;scrollbar-gutter:stable;padding:12px 14px 6px;cursor:text}.banner{color:var(--muted, #8b949e);margin-bottom:8px}.banner .cmd{color:var(--accent, #58a6ff)}.banner .cmd:hover{text-decoration:underline}.line{white-space:pre-wrap;overflow-wrap:break-word}.cwd{color:var(--accent, #58a6ff)}.sigil{color:var(--muted, #8b949e);margin:0 6px 0 4px}.stdout,.stderr{margin:0 0 4px;font:inherit;white-space:pre-wrap;overflow-wrap:break-word}.stderr{color:var(--critical, #d8413a)}.form{flex:0 0 auto;display:flex;align-items:center;padding:8px 14px 10px;border-top:1px solid var(--border, #2c2c2c)}.form:focus-within{border-top-color:var(--accent, #58a6ff)}.form .cwd{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;user-select:none}.form .sigil{flex:0 0 auto;user-select:none}.input-wrap{flex:1 1 auto;min-width:0;position:relative;display:flex;align-items:center}.input{width:100%;background:transparent;border:none;outline:none;color:inherit;font:inherit;padding:0;position:relative}.ghost{position:absolute;inset:0;display:flex;align-items:center;font:inherit;white-space:pre;overflow:hidden;pointer-events:none;user-select:none;color:var(--muted, #8b949e);opacity:.55}.ghost-pad{color:transparent}
|
|
45
|
+
`;function mr(t){let r=["ls","find /",`grep -r ${gr(t)} .`];if(!t||t.size===0)return r;let n=null;for(let s of t.keys()){let o=wr(s);(n===null||o.length<n.length)&&(n=o)}return n&&r.push(`cat ${n} | head -n 20`),r}var rt=["TODO","FIXME","XXX","HACK","NOTE","BUG","export","import","require","//"];function gr(t){if(!t||t.size===0)return rt[0];for(let e of rt)for(let r of t.values())if(r.includes(e))return e;return rt[0]}function wr(t){return t.startsWith("./")?t.slice(2):t.startsWith("/")?t.slice(1):t}var st=class t extends it{static properties={sources:{attribute:!1},_lines:{state:!0},_input:{state:!0},_cwd:{state:!0},_ghost:{state:!0}};static styles=ut(se);#n=null;#c=null;#e=[];#t=-1;#s="";#r=null;#o=null;static#f=200;constructor(){super(),this.sources=null,this._lines=[],this._input="",this._cwd="/",this._ghost=""}willUpdate(e){e.has("sources")&&this.sources!==this.#c&&(this.#n=this.sources?Qt(this.sources):null,this._cwd=this.#n?this.#n.cwd():"/",this._lines=[{kind:"banner",commands:mr(this.sources)}],this.#e=[],this.#t=-1,this.#s="",this.#r=null,this._input="",this.#c=this.sources),e.has("_input")&&(this.#u(),this.#a())}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.#l())}disconnectedCallback(){super.disconnectedCallback(),this.#u()}firstUpdated(){this.#i()}updated(e){(e.has("_lines")||e.has("sources"))&&this.#l()}#i(){let e=this.renderRoot.querySelector(".input");e&&e.focus()}#l(){let e=this.renderRoot.querySelector(".output");e&&(e.scrollTop=e.scrollHeight)}#d=e=>{if(e.preventDefault(),!this.#n)return;let r=this._input,n=r.trim();if(n==="clear"){this._lines=[],this._input="",n.length>0&&(this.#e=[...this.#e,r]),this.#t=-1;return}let s=this._cwd,o=this.#n.run(r);this._cwd=o.cwd;let i=[...this._lines,{kind:"prompt",cwd:s,text:r}];o.stdout&&i.push({kind:"stdout",text:o.stdout}),o.stderr&&i.push({kind:"stderr",text:o.stderr}),this._lines=i,n.length>0&&(this.#e=[...this.#e,r]),this.#t=-1,this._input=""};#h=e=>{if(e.key==="Tab"&&!e.shiftKey){e.preventDefault(),this.#p();return}this.#r=null,e.key==="ArrowUp"?(e.preventDefault(),this.#g()):e.key==="ArrowDown"&&(e.preventDefault(),this.#w()),this.#u(),this.#a()};#p(){if(!this.#n)return;let e=this.#r;if(e&&e.items[e.index]===this._input){e.index=(e.index+1)%e.items.length,this._input=e.items[e.index];return}let r=this.#n.complete(this._input);if(r.length===0){this.#r=null;return}this._input=r[0],this.#r=r.length>1?{items:r,index:0}:null}#u(){this._ghost="",this.#o!==null&&(clearTimeout(this.#o),this.#o=null)}#a(){this.#o=setTimeout(()=>{this.#o=null,this.#m()},t.#f)}#m(){if(!this.#n||this.#r)return;let e=this._input,r=e.slice(-1),n=e===""||r===" "||r==="|",s=/[\w./]/u.test(r);if(!n&&!s)return;let o=this.#n.complete(e);if(o.length===0)return;let i=o[0];!i.startsWith(e)||i===e||s&&o.includes(e)||(this._ghost=i.slice(e.length))}#g(){this.#e.length!==0&&(this.#t<0?(this.#s=this._input,this.#t=this.#e.length-1):this.#t=Math.max(0,this.#t-1),this._input=this.#e[this.#t])}#w(){if(this.#t<0)return;let e=this.#t+1;e>=this.#e.length?(this.#t=-1,this._input=this.#s,this.#s=""):(this.#t=e,this._input=this.#e[e])}#x=e=>{this._input=e.target.value};#S=e=>{this._input=e,this.#t=-1,this.#s="",this.#i()};#b=()=>{let e=this.renderRoot.getSelection?.()??document.getSelection();e&&!e.isCollapsed||this.#i()};render(){return D`<div class="output" @click="${this.#b}">${this._lines.map(e=>this.#v(e))}</div><form class="form" @submit="${this.#d}"><span class="cwd">${this._cwd}</span><span class="sigil">$</span><div class="input-wrap">${this._ghost?D`<div class="ghost" aria-hidden="true"><span class="ghost-pad">${this._input}</span>${this._ghost}</div>`:z} <input class="input" type="text" aria-label="Terminal command" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" .value="${this._input}" @input="${this.#x}" @keydown="${this.#h}"></div></form>`}#v(e){return e.kind==="banner"?D`<div class="banner">Virtual shell over the bundle source tree. Try ${e.commands.map((r,n)=>D`${n>0?", ":""}\`<span class="cmd" @click="${()=>this.#S(r)}">${r}</span>\``)}. ↑/↓ for history, Tab to complete.</div>`:e.kind==="prompt"?D`<div class="line"><span class="cwd">${e.cwd}</span><span class="sigil">$</span>${e.text}</div>`:e.kind==="stdout"?D`<pre class="stdout">${e.text}</pre>`:e.kind==="stderr"?D`<pre class="stderr">${e.text}</pre>`:z}};customElements.define("bundle-terminal",st);function ks(t,e){let r=document.createElement("bundle-terminal");return r.dataset.integrity=e??"",r.sources=t,r}export{ks as createTerminalElement};
|