import{a as z,b as A,c as k}from"./chunk-MD7IQ7EC.js";import{a as l}from"./chunk-54LXMJYQ.js";import{M as n,ea as c,g as r,ja as d,n as h}from"./chunk-ZHRPBG7M.js";var f=r(z(),1),a=r(A(),1),p=r(k(),1);var $=(()=>{class t{$ws=d(l);io;fitAddon;webLinksAddon;resize;elementResize;pluginName;term;startTerminal(m,s={},u,w){this.pluginName=w,this.elementResize=u,this.io=this.$ws.connectToNamespace("log"),this.term=new p.Terminal(s),setTimeout(()=>{this.term.loadAddon(this.fitAddon),this.term.loadAddon(this.webLinksAddon)}),this.fitAddon=new f.FitAddon,this.webLinksAddon=new a.WebLinksAddon,this.resize=new h,this.term.open(m.nativeElement),setTimeout(()=>{this.fitAddon.activate(this.term),this.fitAddon.fit()}),this.io.connected.subscribe(()=>{this.term.reset(),this.io.socket.emit("tail-log",{cols:this.term.cols,rows:this.term.rows})}),this.io.socket.on("disconnect",()=>{this.term.write(`
\r
\rWebsocket failed to connect. Is the server running?
\r
\r`)}),this.resize.pipe(n(500)).subscribe(e=>{this.io.socket.emit("resize",e)}),this.io.socket.on("stdout",e=>{if(this.pluginName){let b=e.split(`
\r`),o=!1;b.forEach(i=>{if(i){if(o)if(i.match(/36m\[.*?\]/))o=!1;else{this.term.write(`${i}
\r`);return}i.includes(`36m[${this.pluginName}]`)&&(this.term.write(`${i}
\r`),o=!0)}})}else this.term.write(e)}),this.term.onResize(e=>{this.resize.next(e)}),this.elementResize&&this.elementResize.pipe(n(100)).subscribe({next:()=>{this.fitAddon.fit()}})}destroyTerminal(){this.io.end(),this.term.dispose(),this.resize.complete(),this.elementResize&&this.elementResize.complete()}static \u0275fac=function(s){return new(s||t)};static \u0275prov=c({token:t,factory:t.\u0275fac,providedIn:"root"})}return t})();export{$ as a};
