From 2c53b1d99769a3f7d2e5f6c8b350b00ca5ad799b Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Sun, 14 Dec 2025 23:16:35 +0800 Subject: [PATCH] Adds per-log theme and font size controls to log replay Enables users to customize terminal theme and font size for each log replay, improving readability and personalization of the log view experience. Updates persist in the log model, and theme/font changes apply instantly without recreating the terminal. Also improves UI for these controls and tidies minor imports. --- App.tsx | 39 +++++---- components/KeychainManager.tsx | 2 - components/KnownHostsManager.tsx | 6 +- components/LogView.tsx | 141 +++++++++++++++++++++++++------ domain/models.ts | 2 + 5 files changed, 144 insertions(+), 46 deletions(-) diff --git a/App.tsx b/App.tsx index 2421b3702..468defdc4 100755 --- a/App.tsx +++ b/App.tsx @@ -6,7 +6,7 @@ import { useVaultState } from './application/state/useVaultState'; import { useWindowControls } from './application/state/useWindowControls'; import { matchesKeyBinding } from './domain/models'; import { netcattyBridge } from './infrastructure/services/netcattyBridge'; -import LogView from './components/LogView'; +import LogView from './components/LogView.tsx'; import ProtocolSelectDialog from './components/ProtocolSelectDialog'; import { QuickSwitcher } from './components/QuickSwitcher'; import SettingsDialog from './components/SettingsDialog'; @@ -20,7 +20,7 @@ import { Label } from './components/ui/label'; import { ToastProvider } from './components/ui/toast'; import { VaultView, VaultSection } from './components/VaultView'; import { cn } from './lib/utils'; -import { Host, HostProtocol, TerminalTheme } from './types'; +import { ConnectionLog, Host, HostProtocol, TerminalTheme } from './types'; import { LogView as LogViewType } from './application/state/useSessionState'; // Visibility container for VaultView - isolates isActive subscription @@ -40,12 +40,13 @@ const VaultViewContainer: React.FC<{ children: React.ReactNode }> = ({ children // LogView wrapper - manages visibility based on active tab interface LogViewWrapperProps { logView: LogViewType; - terminalTheme: TerminalTheme; - fontSize: number; + defaultTerminalTheme: TerminalTheme; + defaultFontSize: number; onClose: () => void; + onUpdateLog: (logId: string, updates: Partial) => void; } -const LogViewWrapper: React.FC = ({ logView, terminalTheme, fontSize, onClose }) => { +const LogViewWrapper: React.FC = ({ logView, defaultTerminalTheme, defaultFontSize, onClose, onUpdateLog }) => { const activeTabId = useActiveTabId(); const isVisible = activeTabId === logView.id; @@ -58,10 +59,11 @@ const LogViewWrapper: React.FC = ({ logView, terminalTheme,
); @@ -672,15 +674,20 @@ function App() { /> {/* Log Views - readonly terminal replays */} - {logViews.map(logView => ( - closeLogView(logView.id)} - /> - ))} + {logViews.map(logView => { + // Get the latest log data from connectionLogs to reflect updates + const latestLog = connectionLogs.find(l => l.id === logView.connectionLogId) || logView.log; + return ( + closeLogView(logView.id)} + onUpdateLog={updateConnectionLog} + /> + ); + })} > "$FILE"`); } }, [ draftKey, - isMac, - hasBrowserWebAuthn, createCredentialInBrowser, onSave, closePanel, diff --git a/components/KnownHostsManager.tsx b/components/KnownHostsManager.tsx index 545d96063..53e266f78 100644 --- a/components/KnownHostsManager.tsx +++ b/components/KnownHostsManager.tsx @@ -1,10 +1,8 @@ import { ArrowRight, ChevronDown, - Clock, FolderOpen, Import, - Key, LayoutGrid, List as ListIcon, RefreshCw, @@ -51,7 +49,7 @@ interface KnownHostsManagerProps { type ViewMode = "grid" | "list"; // Helper functions outside component for stable references -const formatDateFn = (timestamp: number) => { +const _formatDateFn = (timestamp: number) => { return new Date(timestamp).toLocaleDateString("en-US", { year: "numeric", month: "short", @@ -59,7 +57,7 @@ const formatDateFn = (timestamp: number) => { }); }; -const getKeyTypeColorFn = (keyType: string) => { +const _getKeyTypeColorFn = (keyType: string) => { switch (keyType.toLowerCase()) { case "ssh-ed25519": return "text-emerald-500"; diff --git a/components/LogView.tsx b/components/LogView.tsx index 616c654da..88ccfb131 100644 --- a/components/LogView.tsx +++ b/components/LogView.tsx @@ -2,34 +2,46 @@ import { Terminal as XTerm } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import { WebglAddon } from "@xterm/addon-webgl"; import "@xterm/xterm/css/xterm.css"; -import { FileText, X } from "lucide-react"; -import React, { memo, useEffect, useMemo, useRef, useState } from "react"; +import { ChevronDown, FileText, Minus, Plus, X } from "lucide-react"; +import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from "react"; import { cn } from "../lib/utils"; import { ConnectionLog, TerminalTheme } from "../types"; import { TERMINAL_THEMES } from "../infrastructure/config/terminalThemes"; import { Button } from "./ui/button"; +import { Dropdown, DropdownContent, DropdownTrigger } from "./ui/dropdown"; interface LogViewProps { log: ConnectionLog; - terminalTheme: TerminalTheme; - fontSize: number; + defaultTerminalTheme: TerminalTheme; + defaultFontSize: number; isVisible: boolean; onClose: () => void; + onUpdateLog: (logId: string, updates: Partial) => void; } const LogViewComponent: React.FC = ({ log, - terminalTheme, - fontSize, + defaultTerminalTheme, + defaultFontSize, isVisible, onClose, + onUpdateLog, }) => { const containerRef = useRef(null); const termRef = useRef(null); const fitAddonRef = useRef(null); const [isReady, setIsReady] = useState(false); + const [themeDropdownOpen, setThemeDropdownOpen] = useState(false); - console.log('[LogView] Render', { logId: log.id, isVisible, hasTerminalData: !!log.terminalData }); + // Use log's saved theme/fontSize or fall back to defaults + const currentTheme = useMemo(() => { + if (log.themeId) { + return TERMINAL_THEMES.find(t => t.id === log.themeId) || defaultTerminalTheme; + } + return defaultTerminalTheme; + }, [log.themeId, defaultTerminalTheme]); + + const currentFontSize = log.fontSize ?? defaultFontSize; // Format date for display const formattedDate = useMemo(() => { @@ -43,22 +55,31 @@ const LogViewComponent: React.FC = ({ }); }, [log.startTime]); + // Handle theme change + const handleThemeChange = useCallback((themeId: string) => { + onUpdateLog(log.id, { themeId }); + setThemeDropdownOpen(false); + }, [log.id, onUpdateLog]); + + // Handle font size change + const handleFontSizeChange = useCallback((delta: number) => { + const newSize = Math.max(8, Math.min(24, currentFontSize + delta)); + onUpdateLog(log.id, { fontSize: newSize }); + }, [log.id, currentFontSize, onUpdateLog]); + // Initialize terminal useEffect(() => { - console.log('[LogView] useEffect', { isVisible, hasContainer: !!containerRef.current }); if (!containerRef.current || !isVisible) return; - console.log('[LogView] Creating terminal'); - // Create terminal const term = new XTerm({ fontFamily: '"JetBrains Mono", "SF Mono", Monaco, Menlo, monospace', - fontSize: fontSize, + fontSize: currentFontSize, cursorBlink: false, cursorStyle: "underline", allowProposedApi: true, disableStdin: true, // Read-only mode - theme: terminalTheme.theme, + theme: currentTheme.colors, scrollback: 10000, }); @@ -71,13 +92,12 @@ const LogViewComponent: React.FC = ({ // Open terminal term.open(containerRef.current); - console.log('[LogView] Terminal opened'); // Try to load WebGL addon for better performance try { const webglAddon = new WebglAddon(); term.loadAddon(webglAddon); - } catch (e) { + } catch { // WebGL not available, canvas renderer will be used } @@ -85,14 +105,12 @@ const LogViewComponent: React.FC = ({ setTimeout(() => { try { fitAddon.fit(); - console.log('[LogView] Terminal fitted'); } catch { // Ignore fit errors } }, 50); // Write terminal data if available - console.log('[LogView] Writing data, hasTerminalData:', !!log.terminalData, 'length:', log.terminalData?.length); if (log.terminalData) { term.write(log.terminalData); } else { @@ -120,14 +138,32 @@ const LogViewComponent: React.FC = ({ fitAddonRef.current = null; setIsReady(false); }; - }, [isVisible, log.terminalData, log.hostname, log.username, log.protocol, formattedDate, log.endTime, log.startTime, fontSize, terminalTheme.theme]); + // Only re-create terminal when visibility or terminalData changes + // Theme and font size updates are handled separately + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isVisible, log.id, log.terminalData]); - // Update theme + // Update theme instantly without recreating terminal useEffect(() => { if (termRef.current && isReady) { - termRef.current.options.theme = terminalTheme.theme; + termRef.current.options.theme = currentTheme.colors; } - }, [terminalTheme, isReady]); + }, [currentTheme, isReady]); + + // Update font size instantly without recreating terminal + useEffect(() => { + if (termRef.current && isReady) { + termRef.current.options.fontSize = currentFontSize; + // Refit after font size change + setTimeout(() => { + try { + fitAddonRef.current?.fit(); + } catch { + // Ignore fit errors + } + }, 10); + } + }, [currentFontSize, isReady]); // Handle resize useEffect(() => { @@ -180,8 +216,63 @@ const LogViewComponent: React.FC = ({
+ {/* Theme selector */} + + + + + + {TERMINAL_THEMES.map(theme => ( + + ))} + + + + {/* Font size controls */} +
+ + {currentFontSize} + +
+ - Read-only Log Replay + Read-only