mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
Enables local terminal customization for theme and font
Allows users to customize theme, font family, and font size for local terminals independently of remote host settings. Improves user experience by making appearance preferences for local sessions more flexible and immediately responsive.
This commit is contained in:
1 parent
e05bed0b9d
commit
1a4c6ade9f
5 files changed
+73
-7
No files matched your search
@@ -85,8 +85,12 @@ function App() {
|
||||
const {
|
||||
theme,
|
||||
setTheme,
|
||||
setTerminalThemeId,
|
||||
currentTerminalTheme,
|
||||
terminalFontFamilyId,
|
||||
setTerminalFontFamilyId,
|
||||
terminalFontSize,
|
||||
setTerminalFontSize,
|
||||
terminalSettings,
|
||||
hotkeyScheme,
|
||||
keyBindings,
|
||||
@@ -657,10 +661,14 @@ function App() {
|
||||
draggingSessionId={draggingSessionId}
|
||||
terminalTheme={currentTerminalTheme}
|
||||
terminalSettings={terminalSettings}
|
||||
terminalFontFamilyId={terminalFontFamilyId}
|
||||
fontSize={terminalFontSize}
|
||||
hotkeyScheme={hotkeyScheme}
|
||||
keyBindings={keyBindings}
|
||||
onHotkeyAction={handleHotkeyAction}
|
||||
onUpdateTerminalThemeId={setTerminalThemeId}
|
||||
onUpdateTerminalFontFamilyId={setTerminalFontFamilyId}
|
||||
onUpdateTerminalFontSize={setTerminalFontSize}
|
||||
onCloseSession={closeSession}
|
||||
onUpdateSessionStatus={updateSessionStatus}
|
||||
onUpdateHostDistro={updateHostDistro}
|
||||
|
||||
+18
-3
@@ -49,11 +49,15 @@ interface TerminalProps {
|
||||
isResizing?: boolean;
|
||||
isFocusMode?: boolean;
|
||||
isFocused?: boolean;
|
||||
fontFamilyId: string;
|
||||
fontSize: number;
|
||||
terminalTheme: TerminalTheme;
|
||||
terminalSettings?: TerminalSettings;
|
||||
sessionId: string;
|
||||
startupCommand?: string;
|
||||
onUpdateTerminalThemeId?: (themeId: string) => void;
|
||||
onUpdateTerminalFontFamilyId?: (fontFamilyId: string) => void;
|
||||
onUpdateTerminalFontSize?: (fontSize: number) => void;
|
||||
hotkeyScheme?: "disabled" | "mac" | "pc";
|
||||
keyBindings?: KeyBinding[];
|
||||
onHotkeyAction?: (action: string, event: KeyboardEvent) => void;
|
||||
@@ -89,11 +93,15 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
isResizing,
|
||||
isFocusMode,
|
||||
isFocused,
|
||||
fontFamilyId,
|
||||
fontSize,
|
||||
terminalTheme,
|
||||
terminalSettings,
|
||||
sessionId,
|
||||
startupCommand,
|
||||
onUpdateTerminalThemeId,
|
||||
onUpdateTerminalFontFamilyId,
|
||||
onUpdateTerminalFontSize,
|
||||
hotkeyScheme = "disabled",
|
||||
keyBindings = [],
|
||||
onHotkeyAction,
|
||||
@@ -307,8 +315,9 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
const runtime = createXTermRuntime({
|
||||
container: containerRef.current,
|
||||
host,
|
||||
fontFamilyId,
|
||||
fontSize,
|
||||
terminalTheme,
|
||||
terminalTheme: effectiveTheme,
|
||||
terminalSettingsRef,
|
||||
terminalBackend,
|
||||
sessionRef,
|
||||
@@ -510,7 +519,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
const effectiveFontSize = host.fontSize || fontSize;
|
||||
termRef.current.options.fontSize = effectiveFontSize;
|
||||
|
||||
const hostFontId = host.fontFamily || "menlo";
|
||||
const hostFontId = host.fontFamily || fontFamilyId || "menlo";
|
||||
const fontObj = TERMINAL_FONTS.find((f) => f.id === hostFontId) || TERMINAL_FONTS[0];
|
||||
termRef.current.options.fontFamily = fontObj.family;
|
||||
|
||||
@@ -521,7 +530,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
|
||||
setTimeout(() => safeFit(), 50);
|
||||
}
|
||||
}, [host.fontSize, host.fontFamily, host.theme, fontSize, effectiveTheme]);
|
||||
}, [host.fontSize, host.fontFamily, host.theme, fontFamilyId, fontSize, effectiveTheme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isVisible && fitAddonRef.current) {
|
||||
@@ -761,6 +770,12 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
status={status}
|
||||
snippets={snippets}
|
||||
host={host}
|
||||
defaultThemeId={terminalTheme.id}
|
||||
defaultFontFamilyId={fontFamilyId}
|
||||
defaultFontSize={fontSize}
|
||||
onUpdateTerminalThemeId={onUpdateTerminalThemeId}
|
||||
onUpdateTerminalFontFamilyId={onUpdateTerminalFontFamilyId}
|
||||
onUpdateTerminalFontSize={onUpdateTerminalFontSize}
|
||||
isScriptsOpen={isScriptsOpen}
|
||||
setIsScriptsOpen={setIsScriptsOpen}
|
||||
onOpenSFTP={() => setShowSFTP((v) => !v)}
|
||||
|
||||
@@ -40,10 +40,14 @@ interface TerminalLayerProps {
|
||||
draggingSessionId: string | null;
|
||||
terminalTheme: TerminalTheme;
|
||||
terminalSettings?: TerminalSettings;
|
||||
terminalFontFamilyId: string;
|
||||
fontSize?: number;
|
||||
hotkeyScheme?: 'disabled' | 'mac' | 'pc';
|
||||
keyBindings?: KeyBinding[];
|
||||
onHotkeyAction?: (action: string, event: KeyboardEvent) => void;
|
||||
onUpdateTerminalThemeId?: (themeId: string) => void;
|
||||
onUpdateTerminalFontFamilyId?: (fontFamilyId: string) => void;
|
||||
onUpdateTerminalFontSize?: (fontSize: number) => void;
|
||||
onCloseSession: (sessionId: string, e?: React.MouseEvent) => void;
|
||||
onUpdateSessionStatus: (sessionId: string, status: TerminalSession['status']) => void;
|
||||
onUpdateHostDistro: (hostId: string, distro: string) => void;
|
||||
@@ -73,10 +77,14 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
draggingSessionId,
|
||||
terminalTheme,
|
||||
terminalSettings,
|
||||
terminalFontFamilyId,
|
||||
fontSize = 14,
|
||||
hotkeyScheme = 'disabled',
|
||||
keyBindings = [],
|
||||
onHotkeyAction,
|
||||
onUpdateTerminalThemeId,
|
||||
onUpdateTerminalFontFamilyId,
|
||||
onUpdateTerminalFontSize,
|
||||
onCloseSession,
|
||||
onUpdateSessionStatus,
|
||||
onUpdateHostDistro,
|
||||
@@ -657,11 +665,15 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
isResizing={!!resizing}
|
||||
isFocusMode={isFocusMode}
|
||||
isFocused={isFocusedPane}
|
||||
fontFamilyId={terminalFontFamilyId}
|
||||
fontSize={fontSize}
|
||||
terminalTheme={terminalTheme}
|
||||
terminalSettings={terminalSettings}
|
||||
sessionId={session.id}
|
||||
startupCommand={session.startupCommand}
|
||||
onUpdateTerminalThemeId={onUpdateTerminalThemeId}
|
||||
onUpdateTerminalFontFamilyId={onUpdateTerminalFontFamilyId}
|
||||
onUpdateTerminalFontSize={onUpdateTerminalFontSize}
|
||||
hotkeyScheme={hotkeyScheme}
|
||||
keyBindings={keyBindings}
|
||||
onHotkeyAction={onHotkeyAction}
|
||||
|
||||
@@ -15,6 +15,12 @@ export interface TerminalToolbarProps {
|
||||
status: 'connecting' | 'connected' | 'disconnected';
|
||||
snippets: Snippet[];
|
||||
host?: Host;
|
||||
defaultThemeId: string;
|
||||
defaultFontFamilyId: string;
|
||||
defaultFontSize: number;
|
||||
onUpdateTerminalThemeId?: (themeId: string) => void;
|
||||
onUpdateTerminalFontFamilyId?: (fontFamilyId: string) => void;
|
||||
onUpdateTerminalFontSize?: (fontSize: number) => void;
|
||||
isScriptsOpen: boolean;
|
||||
setIsScriptsOpen: (open: boolean) => void;
|
||||
onOpenSFTP: () => void;
|
||||
@@ -31,6 +37,12 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
|
||||
status,
|
||||
snippets,
|
||||
host,
|
||||
defaultThemeId,
|
||||
defaultFontFamilyId,
|
||||
defaultFontSize,
|
||||
onUpdateTerminalThemeId,
|
||||
onUpdateTerminalFontFamilyId,
|
||||
onUpdateTerminalFontSize,
|
||||
isScriptsOpen,
|
||||
setIsScriptsOpen,
|
||||
onOpenSFTP,
|
||||
@@ -45,19 +57,37 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
|
||||
const [themeModalOpen, setThemeModalOpen] = useState(false);
|
||||
const buttonBase = "h-7 px-2 text-[11px] bg-white/5 hover:bg-white/10 text-white shadow-none border-none";
|
||||
|
||||
const isLocalTerminal = host?.protocol === 'local' || host?.id?.startsWith('local-');
|
||||
|
||||
const currentThemeId = host?.theme || defaultThemeId;
|
||||
const currentFontFamilyId = host?.fontFamily || defaultFontFamilyId;
|
||||
const currentFontSize = host?.fontSize || defaultFontSize;
|
||||
|
||||
const handleThemeChange = (themeId: string) => {
|
||||
if (isLocalTerminal) {
|
||||
onUpdateTerminalThemeId?.(themeId);
|
||||
return;
|
||||
}
|
||||
if (host && onUpdateHost) {
|
||||
onUpdateHost({ ...host, theme: themeId });
|
||||
}
|
||||
};
|
||||
|
||||
const handleFontFamilyChange = (fontFamilyId: string) => {
|
||||
if (isLocalTerminal) {
|
||||
onUpdateTerminalFontFamilyId?.(fontFamilyId);
|
||||
return;
|
||||
}
|
||||
if (host && onUpdateHost) {
|
||||
onUpdateHost({ ...host, fontFamily: fontFamilyId });
|
||||
}
|
||||
};
|
||||
|
||||
const handleFontSizeChange = (fontSize: number) => {
|
||||
if (isLocalTerminal) {
|
||||
onUpdateTerminalFontSize?.(fontSize);
|
||||
return;
|
||||
}
|
||||
if (host && onUpdateHost) {
|
||||
onUpdateHost({ ...host, fontSize });
|
||||
}
|
||||
@@ -153,9 +183,9 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
|
||||
<ThemeCustomizeModal
|
||||
open={themeModalOpen}
|
||||
onClose={() => setThemeModalOpen(false)}
|
||||
currentThemeId={host?.theme || 'termius-dark'}
|
||||
currentFontFamilyId={host?.fontFamily || 'menlo'}
|
||||
currentFontSize={host?.fontSize || 14}
|
||||
currentThemeId={currentThemeId}
|
||||
currentFontFamilyId={currentFontFamilyId}
|
||||
currentFontSize={currentFontSize}
|
||||
onThemeChange={handleThemeChange}
|
||||
onFontFamilyChange={handleFontFamilyChange}
|
||||
onFontSizeChange={handleFontSizeChange}
|
||||
|
||||
@@ -43,6 +43,7 @@ export type XTermRuntime = {
|
||||
export type CreateXTermRuntimeContext = {
|
||||
container: HTMLDivElement;
|
||||
host: Host;
|
||||
fontFamilyId: string;
|
||||
fontSize: number;
|
||||
terminalTheme: TerminalTheme;
|
||||
terminalSettingsRef: RefObject<TerminalSettings | undefined>;
|
||||
@@ -104,7 +105,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
|
||||
deviceMemoryGb,
|
||||
});
|
||||
|
||||
const hostFontId = ctx.host.fontFamily || "menlo";
|
||||
const hostFontId = ctx.host.fontFamily || ctx.fontFamilyId || "menlo";
|
||||
const fontObj = TERMINAL_FONTS.find((f) => f.id === hostFontId) || TERMINAL_FONTS[0];
|
||||
const fontFamily = fontObj.family;
|
||||
|
||||
|
||||
Reference in new issue
Block a user