webtty 1.3.0 → 1.4.1

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.
@@ -1,3 +1,3 @@
1
- import{FitAddon as f,init as u,Terminal as h}from"/dist/ghostty-web.js";var a=window.location.pathname.split("/s/")[1]??"main",o=await fetch("/api/config").then((t)=>t.json());document.title=`${a} | webtty`;await u();var e=new h({cols:o.cols,rows:o.rows,cursorBlink:o.cursorBlink,fontSize:o.fontSize,fontFamily:o.fontFamily,scrollback:Math.ceil(o.scrollback/80),theme:o.theme}),l=new f;e.loadAddon(l);var g=document.getElementById("terminal");await e.open(g);l.fit();l.observeResize();var p=window.location.protocol==="https:"?"wss:":"ws:",n;function w(){let t=`${p}//${window.location.host}/ws/${a}?cols=${e.cols}&rows=${e.rows}`;n=new WebSocket(t);let i="\x1B[2m",d="\x1B[1;33m",b="\x1B[3m",s="\x1B[0m",m=`${i}[${s} ${d}webtty${s} ${i}]${s}`,c=(r)=>`\r
2
- ${m} ${i}${b}${r}${s}\r
3
- `;n.onopen=()=>{n.send(JSON.stringify({type:"resize",cols:e.cols,rows:e.rows}))},n.onmessage=(r)=>{e.write(r.data)},n.onclose=(r)=>{if(r.code===4001){e.write(c("Session removed.")),setTimeout(()=>window.close(),500);return}if(r.code===1001){e.write(c("Server stopped.")),setTimeout(()=>window.close(),500);return}e.write(c("Connection lost. Reconnecting in 2s...")),setTimeout(w,2000)},n.onerror=()=>{e.write(c("WebSocket error."))}}w();e.onData((t)=>{if(n&&n.readyState===WebSocket.OPEN)n.send(t)});e.onResize(({cols:t,rows:i})=>{if(n&&n.readyState===WebSocket.OPEN)n.send(JSON.stringify({type:"resize",cols:t,rows:i}))});window.addEventListener("resize",()=>{l.fit()});if(o.copyOnSelect)e.onSelectionChange(()=>{let t=e.getSelection();if(!t)return;navigator.clipboard.writeText(t).catch(()=>{})});if(o.rightClickBehavior==="copyPaste")g.addEventListener("contextmenu",(t)=>{let i=e.getSelection();if(!i)return;t.preventDefault(),navigator.clipboard.writeText(i).catch(()=>{}),e.clearSelection()});
1
+ import{FitAddon as y,init as h,Terminal as S}from"/dist/ghostty-web.js";var w=new RegExp("\x1B\\[(\\d*) q","g");function b(t,i){w.lastIndex=0;let c=w.exec(i);while(c!==null){let n=c[1]===""?0:Number(c[1]);if(!Number.isNaN(n)&&n>=0&&n<=6)t.options.cursorStyle=n===0||n===1||n===2?"block":n===3||n===4?"underline":"bar",t.options.cursorBlink=n===0||n===1||n===3||n===5;c=w.exec(i)}}var u=window.location.pathname.split("/s/")[1]??"main",r=await fetch("/api/config").then((t)=>t.json());document.title=`${u} | webtty`;await h();var e=new S({cols:r.cols,rows:r.rows,cursorStyle:r.cursorStyle,cursorBlink:r.cursorStyleBlink,fontSize:r.fontSize,fontFamily:r.fontFamily,scrollback:Math.ceil(r.scrollback/80),theme:r.theme}),a=new y;e.loadAddon(a);var d=document.getElementById("terminal");await e.open(d);a.fit();a.observeResize();var k=window.location.protocol==="https:"?"wss:":"ws:",o;function f(){let t=`${k}//${window.location.host}/ws/${u}?cols=${e.cols}&rows=${e.rows}`;o=new WebSocket(t);let i="\x1B[2m",c="\x1B[1;33m",n="\x1B[3m",l="\x1B[0m",m=`${i}[${l} ${c}webtty${l} ${i}]${l}`,g=(s)=>`\r
2
+ ${m} ${i}${n}${s}${l}\r
3
+ `;o.onopen=()=>{o.send(JSON.stringify({type:"resize",cols:e.cols,rows:e.rows}))},o.onmessage=(s)=>{b(e,s.data),e.write(s.data)},o.onclose=(s)=>{if(s.code===4001){e.write(g("Session removed.")),setTimeout(()=>window.close(),500);return}if(s.code===1001){e.write(g("Server stopped.")),setTimeout(()=>window.close(),500);return}e.write(g("Connection lost. Reconnecting in 2s...")),setTimeout(f,2000)},o.onerror=()=>{e.write(g("WebSocket error."))}}f();e.onData((t)=>{if(o&&o.readyState===WebSocket.OPEN)o.send(t)});e.onResize(({cols:t,rows:i})=>{if(o&&o.readyState===WebSocket.OPEN)o.send(JSON.stringify({type:"resize",cols:t,rows:i}))});window.addEventListener("resize",()=>{a.fit()});if(r.copyOnSelect)e.onSelectionChange(()=>{let t=e.getSelection();if(!t)return;navigator.clipboard.writeText(t).catch(()=>{})});if(r.rightClickBehavior==="copyPaste")d.addEventListener("contextmenu",(t)=>{let i=e.getSelection();if(!i)return;t.preventDefault(),navigator.clipboard.writeText(i).catch(()=>{}),e.clearSelection()});
Binary file