diff --git a/src/webterm/static/js/terminal.js b/src/webterm/static/js/terminal.js index d391421..71335bd 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={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.xterm;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(()=>{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=` position: absolute; left: 0; top: 0; diff --git a/src/webterm/static/js/terminal.ts b/src/webterm/static/js/terminal.ts index b097488..f5caced 100644 --- a/src/webterm/static/js/terminal.ts +++ b/src/webterm/static/js/terminal.ts @@ -16,7 +16,31 @@ const DEFAULT_FONT_FAMILY = /** Predefined terminal themes */ const THEMES: Record = { - // Classic xterm - default theme (VGA colors, pure black background) + // Tango - default theme (GNOME/xterm.js colors) + 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", + }, + // Classic xterm (VGA colors, pure black background) xterm: { background: "#000000", foreground: "#e5e5e5", @@ -407,7 +431,7 @@ class WebTerminal { console.log("[webterm:create] Ghostty loaded:", ghostty); // Build terminal options - const themeToUse = config.theme ?? THEMES.xterm; + const themeToUse = config.theme ?? THEMES.tango; console.log("[webterm:create] Theme to use (config.theme ?? THEMES.xterm):", JSON.stringify(themeToUse, null, 2)); const fontFamily = config.fontFamily?.trim() || DEFAULT_FONT_FAMILY; const fontSize = config.fontSize ?? 16;