diff --git a/webterm/static/js/terminal.js b/webterm/static/js/terminal.js index 6a959ad..af2defc 100644 --- a/webterm/static/js/terminal.js +++ b/webterm/static/js/terminal.js @@ -10,7 +10,7 @@ Example: For tests, pass a Ghostty instance directly: import { Ghostty, Terminal } from "ghostty-web"; const ghostty = await Ghostty.load(); - const term = new Terminal({ ghostty });`);return Q}var f=1000,K0=30000,S0=262144,u0=10,f0=8192,l="\uD83D\uDD14",I=null;async function M0(){if(!I){let j=p0();console.log("[webterm] Loading shared Ghostty WASM:",j),I=await u.load(j)}return I}var z0='ui-monospace, "SFMono-Regular", "FiraCode Nerd Font", "FiraMono Nerd Font", "Fira Code", "Roboto Mono", Menlo, Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace',p={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#d3d7cf",selectionForeground:"#000000",black:"#2e3436",red:"#cc0000",green:"#4e9a06",yellow:"#c4a000",blue:"#3465a4",magenta:"#75507b",cyan:"#06989a",white:"#d3d7cf",brightBlack:"#555753",brightRed:"#ef2929",brightGreen:"#8ae234",brightYellow:"#fce94f",brightBlue:"#729fcf",brightMagenta:"#ad7fa8",brightCyan:"#34e2e2",brightWhite:"#eeeeec"},xterm:{background:"#000000",foreground:"#e5e5e5",cursor:"#e5e5e5",cursorAccent:"#000000",selectionBackground:"#e5e5e5",selectionForeground:"#000000",black:"#000000",red:"#cd0000",green:"#00cd00",yellow:"#cdcd00",blue:"#0000cd",magenta:"#cd00cd",cyan:"#00cdcd",white:"#e5e5e5",brightBlack:"#4d4d4d",brightRed:"#ff0000",brightGreen:"#00ff00",brightYellow:"#ffff00",brightBlue:"#0000ff",brightMagenta:"#ff00ff",brightCyan:"#00ffff",brightWhite:"#ffffff"},monokai:{background:"#272822",foreground:"#fdfff1",cursor:"#fdfff1",cursorAccent:"#272822",selectionBackground:"#fdfff1",selectionForeground:"#272822",black:"#272822",red:"#f92672",green:"#a6e22e",yellow:"#e6db74",blue:"#fd971f",magenta:"#ae81ff",cyan:"#66d9ef",white:"#fdfff1",brightBlack:"#6e7066",brightRed:"#f92672",brightGreen:"#a6e22e",brightYellow:"#e6db74",brightBlue:"#fd971f",brightMagenta:"#ae81ff",brightCyan:"#66d9ef",brightWhite:"#fdfff1"},"monokai-pro":{background:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#fcfcfa",selectionForeground:"#2d2a2e",black:"#403e41",red:"#ff6188",green:"#a9dc76",yellow:"#ffd866",blue:"#fc9867",magenta:"#ab9df2",cyan:"#78dce8",white:"#fcfcfa",brightBlack:"#727072",brightRed:"#ff6188",brightGreen:"#a9dc76",brightYellow:"#ffd866",brightBlue:"#fc9867",brightMagenta:"#ab9df2",brightCyan:"#78dce8",brightWhite:"#fcfcfa"},ristretto:{background:"#2d2525",foreground:"#fff1f3",cursor:"#fff1f3",cursorAccent:"#2d2525",selectionBackground:"#fff1f3",selectionForeground:"#2d2525",black:"#2c2525",red:"#fd6883",green:"#adda78",yellow:"#f9cc6c",blue:"#f38d70",magenta:"#a8a9eb",cyan:"#85dacc",white:"#f9f8f5",brightBlack:"#655761",brightRed:"#fd6883",brightGreen:"#adda78",brightYellow:"#f9cc6c",brightBlue:"#f38d70",brightMagenta:"#a8a9eb",brightCyan:"#85dacc",brightWhite:"#f9f8f5"},dark:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#aeafad",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"},light:{background:"#ffffff",foreground:"#383a42",cursor:"#526eff",cursorAccent:"#ffffff",selectionBackground:"#383a42",selectionForeground:"#ffffff",black:"#000000",red:"#e45649",green:"#50a14f",yellow:"#c18401",blue:"#4078f2",magenta:"#a626a4",cyan:"#0184bc",white:"#a0a1a7",brightBlack:"#5c6370",brightRed:"#e06c75",brightGreen:"#98c379",brightYellow:"#d19a66",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"},dracula:{background:"#282a36",foreground:"#f8f8f2",cursor:"#f8f8f2",cursorAccent:"#282a36",selectionBackground:"#f8f8f2",selectionForeground:"#282a36",black:"#21222c",red:"#ff5555",green:"#50fa7b",yellow:"#f1fa8c",blue:"#bd93f9",magenta:"#ff79c6",cyan:"#8be9fd",white:"#f8f8f2",brightBlack:"#6272a4",brightRed:"#ff6e6e",brightGreen:"#69ff94",brightYellow:"#ffffa5",brightBlue:"#d6acff",brightMagenta:"#ff92df",brightCyan:"#a4ffff",brightWhite:"#ffffff"},catppuccin:{background:"#1e1e2e",foreground:"#cdd6f4",cursor:"#f5e0dc",cursorAccent:"#1e1e2e",selectionBackground:"#cdd6f4",selectionForeground:"#1e1e2e",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#f5c2e7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#f5c2e7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},nord:{background:"#2e3440",foreground:"#d8dee9",cursor:"#d8dee9",cursorAccent:"#2e3440",selectionBackground:"#d8dee9",selectionForeground:"#2e3440",black:"#3b4252",red:"#bf616a",green:"#a3be8c",yellow:"#ebcb8b",blue:"#81a1c1",magenta:"#b48ead",cyan:"#88c0d0",white:"#e5e9f0",brightBlack:"#4c566a",brightRed:"#bf616a",brightGreen:"#a3be8c",brightYellow:"#ebcb8b",brightBlue:"#81a1c1",brightMagenta:"#b48ead",brightCyan:"#8fbcbb",brightWhite:"#eceff4"},gruvbox:{background:"#282828",foreground:"#ebdbb2",cursor:"#ebdbb2",cursorAccent:"#282828",selectionBackground:"#ebdbb2",selectionForeground:"#282828",black:"#282828",red:"#cc241d",green:"#98971a",yellow:"#d79921",blue:"#458588",magenta:"#b16286",cyan:"#689d6a",white:"#a89984",brightBlack:"#928374",brightRed:"#fb4934",brightGreen:"#b8bb26",brightYellow:"#fabd2f",brightBlue:"#83a598",brightMagenta:"#d3869b",brightCyan:"#8ec07c",brightWhite:"#ebdbb2"},solarized:{background:"#002b36",foreground:"#839496",cursor:"#839496",cursorAccent:"#002b36",selectionBackground:"#839496",selectionForeground:"#002b36",black:"#073642",red:"#dc322f",green:"#859900",yellow:"#b58900",blue:"#268bd2",magenta:"#d33682",cyan:"#2aa198",white:"#eee8d5",brightBlack:"#586e75",brightRed:"#cb4b16",brightGreen:"#586e75",brightYellow:"#657b83",brightBlue:"#839496",brightMagenta:"#6c71c4",brightCyan:"#93a1a1",brightWhite:"#fdf6e3"},tokyo:{background:"#1a1b26",foreground:"#a9b1d6",cursor:"#c0caf5",cursorAccent:"#1a1b26",selectionBackground:"#a9b1d6",selectionForeground:"#1a1b26",black:"#15161e",red:"#f7768e",green:"#9ece6a",yellow:"#e0af68",blue:"#7aa2f7",magenta:"#bb9af7",cyan:"#7dcfff",white:"#a9b1d6",brightBlack:"#414868",brightRed:"#f7768e",brightGreen:"#9ece6a",brightYellow:"#e0af68",brightBlue:"#7aa2f7",brightMagenta:"#bb9af7",brightCyan:"#7dcfff",brightWhite:"#c0caf5"},miasma:{background:"#222222",foreground:"#c2c2b0",cursor:"#c2c2b0",cursorAccent:"#222222",selectionBackground:"#c2c2b0",selectionForeground:"#222222",black:"#000000",red:"#685742",green:"#5f875f",yellow:"#b36d43",blue:"#78824b",magenta:"#bb7744",cyan:"#c9a554",white:"#d7c483",brightBlack:"#666666",brightRed:"#685742",brightGreen:"#5f875f",brightYellow:"#b36d43",brightBlue:"#78824b",brightMagenta:"#bb7744",brightCyan:"#c9a554",brightWhite:"#d7c483"},github:{background:"#1c2128",foreground:"#adbac7",cursor:"#adbac7",cursorAccent:"#1c2128",selectionBackground:"#adbac7",selectionForeground:"#1c2128",black:"#545d68",red:"#f47067",green:"#57ab5a",yellow:"#c69026",blue:"#539bf5",magenta:"#b083f0",cyan:"#39c5cf",white:"#909dab",brightBlack:"#636e7b",brightRed:"#ff938a",brightGreen:"#6bc46d",brightYellow:"#daaa3f",brightBlue:"#6cb6ff",brightMagenta:"#dcbdfb",brightCyan:"#56d4dd",brightWhite:"#cdd9e5"},gotham:{background:"#0c1014",foreground:"#99d1ce",cursor:"#99d1ce",cursorAccent:"#0c1014",selectionBackground:"#99d1ce",selectionForeground:"#0c1014",black:"#0c1014",red:"#c23127",green:"#2aa889",yellow:"#edb443",blue:"#195466",magenta:"#4e5166",cyan:"#33859e",white:"#99d1ce",brightBlack:"#0c1014",brightRed:"#c23127",brightGreen:"#2aa889",brightYellow:"#edb443",brightBlue:"#195466",brightMagenta:"#4e5166",brightCyan:"#33859e",brightWhite:"#99d1ce"}};function m0(j){let V={};if(j.dataset.fontFamily){let $=j.dataset.fontFamily;if($.startsWith("var(")){let Z=$.match(/var\(([^)]+)\)/);if(Z){let P=Z[1].trim(),J=getComputedStyle(document.documentElement).getPropertyValue(P).trim();if(J)$=J;else console.warn(`[webterm] CSS variable ${P} not found, using default font`),$=z0}}V.fontFamily=$}if(j.dataset.fontSize)V.fontSize=parseInt(j.dataset.fontSize,10);if(j.dataset.scrollback)V.scrollback=parseInt(j.dataset.scrollback,10);if(j.dataset.theme){let $=j.dataset.theme.toLowerCase();if($ in p)V.theme=p[$];else try{V.theme=JSON.parse(j.dataset.theme)}catch(Z){console.warn(`[webterm] Unknown theme "${j.dataset.theme}"`,Z)}}return V}function p0(){let j=document.querySelectorAll('script[src*="terminal.js"]');if(j.length>0){let V=j[0].src;return V.substring(0,V.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function n(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}var k0={"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+","[":"{","]":"}","\\":"|",";":":","'":'"',",":"<",".":">","/":"?"},w0={"2":"@","3":"[","4":"\\","5":"]","6":"^","7":"_","8":"?"},c0=["\x1BOP","\x1BOQ","\x1BOR","\x1BOS","\x1B[15~","\x1B[17~","\x1B[18~","\x1B[19~","\x1B[20~","\x1B[21~"],D0=["\x1B[23~","\x1B[24~","\x1B[25~","\x1B[26~","\x1B[28~","\x1B[29~","\x1B[31~","\x1B[32~","\x1B[33~","\x1B[34~"];function y0(j){if(j.length!==1)return j;if(j>="a"&&j<="z")return j.toUpperCase();return k0[j]??j}function R0(j){if(j.length!==1)return j;let V=w0[j]??j;if(V==="?")return"";let $=V.toUpperCase().charCodeAt(0);if($>=64&&$<=95)return String.fromCharCode($-64);return j}function o(j,V){if(j.length!==1)return null;let $="1234567890".indexOf(j);if($<0)return null;return V?D0[$]:c0[$]}function S(j){if(!j||j.startsWith("\x1B"))return j;return`\x1B${j}`}function C(j,V,$,Z,P){if(j.length!==1)return j;if(P){let J=o(j,V);if(J)return Z?S(J):J}if($){let J=R0(j);if(J!==j)return Z?S(J):J}if(V){let J=y0(j);return Z?S(J):J}return Z?S(j):j}class k{terminal;fitAddon;socket=null;socketGeneration=0;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;heartbeatIntervalMs=15000;stallTimeoutMs=45000;heartbeatTimer;lastMessageAt=0;lastPongAt=0;messageQueue=[];pendingStdin="";pendingStdinTimer;lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;altActive=!1;shiftActive=!1;fnActive=!1;pendingCtrl=!1;pendingAlt=!1;pendingShift=!1;pendingFn=!1;fontFamily;fontSize;cleanupTimer;resizeObserver=null;mobileKeybarStyle=null;boundHandlers=[];isTabHidden=!1;hiddenBuffer=[];hiddenBufferBytes=0;baseTitle;bellActive=!1;routeKey;static sharedTextEncoder=new TextEncoder;constructor(j,V,$,Z,P,J,O,X){this.element=j,this.wsUrl=V,this.terminal=$,this.fitAddon=Z,this.fontFamily=P,this.fontSize=J,this.routeKey=O,this.baseTitle=X}addTrackedListener(j,V,$,Z){j.addEventListener(V,$,Z),this.boundHandlers.push({target:j,type:V,handler:$,options:Z})}bellStorageKey(){if(!this.routeKey)return null;return`webterm:bell:${this.routeKey}`}setBellActive(){if(!this.bellActive)this.bellActive=!0,document.title=`${l} ${this.baseTitle}`;let j=this.bellStorageKey();if(j)localStorage.setItem(j,String(Date.now()))}clearBellState(){let j=this.bellStorageKey();if(j)localStorage.removeItem(j);if(!this.bellActive)return;this.bellActive=!1,document.title=this.baseTitle}static async create(j,V,$){let Z=await M0(),P=$.theme??p.tango,J=$.fontFamily?.trim()||z0,O=$.fontSize??16,X=n()?200:1000,K={fontFamily:J,fontSize:O,scrollback:$.scrollback??X,cursorBlink:!0,cursorStyle:"block",theme:P,ghostty:Z},z=new d(K),W=new r;z.loadAddon(W),z.open(j);let Y=j.dataset.sessionRouteKey??new URLSearchParams(window.location.search).get("route_key")??"",L=j.dataset.sessionName?.trim()||document.title,H=L.startsWith(`${l} `)?L.slice(l.length+1):L,q=new k(j,V,z,W,J,O,Y,H);return q.initialize(),q}initialize(){if(this.waitForFonts().then(()=>{if(typeof this.terminal.loadFonts==="function")this.terminal.loadFonts();this.fit()}),this.setupResizeObserver(),this.addTrackedListener(window,"resize",()=>{this.fit()}),this.terminal.onData((V)=>{this.clearBellState(),this.sendStdin(V)}),this.terminal.onBell(()=>{this.setBellActive()}),this.terminal.onResize((V)=>{if(this.isValidSize(V.cols,V.rows))this.lastValidSize={cols:V.cols,rows:V.rows},this.send(["resize",{width:V.cols,height:V.rows}])}),this.setupMobileKeyboard(),this.setupTouchSelection(),n())this.setupMobileKeybar();if(this.isTabHidden=document.hidden,this.startResourceCleanup(),this.connect(),document.hasFocus())this.clearBellState();let j=()=>{if(this.clearBellState(),n())this.focusMobileInput();else this.terminal.focus()};this.addTrackedListener(document,"visibilitychange",()=>{if(document.hidden)this.isTabHidden=!0,this.stopHeartbeatWatchdog();else this.isTabHidden=!1,this.refreshConnection(),j()}),this.addTrackedListener(window,"focus",()=>{j()}),this.addTrackedListener(window,"pageshow",()=>{j()})}setupMobileKeyboard(){let j=document.createElement("textarea");j.setAttribute("autocapitalize","off"),j.setAttribute("autocomplete","off"),j.setAttribute("autocorrect","off"),j.setAttribute("spellcheck","false"),j.setAttribute("inputmode","text"),j.setAttribute("enterkeyhint","send"),j.style.cssText=` + const term = new Terminal({ ghostty });`);return Q}var f=1000,K0=30000,S0=262144,u0=10,f0=8192,l="\uD83D\uDD14",I=null;async function M0(){if(!I){let j=p0();console.log("[webterm] Loading shared Ghostty WASM:",j),I=await u.load(j)}return I}var z0='ui-monospace, "SFMono-Regular", "FiraCode Nerd Font", "FiraMono Nerd Font", "Fira Code", "Roboto Mono", Menlo, Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace',p={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#d3d7cf",selectionForeground:"#000000",black:"#2e3436",red:"#cc0000",green:"#4e9a06",yellow:"#c4a000",blue:"#3465a4",magenta:"#75507b",cyan:"#06989a",white:"#d3d7cf",brightBlack:"#555753",brightRed:"#ef2929",brightGreen:"#8ae234",brightYellow:"#fce94f",brightBlue:"#729fcf",brightMagenta:"#ad7fa8",brightCyan:"#34e2e2",brightWhite:"#eeeeec"},xterm:{background:"#000000",foreground:"#e5e5e5",cursor:"#e5e5e5",cursorAccent:"#000000",selectionBackground:"#e5e5e5",selectionForeground:"#000000",black:"#000000",red:"#cd0000",green:"#00cd00",yellow:"#cdcd00",blue:"#0000cd",magenta:"#cd00cd",cyan:"#00cdcd",white:"#e5e5e5",brightBlack:"#4d4d4d",brightRed:"#ff0000",brightGreen:"#00ff00",brightYellow:"#ffff00",brightBlue:"#0000ff",brightMagenta:"#ff00ff",brightCyan:"#00ffff",brightWhite:"#ffffff"},monokai:{background:"#272822",foreground:"#fdfff1",cursor:"#fdfff1",cursorAccent:"#272822",selectionBackground:"#fdfff1",selectionForeground:"#272822",black:"#272822",red:"#f92672",green:"#a6e22e",yellow:"#e6db74",blue:"#fd971f",magenta:"#ae81ff",cyan:"#66d9ef",white:"#fdfff1",brightBlack:"#6e7066",brightRed:"#f92672",brightGreen:"#a6e22e",brightYellow:"#e6db74",brightBlue:"#fd971f",brightMagenta:"#ae81ff",brightCyan:"#66d9ef",brightWhite:"#fdfff1"},"monokai-pro":{background:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#fcfcfa",selectionForeground:"#2d2a2e",black:"#403e41",red:"#ff6188",green:"#a9dc76",yellow:"#ffd866",blue:"#fc9867",magenta:"#ab9df2",cyan:"#78dce8",white:"#fcfcfa",brightBlack:"#727072",brightRed:"#ff6188",brightGreen:"#a9dc76",brightYellow:"#ffd866",brightBlue:"#fc9867",brightMagenta:"#ab9df2",brightCyan:"#78dce8",brightWhite:"#fcfcfa"},ristretto:{background:"#2d2525",foreground:"#fff1f3",cursor:"#fff1f3",cursorAccent:"#2d2525",selectionBackground:"#fff1f3",selectionForeground:"#2d2525",black:"#2c2525",red:"#fd6883",green:"#adda78",yellow:"#f9cc6c",blue:"#f38d70",magenta:"#a8a9eb",cyan:"#85dacc",white:"#f9f8f5",brightBlack:"#655761",brightRed:"#fd6883",brightGreen:"#adda78",brightYellow:"#f9cc6c",brightBlue:"#f38d70",brightMagenta:"#a8a9eb",brightCyan:"#85dacc",brightWhite:"#f9f8f5"},dark:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#aeafad",cursorAccent:"#1e1e1e",selectionBackground:"#d4d4d4",selectionForeground:"#1e1e1e",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"},light:{background:"#ffffff",foreground:"#383a42",cursor:"#526eff",cursorAccent:"#ffffff",selectionBackground:"#383a42",selectionForeground:"#ffffff",black:"#000000",red:"#e45649",green:"#50a14f",yellow:"#c18401",blue:"#4078f2",magenta:"#a626a4",cyan:"#0184bc",white:"#a0a1a7",brightBlack:"#5c6370",brightRed:"#e06c75",brightGreen:"#98c379",brightYellow:"#d19a66",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"},dracula:{background:"#282a36",foreground:"#f8f8f2",cursor:"#f8f8f2",cursorAccent:"#282a36",selectionBackground:"#f8f8f2",selectionForeground:"#282a36",black:"#21222c",red:"#ff5555",green:"#50fa7b",yellow:"#f1fa8c",blue:"#bd93f9",magenta:"#ff79c6",cyan:"#8be9fd",white:"#f8f8f2",brightBlack:"#6272a4",brightRed:"#ff6e6e",brightGreen:"#69ff94",brightYellow:"#ffffa5",brightBlue:"#d6acff",brightMagenta:"#ff92df",brightCyan:"#a4ffff",brightWhite:"#ffffff"},catppuccin:{background:"#1e1e2e",foreground:"#cdd6f4",cursor:"#f5e0dc",cursorAccent:"#1e1e2e",selectionBackground:"#cdd6f4",selectionForeground:"#1e1e2e",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#f5c2e7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#f5c2e7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},nord:{background:"#2e3440",foreground:"#d8dee9",cursor:"#d8dee9",cursorAccent:"#2e3440",selectionBackground:"#d8dee9",selectionForeground:"#2e3440",black:"#3b4252",red:"#bf616a",green:"#a3be8c",yellow:"#ebcb8b",blue:"#81a1c1",magenta:"#b48ead",cyan:"#88c0d0",white:"#e5e9f0",brightBlack:"#4c566a",brightRed:"#bf616a",brightGreen:"#a3be8c",brightYellow:"#ebcb8b",brightBlue:"#81a1c1",brightMagenta:"#b48ead",brightCyan:"#8fbcbb",brightWhite:"#eceff4"},gruvbox:{background:"#282828",foreground:"#ebdbb2",cursor:"#ebdbb2",cursorAccent:"#282828",selectionBackground:"#ebdbb2",selectionForeground:"#282828",black:"#282828",red:"#cc241d",green:"#98971a",yellow:"#d79921",blue:"#458588",magenta:"#b16286",cyan:"#689d6a",white:"#a89984",brightBlack:"#928374",brightRed:"#fb4934",brightGreen:"#b8bb26",brightYellow:"#fabd2f",brightBlue:"#83a598",brightMagenta:"#d3869b",brightCyan:"#8ec07c",brightWhite:"#ebdbb2"},solarized:{background:"#002b36",foreground:"#839496",cursor:"#839496",cursorAccent:"#002b36",selectionBackground:"#839496",selectionForeground:"#002b36",black:"#073642",red:"#dc322f",green:"#859900",yellow:"#b58900",blue:"#268bd2",magenta:"#d33682",cyan:"#2aa198",white:"#eee8d5",brightBlack:"#586e75",brightRed:"#cb4b16",brightGreen:"#586e75",brightYellow:"#657b83",brightBlue:"#839496",brightMagenta:"#6c71c4",brightCyan:"#93a1a1",brightWhite:"#fdf6e3"},tokyo:{background:"#1a1b26",foreground:"#a9b1d6",cursor:"#c0caf5",cursorAccent:"#1a1b26",selectionBackground:"#a9b1d6",selectionForeground:"#1a1b26",black:"#15161e",red:"#f7768e",green:"#9ece6a",yellow:"#e0af68",blue:"#7aa2f7",magenta:"#bb9af7",cyan:"#7dcfff",white:"#a9b1d6",brightBlack:"#414868",brightRed:"#f7768e",brightGreen:"#9ece6a",brightYellow:"#e0af68",brightBlue:"#7aa2f7",brightMagenta:"#bb9af7",brightCyan:"#7dcfff",brightWhite:"#c0caf5"},miasma:{background:"#222222",foreground:"#c2c2b0",cursor:"#c2c2b0",cursorAccent:"#222222",selectionBackground:"#c2c2b0",selectionForeground:"#222222",black:"#000000",red:"#685742",green:"#5f875f",yellow:"#b36d43",blue:"#78824b",magenta:"#bb7744",cyan:"#c9a554",white:"#d7c483",brightBlack:"#666666",brightRed:"#685742",brightGreen:"#5f875f",brightYellow:"#b36d43",brightBlue:"#78824b",brightMagenta:"#bb7744",brightCyan:"#c9a554",brightWhite:"#d7c483"},github:{background:"#1c2128",foreground:"#adbac7",cursor:"#adbac7",cursorAccent:"#1c2128",selectionBackground:"#adbac7",selectionForeground:"#1c2128",black:"#545d68",red:"#f47067",green:"#57ab5a",yellow:"#c69026",blue:"#539bf5",magenta:"#b083f0",cyan:"#39c5cf",white:"#909dab",brightBlack:"#636e7b",brightRed:"#ff938a",brightGreen:"#6bc46d",brightYellow:"#daaa3f",brightBlue:"#6cb6ff",brightMagenta:"#dcbdfb",brightCyan:"#56d4dd",brightWhite:"#cdd9e5"},gotham:{background:"#0c1014",foreground:"#99d1ce",cursor:"#99d1ce",cursorAccent:"#0c1014",selectionBackground:"#99d1ce",selectionForeground:"#0c1014",black:"#0c1014",red:"#c23127",green:"#2aa889",yellow:"#edb443",blue:"#195466",magenta:"#4e5166",cyan:"#33859e",white:"#99d1ce",brightBlack:"#0c1014",brightRed:"#c23127",brightGreen:"#2aa889",brightYellow:"#edb443",brightBlue:"#195466",brightMagenta:"#4e5166",brightCyan:"#33859e",brightWhite:"#99d1ce"}};function m0(j){let V={};if(j.dataset.fontFamily){let $=j.dataset.fontFamily;if($.startsWith("var(")){let Z=$.match(/var\(([^)]+)\)/);if(Z){let P=Z[1].trim(),J=getComputedStyle(document.documentElement).getPropertyValue(P).trim();if(J)$=J;else console.warn(`[webterm] CSS variable ${P} not found, using default font`),$=z0}}V.fontFamily=$}if(j.dataset.fontSize)V.fontSize=parseInt(j.dataset.fontSize,10);if(j.dataset.scrollback)V.scrollback=parseInt(j.dataset.scrollback,10);if(j.dataset.theme){let $=j.dataset.theme.toLowerCase();if($ in p)V.theme=p[$];else try{V.theme=JSON.parse(j.dataset.theme)}catch(Z){console.warn(`[webterm] Unknown theme "${j.dataset.theme}"`,Z)}}return V}function p0(){let j=document.querySelectorAll('script[src*="terminal.js"]');if(j.length>0){let V=j[0].src;return V.substring(0,V.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function n(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}var k0={"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+","[":"{","]":"}","\\":"|",";":":","'":'"',",":"<",".":">","/":"?"},w0={"2":"@","3":"[","4":"\\","5":"]","6":"^","7":"_","8":"?"},c0=["\x1BOP","\x1BOQ","\x1BOR","\x1BOS","\x1B[15~","\x1B[17~","\x1B[18~","\x1B[19~","\x1B[20~","\x1B[21~"],D0=["\x1B[23~","\x1B[24~","\x1B[25~","\x1B[26~","\x1B[28~","\x1B[29~","\x1B[31~","\x1B[32~","\x1B[33~","\x1B[34~"];function y0(j){if(j.length!==1)return j;if(j>="a"&&j<="z")return j.toUpperCase();return k0[j]??j}function R0(j){if(j.length!==1)return j;let V=w0[j]??j;if(V==="?")return"";let $=V.toUpperCase().charCodeAt(0);if($>=64&&$<=95)return String.fromCharCode($-64);return j}function o(j,V){if(j.length!==1)return null;let $="1234567890".indexOf(j);if($<0)return null;return V?D0[$]:c0[$]}function S(j){if(!j||j.startsWith("\x1B"))return j;return`\x1B${j}`}function C(j,V,$,Z,P){if(j.length!==1)return j;if(P){let J=o(j,V);if(J)return Z?S(J):J}if($){let J=R0(j);if(J!==j)return Z?S(J):J}if(V){let J=y0(j);return Z?S(J):J}return Z?S(j):j}class k{terminal;fitAddon;socket=null;socketGeneration=0;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;heartbeatIntervalMs=15000;stallTimeoutMs=45000;heartbeatTimer;lastMessageAt=0;lastPongAt=0;messageQueue=[];pendingStdin="";pendingStdinTimer;lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;altActive=!1;shiftActive=!1;fnActive=!1;pendingCtrl=!1;pendingAlt=!1;pendingShift=!1;pendingFn=!1;fontFamily;fontSize;cleanupTimer;resizeObserver=null;mobileKeybarStyle=null;boundHandlers=[];isTabHidden=!1;hiddenBuffer=[];hiddenBufferBytes=0;baseTitle;bellActive=!1;routeKey;static sharedTextEncoder=new TextEncoder;constructor(j,V,$,Z,P,J,O,X){this.element=j,this.wsUrl=V,this.terminal=$,this.fitAddon=Z,this.fontFamily=P,this.fontSize=J,this.routeKey=O,this.baseTitle=X}addTrackedListener(j,V,$,Z){j.addEventListener(V,$,Z),this.boundHandlers.push({target:j,type:V,handler:$,options:Z})}bellStorageKey(){if(!this.routeKey)return null;return`webterm:bell:${this.routeKey}`}bellSuppressUntil=0;setBellActive(){if(Date.now(){if(typeof this.terminal.loadFonts==="function")this.terminal.loadFonts();this.fit()}),this.setupResizeObserver(),this.addTrackedListener(window,"resize",()=>{this.fit()}),this.terminal.onData((V)=>{this.clearBellState(),this.sendStdin(V)}),this.terminal.onBell(()=>{this.setBellActive()}),this.addTrackedListener(this.element,"mousedown",()=>{if(this.bellActive)this.clearBellState()}),this.terminal.onResize((V)=>{if(this.isValidSize(V.cols,V.rows))this.lastValidSize={cols:V.cols,rows:V.rows},this.send(["resize",{width:V.cols,height:V.rows}])}),this.setupMobileKeyboard(),this.setupTouchSelection(),n())this.setupMobileKeybar();if(this.isTabHidden=document.hidden,this.startResourceCleanup(),this.connect(),document.hasFocus())this.clearBellState();let j=()=>{if(this.clearBellState(),n())this.focusMobileInput();else this.terminal.focus()};this.addTrackedListener(document,"visibilitychange",()=>{if(document.hidden)this.isTabHidden=!0,this.stopHeartbeatWatchdog();else this.isTabHidden=!1,this.refreshConnection(),j()}),this.addTrackedListener(window,"focus",()=>{j()}),this.addTrackedListener(window,"pageshow",()=>{j()})}setupMobileKeyboard(){let j=document.createElement("textarea");j.setAttribute("autocapitalize","off"),j.setAttribute("autocomplete","off"),j.setAttribute("autocorrect","off"),j.setAttribute("spellcheck","false"),j.setAttribute("inputmode","text"),j.setAttribute("enterkeyhint","send"),j.style.cssText=` position: absolute; left: 0; top: 0; diff --git a/webterm/static/js/terminal.ts b/webterm/static/js/terminal.ts index ba42ac3..a57804f 100644 --- a/webterm/static/js/terminal.ts +++ b/webterm/static/js/terminal.ts @@ -737,7 +737,14 @@ class WebTerminal { return `webterm:bell:${this.routeKey}`; } + private bellSuppressUntil = 0; + private setBellActive(): void { + // Suppress bells briefly after returning to the tab so that + // buffered output processed on visibility change doesn't + // immediately re-trigger the indicator we just cleared. + if (Date.now() < this.bellSuppressUntil) return; + if (!this.bellActive) { this.bellActive = true; document.title = `${BELL_EMOJI} ${this.baseTitle}`; @@ -749,6 +756,10 @@ class WebTerminal { } private clearBellState(): void { + // Suppress further bells for a short window so that buffered + // output arriving right after focus doesn't re-set the indicator. + this.bellSuppressUntil = Date.now() + 1000; + const key = this.bellStorageKey(); if (key) { localStorage.removeItem(key); @@ -846,6 +857,11 @@ class WebTerminal { this.setBellActive(); }); + // Clear bell on any mouse interaction with the terminal + this.addTrackedListener(this.element, "mousedown", () => { + if (this.bellActive) this.clearBellState(); + }); + // Handle resize this.terminal.onResize((size) => { if (this.isValidSize(size.cols, size.rows)) {