From 88667416d877419a4d45545969572e020fab84d8 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Mon, 1 Dec 2025 00:38:42 +0100 Subject: [PATCH] Update hybrid-script-monitor.tsx --- AppImage/components/hybrid-script-monitor.tsx | 102 +++++++++--------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/AppImage/components/hybrid-script-monitor.tsx b/AppImage/components/hybrid-script-monitor.tsx index 8e87b66..69b988b 100644 --- a/AppImage/components/hybrid-script-monitor.tsx +++ b/AppImage/components/hybrid-script-monitor.tsx @@ -9,9 +9,8 @@ import { Label } from "@/components/ui/label" import { ScrollArea } from "@/components/ui/scroll-area" import { Loader2, CheckCircle2, XCircle, TerminalIcon } from "lucide-react" -import { Terminal } from "xterm" -import { FitAddon } from "xterm-addon-fit" -import "xterm/css/xterm.css" +import type { Terminal } from "xterm" +import type { FitAddon } from "xterm-addon-fit" interface HybridScriptMonitorProps { sessionId: string | null @@ -57,57 +56,64 @@ export function HybridScriptMonitor({ } useEffect(() => { - if (!terminalRef.current || xtermRef.current) return + if (!terminalRef.current || xtermRef.current || typeof window === "undefined") return - const term = new Terminal({ - cursorBlink: false, - fontSize: 13, - fontFamily: 'Menlo, Monaco, "Courier New", monospace', - theme: { - background: "#1e1e1e", - foreground: "#d4d4d4", - cursor: "#d4d4d4", - 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", - }, - convertEol: true, - disableStdin: true, // Terminal es solo lectura - }) + const loadTerminal = async () => { + const { Terminal } = await import("xterm") + const { FitAddon } = await import("xterm-addon-fit") + await import("xterm/css/xterm.css") - const fitAddon = new FitAddon() - term.loadAddon(fitAddon) - term.open(terminalRef.current) - fitAddon.fit() + const term = new Terminal({ + cursorBlink: false, + fontSize: 13, + fontFamily: 'Menlo, Monaco, "Courier New", monospace', + theme: { + background: "#1e1e1e", + foreground: "#d4d4d4", + cursor: "#d4d4d4", + 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", + }, + convertEol: true, + disableStdin: true, + }) - xtermRef.current = term - fitAddonRef.current = fitAddon - - // Ajustar terminal cuando cambia el tamaƱo - const resizeObserver = new ResizeObserver(() => { + const fitAddon = new FitAddon() + term.loadAddon(fitAddon) + term.open(terminalRef.current!) fitAddon.fit() - }) - resizeObserver.observe(terminalRef.current) - return () => { - resizeObserver.disconnect() - term.dispose() - xtermRef.current = null - fitAddonRef.current = null + xtermRef.current = term + fitAddonRef.current = fitAddon + + const resizeObserver = new ResizeObserver(() => { + fitAddon.fit() + }) + resizeObserver.observe(terminalRef.current!) + + return () => { + resizeObserver.disconnect() + term.dispose() + xtermRef.current = null + fitAddonRef.current = null + } } + + loadTerminal() }, []) useEffect(() => {