diff --git a/App.tsx b/App.tsx index 5d8a02404..97d713dbb 100755 --- a/App.tsx +++ b/App.tsx @@ -476,6 +476,7 @@ function App() { knownHosts={knownHosts} draggingSessionId={draggingSessionId} terminalTheme={currentTerminalTheme} + terminalSettings={terminalSettings} fontSize={terminalFontSize} hotkeyScheme={hotkeyScheme} keyBindings={keyBindings} diff --git a/application/state/useSettingsState.ts b/application/state/useSettingsState.ts index 3e620910f..c25198b5e 100644 --- a/application/state/useSettingsState.ts +++ b/application/state/useSettingsState.ts @@ -108,11 +108,39 @@ export const useSettingsState = () => { // ignore parse errors } } + // Sync terminal settings from other windows + if (e.key === STORAGE_KEY_TERM_SETTINGS && e.newValue) { + try { + const newSettings = JSON.parse(e.newValue) as TerminalSettings; + setTerminalSettings(prev => ({ ...DEFAULT_TERMINAL_SETTINGS, ...newSettings })); + } catch { + // ignore parse errors + } + } + // Sync terminal theme from other windows + if (e.key === STORAGE_KEY_TERM_THEME && e.newValue) { + if (e.newValue !== terminalThemeId) { + setTerminalThemeId(e.newValue); + } + } + // Sync terminal font family from other windows + if (e.key === STORAGE_KEY_TERM_FONT_FAMILY && e.newValue) { + if (e.newValue !== terminalFontFamilyId) { + setTerminalFontFamilyId(e.newValue); + } + } + // Sync terminal font size from other windows + if (e.key === STORAGE_KEY_TERM_FONT_SIZE && e.newValue) { + const newSize = parseInt(e.newValue, 10); + if (!isNaN(newSize) && newSize !== terminalFontSize) { + setTerminalFontSize(newSize); + } + } }; window.addEventListener('storage', handleStorageChange); return () => window.removeEventListener('storage', handleStorageChange); - }, [theme, primaryColor, customCSS, hotkeyScheme]); + }, [theme, primaryColor, customCSS, hotkeyScheme, terminalThemeId, terminalFontFamilyId, terminalFontSize]); useEffect(() => { localStorageAdapter.writeString(STORAGE_KEY_TERM_THEME, terminalThemeId); diff --git a/components/SettingsPage.tsx b/components/SettingsPage.tsx index 93755b41b..716153576 100644 --- a/components/SettingsPage.tsx +++ b/components/SettingsPage.tsx @@ -8,8 +8,10 @@ import { Download, Keyboard, Loader2, + Minus, Moon, Palette, + Plus, RotateCcw, Sun, TerminalSquare, @@ -21,6 +23,9 @@ import { CursorShape, RightClickBehavior, HotkeyScheme, + TerminalEmulationType, + LinkModifier, + DEFAULT_KEYWORD_HIGHLIGHT_RULES, keyEventToString, } from "../domain/models"; import { TERMINAL_THEMES } from "../infrastructure/config/terminalThemes"; @@ -604,21 +609,33 @@ export default function SettingsPage() { /> - -
- { - const val = parseInt(e.target.value); - if (val >= MIN_FONT_SIZE && val <= MAX_FONT_SIZE) { - setTerminalFontSize(val); + +
+ +
+ {terminalFontSize} +
+
@@ -631,6 +648,94 @@ export default function SettingsPage() { onChange={(v) => updateTerminalSetting("fontLigatures", v)} /> + + + updateTerminalSetting("drawBoldInBrightColors", v)} + /> + + + + updateTerminalSetting("fontWeightBold", parseInt(v))} + className="w-40" + /> + + + +
+ updateTerminalSetting("linePadding", parseInt(e.target.value))} + className="w-24 accent-primary" + /> + + {terminalSettings.linePadding} + +
+
+ + + updateTerminalSetting("minimumContrastRatio", parseInt(e.target.value))} + className="w-24 accent-primary" + /> + + {terminalSettings.minimumContrastRatio} + +
+
+ +
+ updateTerminalSetting("middleClickPaste", v)} + /> + + + + updateTerminalSetting("scrollOnInput", v)} + /> + + + + updateTerminalSetting("wordSeparators", e.target.value)} + className="w-32 text-center font-mono" + placeholder=" ()[]{}'"" + /> + + + + { const val = parseInt(e.target.value); - if (val >= 1000 && val <= 100000) { + if (!isNaN(val) && val >= 0 && val <= 100000) { updateTerminalSetting("scrollback", val); } }} - className="w-24 text-center" + className="w-full" /> - +
+ + + +
+
+ Keyword highlighting + updateTerminalSetting("keywordHighlightEnabled", v)} + /> +
+ {terminalSettings.keywordHighlightEnabled && ( +
+ {terminalSettings.keywordHighlightRules.map((rule) => ( +
+ + {rule.label} + + +
+ ))} + +
+ )}
diff --git a/components/Terminal.tsx b/components/Terminal.tsx index 4eaf999b6..17ba83089 100644 --- a/components/Terminal.tsx +++ b/components/Terminal.tsx @@ -2,6 +2,7 @@ import { Terminal as XTerm } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import { SerializeAddon } from "@xterm/addon-serialize"; import { WebglAddon } from "@xterm/addon-webgl"; +import { WebLinksAddon } from "@xterm/addon-web-links"; import "@xterm/xterm/css/xterm.css"; import { Maximize2 } from "lucide-react"; import React, { memo, useEffect, useMemo, useRef, useState } from "react"; @@ -13,6 +14,7 @@ import { Snippet, TerminalSession, TerminalTheme, + TerminalSettings, KeyBinding, } from "../types"; import { checkAppShortcut, getAppLevelActions, getTerminalPassthroughActions } from "../application/state/useGlobalHotkeys"; @@ -26,6 +28,7 @@ import { TERMINAL_THEMES } from "../infrastructure/config/terminalThemes"; import { TerminalConnectionDialog } from "./terminal/TerminalConnectionDialog"; import { TerminalToolbar } from "./terminal/TerminalToolbar"; import { TerminalContextMenu } from "./terminal/TerminalContextMenu"; +import { createHighlightProcessor } from "./terminal/keywordHighlight"; import { XTERM_PERFORMANCE_CONFIG, type XTermPlatform, @@ -45,6 +48,7 @@ interface TerminalProps { isFocused?: boolean; // Whether this terminal should have keyboard focus (for split views) fontSize: number; terminalTheme: TerminalTheme; + terminalSettings?: TerminalSettings; // Global terminal settings sessionId: string; startupCommand?: string; // Command to run after connection (for snippet runner) // Hotkey configuration @@ -88,6 +92,7 @@ const TerminalComponent: React.FC = ({ isFocused, fontSize, terminalTheme, + terminalSettings, sessionId, startupCommand, hotkeyScheme = 'disabled', @@ -116,6 +121,21 @@ const TerminalComponent: React.FC = ({ const hasRunStartupCommandRef = useRef(false); // Track if startup command has been executed const commandBufferRef = useRef(""); // Buffer for tracking typed commands + // Ref to store latest terminalSettings for use in boot function (avoids stale closure) + const terminalSettingsRef = useRef(terminalSettings); + terminalSettingsRef.current = terminalSettings; + + // Keyword highlight processor - processes terminal output for keyword highlighting + const highlightProcessorRef = useRef<(text: string) => string>((t) => t); + + // Update highlight processor when settings change + useEffect(() => { + highlightProcessorRef.current = createHighlightProcessor( + terminalSettings?.keywordHighlightRules ?? [], + terminalSettings?.keywordHighlightEnabled ?? false + ); + }, [terminalSettings?.keywordHighlightEnabled, terminalSettings?.keywordHighlightRules]); + // Refs to store latest hotkey config for use in keyboard handler const hotkeySchemeRef = useRef(hotkeyScheme); const keyBindingsRef = useRef(keyBindings); @@ -287,10 +307,38 @@ const TerminalComponent: React.FC = ({ // Use host-specific font size if available, otherwise use the global fontSize prop const effectiveFontSize = host.fontSize || fontSize; + // Apply terminal settings with defaults (use ref to get latest values) + const settings = terminalSettingsRef.current; + const cursorStyle = settings?.cursorShape ?? 'block'; + const cursorBlink = settings?.cursorBlink ?? true; + const scrollback = settings?.scrollback ?? 10000; + const fontLigatures = settings?.fontLigatures ?? true; + const drawBoldTextInBrightColors = settings?.drawBoldInBrightColors ?? true; + const fontWeight = settings?.fontWeight ?? 400; + const fontWeightBold = settings?.fontWeightBold ?? 700; + // linePadding 0-10 maps to lineHeight 1.0-2.0 + const lineHeight = 1 + (settings?.linePadding ?? 0) / 10; + const minimumContrastRatio = settings?.minimumContrastRatio ?? 1; + const scrollOnUserInput = settings?.scrollOnInput ?? true; + const altIsMeta = settings?.altAsMeta ?? false; + const wordSeparator = settings?.wordSeparators ?? " ()[]{}'\""; + const term = new XTerm({ ...performanceConfig.options, fontSize: effectiveFontSize, fontFamily: fontFamily, + fontWeight: fontWeight as 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 'normal' | 'bold', + fontWeightBold: fontWeightBold as 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 'normal' | 'bold', + lineHeight, + cursorStyle, + cursorBlink, + scrollback, + allowProposedApi: fontLigatures, // Required for font ligatures + drawBoldTextInBrightColors, + minimumContrastRatio, + scrollOnUserInput, + altClickMovesCursor: !altIsMeta, // If altAsMeta is true, don't use alt for cursor movement + wordSeparator, theme: { ...terminalTheme.colors, selectionBackground: terminalTheme.colors.selection, @@ -397,6 +445,36 @@ const TerminalComponent: React.FC = ({ scopedWindow.__xtermWebGLLoaded = webglLoaded; scopedWindow.__xtermRendererPreference = performanceConfig.preferCanvasRenderer ? "canvas" : "webgl"; + // Load web links addon for clickable URLs + const webLinksAddon = new WebLinksAddon((event, uri) => { + // Check if the required modifier key is held (read from ref for real-time updates) + const currentLinkModifier = terminalSettingsRef.current?.linkModifier ?? 'none'; + let shouldOpen = false; + switch (currentLinkModifier) { + case 'none': + shouldOpen = true; + break; + case 'ctrl': + shouldOpen = event.ctrlKey; + break; + case 'alt': + shouldOpen = event.altKey; + break; + case 'meta': + shouldOpen = event.metaKey; + break; + } + if (shouldOpen) { + // Open URL in default browser + if (window.netcatty?.openExternal) { + window.netcatty.openExternal(uri); + } else { + window.open(uri, '_blank'); + } + } + }); + term.loadAddon(webLinksAddon); + logRenderer(); // Attach custom key event handler to intercept app-level shortcuts @@ -488,6 +566,34 @@ const TerminalComponent: React.FC = ({ return true; // Let xterm handle other keys }); + // Add middle-click paste support + const middleClickPaste = settings?.middleClickPaste ?? true; + if (middleClickPaste && containerRef.current) { + const handleMiddleClick = async (e: MouseEvent) => { + if (e.button === 1) { // Middle mouse button + e.preventDefault(); + try { + const text = await navigator.clipboard.readText(); + if (text && sessionRef.current && window.netcatty?.writeToSession) { + window.netcatty.writeToSession(sessionRef.current, text); + } + } catch (err) { + console.warn('[Terminal] Failed to paste from clipboard:', err); + } + } + }; + containerRef.current.addEventListener('auxclick', handleMiddleClick); + // Store cleanup function + const container = containerRef.current; + const cleanup = () => container.removeEventListener('auxclick', handleMiddleClick); + // Add to disposal - we'll handle this in the main cleanup + const originalDispose = disposeDataRef.current; + disposeDataRef.current = () => { + cleanup(); + originalDispose?.(); + }; + } + fitAddon.fit(); term.focus(); } catch (openErr) { @@ -668,20 +774,47 @@ const TerminalComponent: React.FC = ({ } }; - // Effect for global fontSize/terminalTheme changes (from Settings) + // Effect for global fontSize/terminalTheme/terminalSettings changes (from Settings) useEffect(() => { if (termRef.current) { // Only apply global settings if host doesn't have specific overrides const effectiveFontSize = host.fontSize || fontSize; termRef.current.options.fontSize = effectiveFontSize; + + // Use effectiveTheme which respects host-specific theme override termRef.current.options.theme = { - ...terminalTheme.colors, - selectionBackground: terminalTheme.colors.selection, + ...effectiveTheme.colors, + selectionBackground: effectiveTheme.colors.selection, }; - // Refit after font size change + + // Apply all terminal settings for real-time updates + if (terminalSettings) { + // Cursor settings + termRef.current.options.cursorStyle = terminalSettings.cursorShape; + termRef.current.options.cursorBlink = terminalSettings.cursorBlink; + + // Buffer settings + termRef.current.options.scrollback = terminalSettings.scrollback; + + // Font settings + termRef.current.options.fontWeight = terminalSettings.fontWeight as 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900; + termRef.current.options.fontWeightBold = terminalSettings.fontWeightBold as 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900; + termRef.current.options.lineHeight = 1 + terminalSettings.linePadding / 10; + termRef.current.options.drawBoldTextInBrightColors = terminalSettings.drawBoldInBrightColors; + + // Accessibility + termRef.current.options.minimumContrastRatio = terminalSettings.minimumContrastRatio; + + // Input behavior + termRef.current.options.scrollOnUserInput = terminalSettings.scrollOnInput; + termRef.current.options.altClickMovesCursor = !terminalSettings.altAsMeta; + termRef.current.options.wordSeparator = terminalSettings.wordSeparators; + } + + // Refit after settings change (especially important for lineHeight changes) setTimeout(() => safeFit(), 50); } - }, [fontSize, terminalTheme, host.fontSize]); + }, [fontSize, effectiveTheme, terminalSettings, host.fontSize]); // Effect for host-specific font/theme changes (from ThemeCustomizeModal) useEffect(() => { @@ -695,21 +828,16 @@ const TerminalComponent: React.FC = ({ const fontObj = TERMINAL_FONTS.find(f => f.id === hostFontId) || TERMINAL_FONTS[0]; termRef.current.options.fontFamily = fontObj.family; - // Apply host-specific theme if set - if (host.theme) { - const hostTheme = TERMINAL_THEMES.find(t => t.id === host.theme); - if (hostTheme) { - termRef.current.options.theme = { - ...hostTheme.colors, - selectionBackground: hostTheme.colors.selection, - }; - } - } + // Apply effective theme (host-specific or global) + termRef.current.options.theme = { + ...effectiveTheme.colors, + selectionBackground: effectiveTheme.colors.selection, + }; // Refit after changes setTimeout(() => safeFit(), 50); } - }, [host.fontSize, host.fontFamily, host.theme, fontSize]); + }, [host.fontSize, host.fontFamily, host.theme, fontSize, effectiveTheme]); // Separate effect for visibility-triggered fit (less frequent) useEffect(() => { @@ -844,19 +972,27 @@ const TerminalComponent: React.FC = ({ } }, [isFocused, isVisible, sessionId]); - // Track terminal selection for context menu + // Track terminal selection for context menu and copyOnSelect useEffect(() => { const term = termRef.current; if (!term) return; const onSelectionChange = () => { const selection = term.getSelection(); - setHasSelection(!!selection && selection.length > 0); + const hasText = !!selection && selection.length > 0; + setHasSelection(hasText); + + // Copy on select if enabled + if (hasText && terminalSettings?.copyOnSelect) { + navigator.clipboard.writeText(selection).catch(err => { + console.warn('Copy on select failed:', err); + }); + } }; term.onSelectionChange(onSelectionChange); // No need to return cleanup as xterm handles it when disposed - }, []); + }, [terminalSettings?.copyOnSelect]); useEffect(() => { let resizeTimeout: ReturnType | null = null; @@ -970,6 +1106,18 @@ const TerminalComponent: React.FC = ({ } try { + // Build environment variables, including TERM from settings + const termEnv: Record = { + TERM: terminalSettings?.terminalEmulationType ?? 'xterm-256color', + }; + + // Add host-specific environment variables + if (host.environmentVariables) { + for (const { name, value } of host.environmentVariables) { + if (name) termEnv[name] = value; + } + } + const id = await window.netcatty.startSSHSession({ sessionId, hostname: host.hostname, @@ -982,14 +1130,8 @@ const TerminalComponent: React.FC = ({ cols: term.cols, rows: term.rows, charset: host.charset, - // Environment variables - env: host.environmentVariables?.reduce( - (acc, { name, value }) => { - if (name) acc[name] = value; - return acc; - }, - {} as Record, - ), + // Environment variables including TERM + env: termEnv, // New: proxy and jump host configuration proxy: proxyConfig, jumpHosts: jumpHosts.length > 0 ? jumpHosts : undefined, @@ -1003,7 +1145,8 @@ const TerminalComponent: React.FC = ({ sessionRef.current = id; disposeDataRef.current = window.netcatty.onSessionData(id, (chunk) => { - term.write(chunk); + // Apply keyword highlighting before writing to terminal + term.write(highlightProcessorRef.current(chunk)); if (!hasConnectedRef.current) { updateStatus("connected"); setChainProgress(null); // Clear chain progress on connect @@ -1113,6 +1256,18 @@ const TerminalComponent: React.FC = ({ } try { + // Build environment variables, including TERM from settings + const telnetEnv: Record = { + TERM: terminalSettings?.terminalEmulationType ?? 'xterm-256color', + }; + + // Add host-specific environment variables + if (host.environmentVariables) { + for (const { name, value } of host.environmentVariables) { + if (name) telnetEnv[name] = value; + } + } + const id = await startTelnetSession({ sessionId, hostname: host.hostname, @@ -1120,19 +1275,14 @@ const TerminalComponent: React.FC = ({ cols: term.cols, rows: term.rows, charset: host.charset, - env: host.environmentVariables?.reduce( - (acc, { name, value }) => { - if (name) acc[name] = value; - return acc; - }, - {} as Record, - ), + env: telnetEnv, }); sessionRef.current = id; disposeDataRef.current = window.netcatty?.onSessionData(id, (chunk) => { - term.write(chunk); + // Apply keyword highlighting before writing to terminal + term.write(highlightProcessorRef.current(chunk)); if (!hasConnectedRef.current) { updateStatus("connected"); setTimeout(() => { @@ -1187,6 +1337,18 @@ const TerminalComponent: React.FC = ({ } try { + // Build environment variables, including TERM from settings + const moshEnv: Record = { + TERM: terminalSettings?.terminalEmulationType ?? 'xterm-256color', + }; + + // Add host-specific environment variables + if (host.environmentVariables) { + for (const { name, value } of host.environmentVariables) { + if (name) moshEnv[name] = value; + } + } + const id = await startMoshSession({ sessionId, hostname: host.hostname, @@ -1197,19 +1359,14 @@ const TerminalComponent: React.FC = ({ cols: term.cols, rows: term.rows, charset: host.charset, - env: host.environmentVariables?.reduce( - (acc, { name, value }) => { - if (name) acc[name] = value; - return acc; - }, - {} as Record, - ), + env: moshEnv, }); sessionRef.current = id; disposeDataRef.current = window.netcatty?.onSessionData(id, (chunk) => { - term.write(chunk); + // Apply keyword highlighting before writing to terminal + term.write(highlightProcessorRef.current(chunk)); if (!hasConnectedRef.current) { updateStatus("connected"); setTimeout(() => { @@ -1285,10 +1442,14 @@ const TerminalComponent: React.FC = ({ sessionId, cols: term.cols, rows: term.rows, + env: { + TERM: terminalSettings?.terminalEmulationType ?? 'xterm-256color', + }, }); sessionRef.current = id; disposeDataRef.current = window.netcatty?.onSessionData(id, (chunk) => { - term.write(chunk); + // Apply keyword highlighting before writing to terminal + term.write(highlightProcessorRef.current(chunk)); if (!hasConnectedRef.current) { updateStatus("connected"); // Trigger fit after connection to ensure proper terminal size @@ -1491,6 +1652,16 @@ const TerminalComponent: React.FC = ({ term.clear(); }; + const handleContextSelectWord = () => { + const term = termRef.current; + if (!term) return; + // xterm.js selectWord selects the word under cursor + // Since we don't have a cursor position from right-click, we can select all as fallback + // A proper implementation would require tracking the click position + term.selectAll(); + setHasSelection(true); + }; + const renderControls = (opts?: { showClose?: boolean }) => ( = ({ onCloseSession?.(sessionId) : undefined} diff --git a/components/TerminalLayer.tsx b/components/TerminalLayer.tsx index 4f180d732..cf16c9afc 100644 --- a/components/TerminalLayer.tsx +++ b/components/TerminalLayer.tsx @@ -3,7 +3,7 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from ' import { useActiveTabId } from '../application/state/activeTabStore'; import { collectSessionIds } from '../domain/workspace'; import { SplitDirection } from '../domain/workspace'; -import { KeyBinding } from '../domain/models'; +import { KeyBinding, TerminalSettings } from '../domain/models'; import { cn } from '../lib/utils'; import { Host, KnownHost, SSHKey, Snippet, TerminalSession, TerminalTheme, Workspace, WorkspaceNode } from '../types'; import { DistroAvatar } from './DistroAvatar'; @@ -38,6 +38,7 @@ interface TerminalLayerProps { knownHosts?: KnownHost[]; draggingSessionId: string | null; terminalTheme: TerminalTheme; + terminalSettings?: TerminalSettings; fontSize?: number; hotkeyScheme?: 'disabled' | 'mac' | 'pc'; keyBindings?: KeyBinding[]; @@ -66,6 +67,7 @@ const TerminalLayerInner: React.FC = ({ knownHosts = [], draggingSessionId, terminalTheme, + terminalSettings, fontSize = 14, hotkeyScheme = 'disabled', keyBindings = [], @@ -631,6 +633,7 @@ const TerminalLayerInner: React.FC = ({ isFocused={isFocusedPane} fontSize={fontSize} terminalTheme={terminalTheme} + terminalSettings={terminalSettings} sessionId={session.id} startupCommand={session.startupCommand} hotkeyScheme={hotkeyScheme} @@ -717,6 +720,7 @@ const terminalLayerAreEqual = (prev: TerminalLayerProps, next: TerminalLayerProp prev.workspaces === next.workspaces && prev.draggingSessionId === next.draggingSessionId && prev.terminalTheme === next.terminalTheme && + prev.terminalSettings === next.terminalSettings && prev.fontSize === next.fontSize && prev.onUpdateHost === next.onUpdateHost && prev.onToggleWorkspaceViewMode === next.onToggleWorkspaceViewMode && diff --git a/components/terminal/TerminalContextMenu.tsx b/components/terminal/TerminalContextMenu.tsx index 1d517c92c..b37f9218d 100644 --- a/components/terminal/TerminalContextMenu.tsx +++ b/components/terminal/TerminalContextMenu.tsx @@ -10,7 +10,8 @@ import { Trash2, Terminal as TerminalIcon, } from 'lucide-react'; -import React from 'react'; +import React, { useCallback } from 'react'; +import { RightClickBehavior } from '../../domain/models'; import { ContextMenu, ContextMenuContent, @@ -24,6 +25,7 @@ export interface TerminalContextMenuProps { children: React.ReactNode; hasSelection?: boolean; hotkeyScheme?: 'disabled' | 'mac' | 'pc'; + rightClickBehavior?: RightClickBehavior; onCopy?: () => void; onPaste?: () => void; onSelectAll?: () => void; @@ -31,12 +33,14 @@ export interface TerminalContextMenuProps { onSplitHorizontal?: () => void; onSplitVertical?: () => void; onClose?: () => void; + onSelectWord?: () => void; } export const TerminalContextMenu: React.FC = ({ children, hasSelection = false, hotkeyScheme = 'mac', + rightClickBehavior = 'context-menu', onCopy, onPaste, onSelectAll, @@ -44,6 +48,7 @@ export const TerminalContextMenu: React.FC = ({ onSplitHorizontal, onSplitVertical, onClose, + onSelectWord, }) => { const isMac = hotkeyScheme === 'mac'; @@ -54,6 +59,29 @@ export const TerminalContextMenu: React.FC = ({ const splitVShortcut = isMac ? '⇧⌘D' : 'Ctrl+Shift+E'; const clearShortcut = isMac ? '⌘K' : 'Ctrl+L'; + // Handle right-click based on behavior setting + const handleRightClick = useCallback((e: React.MouseEvent) => { + if (rightClickBehavior === 'paste') { + e.preventDefault(); + e.stopPropagation(); + onPaste?.(); + } else if (rightClickBehavior === 'select-word') { + e.preventDefault(); + e.stopPropagation(); + onSelectWord?.(); + } + // For 'context-menu', let the default behavior happen (menu shows) + }, [rightClickBehavior, onPaste, onSelectWord]); + + // If not using context menu behavior, wrap children with a div that intercepts right-click + if (rightClickBehavior !== 'context-menu') { + return ( +
+ {children} +
+ ); + } + return ( diff --git a/components/terminal/ThemeCustomizeModal.tsx b/components/terminal/ThemeCustomizeModal.tsx index 5c0503d88..a16c009d3 100644 --- a/components/terminal/ThemeCustomizeModal.tsx +++ b/components/terminal/ThemeCustomizeModal.tsx @@ -9,7 +9,7 @@ * - Cancel: reverts to the original settings when modal was opened */ -import React, { useEffect, useMemo, useState, useCallback, useRef } from 'react'; +import React, { useEffect, useMemo, useState, useCallback, useRef, memo } from 'react'; import { createPortal } from 'react-dom'; import { Check, Minus, Palette, Plus, Type, X } from 'lucide-react'; import { TERMINAL_THEMES, TerminalThemeConfig } from '../../infrastructure/config/terminalThemes'; @@ -19,6 +19,82 @@ import { cn } from '../../lib/utils'; type TabType = 'theme' | 'font'; +// Memoized theme item component to prevent unnecessary re-renders +const ThemeItem = memo(({ + theme, + isSelected, + onSelect +}: { + theme: TerminalThemeConfig; + isSelected: boolean; + onSelect: (id: string) => void; +}) => ( + +)); +ThemeItem.displayName = 'ThemeItem'; + +// Memoized font item component +const FontItem = memo(({ + font, + isSelected, + onSelect +}: { + font: TerminalFont; + isSelected: boolean; + onSelect: (id: string) => void; +}) => ( + +)); +FontItem.displayName = 'FontItem'; + interface ThemeCustomizeModalProps { open: boolean; onClose: () => void; @@ -35,6 +111,147 @@ interface ThemeCustomizeModalProps { onSave?: () => void; } +// Memoized preview component to avoid re-rendering on every state change +const TerminalPreview = memo(({ + theme, + font, + fontSize +}: { + theme: TerminalThemeConfig; + font: TerminalFont; + fontSize: number; +}) => ( +
+ {/* Fake title bar */} +
+
+
+
+
+
+
+ user@server — bash +
+
+ + {/* Terminal content */} +
+
+
+ user@server + : + ~ + $ + neofetch +
+
+ {' _,met$$$$$gg. '} +
+
+ {' ,g$$$$$$$$$$$$$$$P. '} + user + @ + server +
+
+ {' ,g$$P" """Y$$.". '} + ----------- +
+
+ {' ,$$P\' `$$$. '} + OS + : Ubuntu 22.04 LTS +
+
+ {'\',$$P ,ggs. `$$b: '} + Kernel + : 5.15.0-generic +
+
+ {'`d$$\' ,$P"\' . $$$ '} + Uptime + : 42 days, 3 hours +
+
+ {' $$P d$\' , $$P '} + Shell + : bash 5.1.16 +
+
+ {' $$: $$. - ,d$$\' '} + Memory + : 4.2G / 16G (26%) +
+
 
+
+ user@server + : + ~ + $ + ls -la +
+
+ drwxr-xr-x + 5 user group + 4.0K + Dec 12 10:30 + .config +
+
+ -rwxr-xr-x + 1 user group + 2.1K + Dec 11 15:22 + deploy.sh +
+
+ lrwxrwxrwx + 1 user group + 24 + Dec 10 09:15 + logs + -{'>'} + /var/log/app +
+
 
+
+ user@server + : + ~ + $ + ▋ +
+
+
+
+)); +TerminalPreview.displayName = 'TerminalPreview'; + export const ThemeCustomizeModal: React.FC = ({ open, onClose, @@ -137,66 +354,6 @@ export const ThemeCustomizeModal: React.FC = ({ if (!open) return null; - // Render theme item - const renderThemeItem = (theme: TerminalThemeConfig) => ( - - ); - - // Render font item - const renderFontItem = (font: TerminalFont) => ( - - ); - const modalContent = (
= ({
-
-

Terminal Appearance

-

Changes apply in real-time

-
+

Terminal Appearance