From 83bbd65c49174b44e11b602a5192e5f854a45be1 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Thu, 29 Jan 2026 18:23:44 +0000 Subject: [PATCH] fix: terminal rendering and dashboard issues - Fix escape sequence display: filter DA1 responses that can be split across socket reads - Fix font rendering: use ghostty-web renderer API (setFontFamily/remeasureFont) - Fix sparklines: update slug-to-service mapping when containers are added/removed - Improve typeahead thumbnails: increase to 96x72px (4:3 ratio) --- src/webterm/docker_exec_session.py | 14 ++++++++++++-- src/webterm/local_server.py | 9 ++++++++- src/webterm/static/js/terminal.js | 2 +- src/webterm/static/js/terminal.ts | 9 ++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/webterm/docker_exec_session.py b/src/webterm/docker_exec_session.py index 6383b81..bb95467 100644 --- a/src/webterm/docker_exec_session.py +++ b/src/webterm/docker_exec_session.py @@ -6,6 +6,7 @@ import asyncio import contextlib import json import logging +import re import socket from collections import deque from dataclasses import dataclass @@ -27,6 +28,10 @@ REPLAY_BUFFER_SIZE = 256 * 1024 # 256KB DEFAULT_SCREEN_WIDTH = 132 DEFAULT_SCREEN_HEIGHT = 45 +# Pattern to filter out terminal device attribute responses that cause display issues +# These are responses to queries that shouldn't be displayed as text +DA_RESPONSE_PATTERN = re.compile(rb'\x1b\[\?[\d;]+c') + @dataclass(frozen=True) class DockerExecSpec: @@ -173,8 +178,8 @@ class DockerExecSession(Session): sock.close() detail = body.decode("utf-8", errors="replace") raise RuntimeError(f"Docker API exec start failed ({status}): {detail}") - if body: - self._pending_output += body + # Don't save body from HTTP upgrade - it contains protocol handshake data, + # not real terminal output (e.g., device attribute responses like "\x1b[?1;10;0c") sock.settimeout(None) return sock @@ -297,6 +302,11 @@ class DockerExecSession(Session): data = await queue.get() if not data: break + # Filter out device attribute responses that can cause display issues + # when split across socket reads + data = DA_RESPONSE_PATTERN.sub(b'', data) + if not data: + continue await self._add_to_replay_buffer(data) await self._update_screen(data) if self._connector: diff --git a/src/webterm/local_server.py b/src/webterm/local_server.py index 6a63c36..e82a04f 100644 --- a/src/webterm/local_server.py +++ b/src/webterm/local_server.py @@ -360,12 +360,19 @@ class LocalServer: def _on_docker_container_added(self, slug: str, name: str, command: str) -> None: """Callback when a Docker container is added.""" log.info("Container added to dashboard: %s -> %s", name, slug) + # Update slug-to-service mapping for sparklines + if self._docker_stats: + self._slug_to_service[slug] = name + log.debug("Added sparkline mapping: %s -> %s", slug, name) # Notify SSE subscribers about dashboard change self._notify_activity("__dashboard__") def _on_docker_container_removed(self, slug: str) -> None: """Callback when a Docker container is removed.""" log.info("Container removed from dashboard: %s", slug) + # Remove slug-to-service mapping + if self._docker_stats and slug in self._slug_to_service: + del self._slug_to_service[slug] # Invalidate any cached screenshots self._screenshot_cache.pop(slug, None) self._screenshot_cache_etag.pop(slug, None) @@ -769,7 +776,7 @@ class LocalServer: .floating-results .search-query {{ font-size: 18px; font-weight: bold; color: #3b82f6; }} .floating-results .result-item {{ display: flex; align-items: center; gap: 12px; padding: 12px; margin: 6px 0; border: 1px solid #334155; border-radius: 6px; cursor: pointer; transition: all 0.15s; }} .floating-results .result-item:hover, .floating-results .result-item.active {{ background: #334155; border-color: #3b82f6; }} - .floating-results .result-thumb {{ width: 72px; height: 40px; flex: 0 0 auto; border-radius: 4px; border: 1px solid #334155; background: #0b1220; object-fit: contain; }} + .floating-results .result-thumb {{ width: 96px; height: 72px; flex: 0 0 auto; border-radius: 4px; border: 1px solid #334155; background: #0b1220; object-fit: contain; }} .floating-results .result-content {{ display: flex; flex-direction: column; gap: 2px; }} .floating-results .result-title {{ font-weight: bold; margin-bottom: 4px; }} .floating-results .result-meta {{ font-size: 12px; color: #94a3b8; }} diff --git a/src/webterm/static/js/terminal.js b/src/webterm/static/js/terminal.js index 71335bd..e5f4789 100644 --- a/src/webterm/static/js/terminal.js +++ b/src/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 s}var W0='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',F={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#555753",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:"#d4d4d4",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:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#5b595c",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:"#403838",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:"#264f78",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:"#add6ff",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:"#44475a",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:"#45475a",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:"#434c5e",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:"#504945",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:"#073642",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:"#33467c",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"}};function z0(V){console.log("[webterm:parseConfig] Parsing config from element");let Z={};if(V.dataset.fontFamily)Z.fontFamily=V.dataset.fontFamily,console.log(`[webterm:parseConfig] fontFamily: "${Z.fontFamily}"`);if(V.dataset.fontSize)Z.fontSize=parseInt(V.dataset.fontSize,10),console.log(`[webterm:parseConfig] fontSize: ${Z.fontSize}`);if(V.dataset.scrollback)Z.scrollback=parseInt(V.dataset.scrollback,10),console.log(`[webterm:parseConfig] scrollback: ${Z.scrollback}`);if(V.dataset.theme){let j=V.dataset.theme.toLowerCase();if(console.log(`[webterm:parseConfig] theme attribute: "${V.dataset.theme}" -> normalized: "${j}"`),console.log(`[webterm:parseConfig] Available themes: ${Object.keys(F).join(", ")}`),console.log(`[webterm:parseConfig] Theme "${j}" in THEMES? ${j in F}`),j in F)Z.theme=F[j],console.log(`[webterm:parseConfig] Using built-in theme "${j}":`,JSON.stringify(Z.theme,null,2));else{console.log("[webterm:parseConfig] Theme not found in THEMES, trying JSON parse...");try{Z.theme=JSON.parse(V.dataset.theme),console.log("[webterm:parseConfig] Parsed custom JSON theme:",Z.theme)}catch($){console.warn(`[webterm:parseConfig] Unknown theme "${V.dataset.theme}", JSON parse failed:`,$)}}}else console.log("[webterm:parseConfig] No theme attribute found on element");return console.log("[webterm:parseConfig] Final config:",Z),Z}function H0(){let V=document.querySelectorAll('script[src*="terminal.js"]');if(V.length>0){let Z=V[0].src;return Z.substring(0,Z.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function G0(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}class m{terminal;fitAddon;socket=null;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;messageQueue=[];lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;shiftActive=!1;fontFamily;fontSize;constructor(V,Z,j,$,P,X){this.element=V,this.wsUrl=Z,this.terminal=j,this.fitAddon=$,this.fontFamily=P,this.fontSize=X}static async create(V,Z,j){console.log("[webterm:create] WebTerminal.create() called"),console.log("[webterm:create] Container:",V),console.log("[webterm:create] wsUrl:",Z),console.log("[webterm:create] Config received:",JSON.stringify(j,null,2));let $=H0();console.log("[webterm:create] WASM path:",$),console.log("[webterm:create] Loading Ghostty WASM...");let P=await v.load($);console.log("[webterm:create] Ghostty loaded:",P);let X=j.theme??F.tango;console.log("[webterm:create] Theme to use (config.theme ?? THEMES.xterm):",JSON.stringify(X,null,2));let R=j.fontFamily?.trim()||W0,L=j.fontSize??16,K={fontFamily:R,fontSize:L,scrollback:j.scrollback??1000,cursorBlink:!0,cursorStyle:"block",theme:X,ghostty:P};console.log("[webterm:create] Full ITerminalOptions:",JSON.stringify(K,null,2)),console.log("[webterm:create] Creating ghostty-web Terminal instance...");let Y=new w(K);console.log("[webterm:create] Terminal created:",Y),console.log("[webterm:create] Terminal.options:",Y.options),console.log("[webterm:create] Creating FitAddon...");let _=new h;console.log("[webterm:create] Loading FitAddon into terminal..."),Y.loadAddon(_),console.log("[webterm:create] Calling terminal.open(container)..."),Y.open(V),console.log("[webterm:create] terminal.open() completed");let z=Y;if(console.log("[webterm:create] Terminal internal keys:",Object.keys(z)),z.renderer){console.log("[webterm:create] Renderer exists:",z.renderer);let W=z.renderer;if(console.log("[webterm:create] Renderer keys:",Object.keys(W)),W.theme)console.log("[webterm:create] Renderer.theme:",W.theme);if(W.palette)console.log("[webterm:create] Renderer.palette:",W.palette)}let u=new m(V,Z,Y,_,R,L);return console.log("[webterm:create] WebTerminal instance created"),u.initialize(),console.log("[webterm:create] WebTerminal initialized"),u}initialize(){console.log("[webterm:init] initialize() called");let V=this.element.querySelector("canvas");if(console.log("[webterm:init] Canvas element:",V),V)console.log("[webterm:init] Canvas dimensions:",{width:V.width,height:V.height,clientWidth:V.clientWidth,clientHeight:V.clientHeight,style:V.style.cssText});if(console.log("[webterm:init] Container dimensions:",{clientWidth:this.element.clientWidth,clientHeight:this.element.clientHeight}),this.waitForFonts().then(()=>{if(console.log("[webterm:init] Fonts loaded, reapplying font family and fitting..."),this.terminal.options.fontFamily=this.fontFamily,typeof this.terminal.loadFonts==="function")this.terminal.loadFonts();this.fit(),console.log("[webterm:init] fit() completed");let Z=this.element.querySelector("canvas");if(Z)console.log("[webterm:init] Canvas after fit:",{width:Z.width,height:Z.height,clientWidth:Z.clientWidth,clientHeight:Z.clientHeight})}),this.setupResizeObserver(),window.addEventListener("resize",()=>{this.fit()}),this.terminal.onData((Z)=>{this.send(["stdin",Z])}),this.terminal.onResize((Z)=>{if(this.isValidSize(Z.cols,Z.rows))this.lastValidSize={cols:Z.cols,rows:Z.rows},this.send(["resize",{width:Z.cols,height:Z.rows}])}),this.setupMobileKeyboard(),G0())this.setupMobileKeybar();this.connect()}setupMobileKeyboard(){let V=document.createElement("textarea");V.setAttribute("autocapitalize","off"),V.setAttribute("autocomplete","off"),V.setAttribute("autocorrect","off"),V.setAttribute("spellcheck","false"),V.setAttribute("inputmode","text"),V.setAttribute("enterkeyhint","send"),V.style.cssText=` + const term = new Terminal({ ghostty });`);return s}var W0='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',F={tango:{background:"#000000",foreground:"#d3d7cf",cursor:"#d3d7cf",cursorAccent:"#000000",selectionBackground:"#555753",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:"#d4d4d4",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:"#2d2a2e",foreground:"#fcfcfa",cursor:"#fcfcfa",cursorAccent:"#2d2a2e",selectionBackground:"#5b595c",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:"#403838",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:"#264f78",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:"#add6ff",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:"#44475a",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:"#45475a",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:"#434c5e",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:"#504945",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:"#073642",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:"#33467c",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"}};function z0(V){console.log("[webterm:parseConfig] Parsing config from element");let Z={};if(V.dataset.fontFamily)Z.fontFamily=V.dataset.fontFamily,console.log(`[webterm:parseConfig] fontFamily: "${Z.fontFamily}"`);if(V.dataset.fontSize)Z.fontSize=parseInt(V.dataset.fontSize,10),console.log(`[webterm:parseConfig] fontSize: ${Z.fontSize}`);if(V.dataset.scrollback)Z.scrollback=parseInt(V.dataset.scrollback,10),console.log(`[webterm:parseConfig] scrollback: ${Z.scrollback}`);if(V.dataset.theme){let j=V.dataset.theme.toLowerCase();if(console.log(`[webterm:parseConfig] theme attribute: "${V.dataset.theme}" -> normalized: "${j}"`),console.log(`[webterm:parseConfig] Available themes: ${Object.keys(F).join(", ")}`),console.log(`[webterm:parseConfig] Theme "${j}" in THEMES? ${j in F}`),j in F)Z.theme=F[j],console.log(`[webterm:parseConfig] Using built-in theme "${j}":`,JSON.stringify(Z.theme,null,2));else{console.log("[webterm:parseConfig] Theme not found in THEMES, trying JSON parse...");try{Z.theme=JSON.parse(V.dataset.theme),console.log("[webterm:parseConfig] Parsed custom JSON theme:",Z.theme)}catch($){console.warn(`[webterm:parseConfig] Unknown theme "${V.dataset.theme}", JSON parse failed:`,$)}}}else console.log("[webterm:parseConfig] No theme attribute found on element");return console.log("[webterm:parseConfig] Final config:",Z),Z}function H0(){let V=document.querySelectorAll('script[src*="terminal.js"]');if(V.length>0){let Z=V[0].src;return Z.substring(0,Z.lastIndexOf("/")+1)+"ghostty-vt.wasm"}return"/static/js/ghostty-vt.wasm"}function G0(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window&&navigator.maxTouchPoints>0}class m{terminal;fitAddon;socket=null;element;wsUrl;reconnectAttempts=0;maxReconnectAttempts=5;reconnectDelay=1000;messageQueue=[];lastValidSize=null;mobileInput=null;mobileKeybar=null;ctrlActive=!1;shiftActive=!1;fontFamily;fontSize;constructor(V,Z,j,$,P,X){this.element=V,this.wsUrl=Z,this.terminal=j,this.fitAddon=$,this.fontFamily=P,this.fontSize=X}static async create(V,Z,j){console.log("[webterm:create] WebTerminal.create() called"),console.log("[webterm:create] Container:",V),console.log("[webterm:create] wsUrl:",Z),console.log("[webterm:create] Config received:",JSON.stringify(j,null,2));let $=H0();console.log("[webterm:create] WASM path:",$),console.log("[webterm:create] Loading Ghostty WASM...");let P=await v.load($);console.log("[webterm:create] Ghostty loaded:",P);let X=j.theme??F.tango;console.log("[webterm:create] Theme to use (config.theme ?? THEMES.xterm):",JSON.stringify(X,null,2));let R=j.fontFamily?.trim()||W0,L=j.fontSize??16,K={fontFamily:R,fontSize:L,scrollback:j.scrollback??1000,cursorBlink:!0,cursorStyle:"block",theme:X,ghostty:P};console.log("[webterm:create] Full ITerminalOptions:",JSON.stringify(K,null,2)),console.log("[webterm:create] Creating ghostty-web Terminal instance...");let Y=new w(K);console.log("[webterm:create] Terminal created:",Y),console.log("[webterm:create] Terminal.options:",Y.options),console.log("[webterm:create] Creating FitAddon...");let _=new h;console.log("[webterm:create] Loading FitAddon into terminal..."),Y.loadAddon(_),console.log("[webterm:create] Calling terminal.open(container)..."),Y.open(V),console.log("[webterm:create] terminal.open() completed");let z=Y;if(console.log("[webterm:create] Terminal internal keys:",Object.keys(z)),z.renderer){console.log("[webterm:create] Renderer exists:",z.renderer);let W=z.renderer;if(console.log("[webterm:create] Renderer keys:",Object.keys(W)),W.theme)console.log("[webterm:create] Renderer.theme:",W.theme);if(W.palette)console.log("[webterm:create] Renderer.palette:",W.palette)}let u=new m(V,Z,Y,_,R,L);return console.log("[webterm:create] WebTerminal instance created"),u.initialize(),console.log("[webterm:create] WebTerminal initialized"),u}initialize(){console.log("[webterm:init] initialize() called");let V=this.element.querySelector("canvas");if(console.log("[webterm:init] Canvas element:",V),V)console.log("[webterm:init] Canvas dimensions:",{width:V.width,height:V.height,clientWidth:V.clientWidth,clientHeight:V.clientHeight,style:V.style.cssText});if(console.log("[webterm:init] Container dimensions:",{clientWidth:this.element.clientWidth,clientHeight:this.element.clientHeight}),this.waitForFonts().then(()=>{console.log("[webterm:init] Fonts loaded, reapplying font family and fitting...");let Z=this.terminal.renderer;if(Z)Z.setFontFamily(this.fontFamily),Z.remeasureFont(),console.log("[webterm:init] Font family updated via renderer");this.fit(),console.log("[webterm:init] fit() completed");let j=this.element.querySelector("canvas");if(j)console.log("[webterm:init] Canvas after fit:",{width:j.width,height:j.height,clientWidth:j.clientWidth,clientHeight:j.clientHeight})}),this.setupResizeObserver(),window.addEventListener("resize",()=>{this.fit()}),this.terminal.onData((Z)=>{this.send(["stdin",Z])}),this.terminal.onResize((Z)=>{if(this.isValidSize(Z.cols,Z.rows))this.lastValidSize={cols:Z.cols,rows:Z.rows},this.send(["resize",{width:Z.cols,height:Z.rows}])}),this.setupMobileKeyboard(),G0())this.setupMobileKeybar();this.connect()}setupMobileKeyboard(){let V=document.createElement("textarea");V.setAttribute("autocapitalize","off"),V.setAttribute("autocomplete","off"),V.setAttribute("autocorrect","off"),V.setAttribute("spellcheck","false"),V.setAttribute("inputmode","text"),V.setAttribute("enterkeyhint","send"),V.style.cssText=` position: absolute; left: 0; top: 0; diff --git a/src/webterm/static/js/terminal.ts b/src/webterm/static/js/terminal.ts index f5caced..f6183dc 100644 --- a/src/webterm/static/js/terminal.ts +++ b/src/webterm/static/js/terminal.ts @@ -515,9 +515,12 @@ class WebTerminal { // Wait for fonts to load before fitting to ensure correct measurements this.waitForFonts().then(() => { console.log("[webterm:init] Fonts loaded, reapplying font family and fitting..."); - this.terminal.options.fontFamily = this.fontFamily; - if (typeof (this.terminal as unknown as { loadFonts?: () => void }).loadFonts === "function") { - (this.terminal as unknown as { loadFonts: () => void }).loadFonts(); + // Use renderer's setFontFamily method to properly update fonts + const renderer = (this.terminal as unknown as { renderer?: { setFontFamily: (family: string) => void; remeasureFont: () => void } }).renderer; + if (renderer) { + renderer.setFontFamily(this.fontFamily); + renderer.remeasureFont(); + console.log("[webterm:init] Font family updated via renderer"); } this.fit(); console.log("[webterm:init] fit() completed");