mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
Expands terminal settings with advanced customization such as emulation type, font weights, line padding, keyword highlighting, link modifiers, and middle-click behavior. Adds support for clickable URLs, cross-window settings sync, and context-aware right-click actions. Improves accessibility with minimum contrast ratio controls and allows keyword-based output highlighting. Refines theme/font selection UI for performance and clarity.
152 lines
5.1 KiB
TypeScript
152 lines
5.1 KiB
TypeScript
/**
|
|
* Terminal Context Menu
|
|
* Right-click menu for terminal with split, copy/paste, and other actions
|
|
*/
|
|
import {
|
|
Copy,
|
|
ClipboardPaste,
|
|
SplitSquareHorizontal,
|
|
SplitSquareVertical,
|
|
Trash2,
|
|
Terminal as TerminalIcon,
|
|
} from 'lucide-react';
|
|
import React, { useCallback } from 'react';
|
|
import { RightClickBehavior } from '../../domain/models';
|
|
import {
|
|
ContextMenu,
|
|
ContextMenuContent,
|
|
ContextMenuItem,
|
|
ContextMenuSeparator,
|
|
ContextMenuShortcut,
|
|
ContextMenuTrigger,
|
|
} from '../ui/context-menu';
|
|
|
|
export interface TerminalContextMenuProps {
|
|
children: React.ReactNode;
|
|
hasSelection?: boolean;
|
|
hotkeyScheme?: 'disabled' | 'mac' | 'pc';
|
|
rightClickBehavior?: RightClickBehavior;
|
|
onCopy?: () => void;
|
|
onPaste?: () => void;
|
|
onSelectAll?: () => void;
|
|
onClear?: () => void;
|
|
onSplitHorizontal?: () => void;
|
|
onSplitVertical?: () => void;
|
|
onClose?: () => void;
|
|
onSelectWord?: () => void;
|
|
}
|
|
|
|
export const TerminalContextMenu: React.FC<TerminalContextMenuProps> = ({
|
|
children,
|
|
hasSelection = false,
|
|
hotkeyScheme = 'mac',
|
|
rightClickBehavior = 'context-menu',
|
|
onCopy,
|
|
onPaste,
|
|
onSelectAll,
|
|
onClear,
|
|
onSplitHorizontal,
|
|
onSplitVertical,
|
|
onClose,
|
|
onSelectWord,
|
|
}) => {
|
|
const isMac = hotkeyScheme === 'mac';
|
|
|
|
const copyShortcut = isMac ? '⌘C' : 'Ctrl+Shift+C';
|
|
const pasteShortcut = isMac ? '⌘V' : 'Ctrl+Shift+V';
|
|
const selectAllShortcut = isMac ? '⌘A' : 'Ctrl+Shift+A';
|
|
const splitHShortcut = isMac ? '⌘D' : 'Ctrl+Shift+D';
|
|
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 (
|
|
<div onContextMenu={handleRightClick} className="contents">
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<ContextMenu>
|
|
<ContextMenuTrigger asChild>
|
|
{children}
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent className="w-56">
|
|
{/* Copy/Paste Section */}
|
|
<ContextMenuItem
|
|
onClick={onCopy}
|
|
disabled={!hasSelection}
|
|
>
|
|
<Copy size={14} className="mr-2" />
|
|
复制
|
|
<ContextMenuShortcut>{copyShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onClick={onPaste}>
|
|
<ClipboardPaste size={14} className="mr-2" />
|
|
粘贴
|
|
<ContextMenuShortcut>{pasteShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onClick={onSelectAll}>
|
|
<TerminalIcon size={14} className="mr-2" />
|
|
全选
|
|
<ContextMenuShortcut>{selectAllShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
|
|
<ContextMenuSeparator />
|
|
|
|
{/* Split Section */}
|
|
<ContextMenuItem onClick={onSplitVertical}>
|
|
<SplitSquareHorizontal size={14} className="mr-2" />
|
|
水平分屏
|
|
<ContextMenuShortcut>{splitVShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
<ContextMenuItem onClick={onSplitHorizontal}>
|
|
<SplitSquareVertical size={14} className="mr-2" />
|
|
垂直分屏
|
|
<ContextMenuShortcut>{splitHShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
|
|
<ContextMenuSeparator />
|
|
|
|
{/* Clear/Close Section */}
|
|
<ContextMenuItem onClick={onClear}>
|
|
<Trash2 size={14} className="mr-2" />
|
|
清除缓冲区
|
|
<ContextMenuShortcut>{clearShortcut}</ContextMenuShortcut>
|
|
</ContextMenuItem>
|
|
|
|
{onClose && (
|
|
<>
|
|
<ContextMenuSeparator />
|
|
<ContextMenuItem
|
|
onClick={onClose}
|
|
className="text-destructive focus:text-destructive"
|
|
>
|
|
<Trash2 size={14} className="mr-2" />
|
|
关闭终端
|
|
</ContextMenuItem>
|
|
</>
|
|
)}
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
};
|
|
|
|
export default TerminalContextMenu;
|