feat(terminal): refactor font size handling in terminal settings
- Updated terminal font size management to use a delta approach, allowing for dynamic adjustments based on user interactions. - Introduced new utility functions for increasing, decreasing, and resetting font size deltas. - Modified relevant components and hooks to accommodate the new font size delta logic, ensuring consistent font size rendering across the application. - Updated type definitions and default settings to include font size delta in terminal configurations.
This commit is contained in:
1 parent
d0e0fe9964
commit
7acd07112a
9 files changed
+71
-22
No files matched your search
@@ -52,6 +52,8 @@ pub struct TerminalSettings {
|
||||
#[serde(default = "default_keep_alive")]
|
||||
pub keep_alive_interval: u32,
|
||||
#[serde(default)]
|
||||
pub font_size_delta: f64,
|
||||
#[serde(default)]
|
||||
pub x11_display: String,
|
||||
#[serde(default = "default_false")]
|
||||
pub hardware_acceleration: bool,
|
||||
@@ -91,6 +93,7 @@ impl Default for TerminalSettings {
|
||||
Self {
|
||||
scrollback_lines: default_scrollback(),
|
||||
keep_alive_interval: default_keep_alive(),
|
||||
font_size_delta: 0.0,
|
||||
x11_display: String::new(),
|
||||
hardware_acceleration: false,
|
||||
keyword_highlights_enabled: false,
|
||||
|
||||
@@ -49,9 +49,9 @@ import { invoke } from "@/lib/invoke";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { isMacOS } from "@/lib/platform";
|
||||
import {
|
||||
DEFAULT_TERMINAL_FONT_SIZE,
|
||||
decreaseTerminalFontSize,
|
||||
increaseTerminalFontSize,
|
||||
decreaseTerminalFontSizeDelta,
|
||||
increaseTerminalFontSizeDelta,
|
||||
resetTerminalFontSizeDelta,
|
||||
} from "@/lib/terminalFontSize";
|
||||
import { getActivePane, getTabDisplayName } from "@/lib/workspaceTabs";
|
||||
import type { SavedConnection, Tab } from "@/types/global";
|
||||
@@ -208,19 +208,25 @@ export default function Header({
|
||||
|
||||
const handleZoom = (delta: number) => {
|
||||
updateAppSettings((prev) => ({
|
||||
appearance: {
|
||||
...prev.appearance,
|
||||
font_size:
|
||||
terminal: {
|
||||
...prev.terminal,
|
||||
font_size_delta:
|
||||
delta > 0
|
||||
? increaseTerminalFontSize(prev.appearance.font_size)
|
||||
: decreaseTerminalFontSize(prev.appearance.font_size),
|
||||
? increaseTerminalFontSizeDelta(
|
||||
prev.appearance.font_size,
|
||||
prev.terminal.font_size_delta,
|
||||
)
|
||||
: decreaseTerminalFontSizeDelta(
|
||||
prev.appearance.font_size,
|
||||
prev.terminal.font_size_delta,
|
||||
),
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const handleResetZoom = () =>
|
||||
updateAppSettings((prev) => ({
|
||||
appearance: { ...prev.appearance, font_size: DEFAULT_TERMINAL_FONT_SIZE },
|
||||
terminal: { ...prev.terminal, font_size_delta: resetTerminalFontSizeDelta() },
|
||||
}));
|
||||
|
||||
const menuKeys = [
|
||||
|
||||
@@ -48,6 +48,7 @@ import {
|
||||
} from "@/lib/shortcutRegistry";
|
||||
import { registerTerminalContextProvider } from "@/lib/terminalContext";
|
||||
import { getTerminalDropOverlayCopy, handleTerminalFileDrop } from "@/lib/terminalFileDrop";
|
||||
import { resolveTerminalFontSize } from "@/lib/terminalFontSize";
|
||||
import {
|
||||
applyTerminalInputData,
|
||||
applyTerminalInputPreview,
|
||||
@@ -405,7 +406,7 @@ export default function XTerminal({
|
||||
scrollback: terminalSettings.scrollback_lines,
|
||||
cursorBlink: appearance.cursor_blink,
|
||||
cursorStyle: appearance.cursor_style as "block" | "underline" | "bar",
|
||||
fontSize: appearance.font_size,
|
||||
fontSize: resolveTerminalFontSize(appearance.font_size, terminalSettings.font_size_delta),
|
||||
fontFamily: appearance.font_family,
|
||||
minimumContrastRatio: appearance.minimum_contrast_ratio,
|
||||
wordSeparator: interaction.word_separators,
|
||||
|
||||
@@ -236,6 +236,7 @@ const DEFAULT_APP_SETTINGS: AppSettings = {
|
||||
terminal: {
|
||||
scrollback_lines: 10000,
|
||||
keep_alive_interval: 60,
|
||||
font_size_delta: 0,
|
||||
x11_display: "",
|
||||
hardware_acceleration: false,
|
||||
keyword_highlights_enabled: false,
|
||||
|
||||
@@ -62,6 +62,7 @@ const DEFAULT_APP_SETTINGS: AppSettings = {
|
||||
terminal: {
|
||||
scrollback_lines: 10000,
|
||||
keep_alive_interval: 60,
|
||||
font_size_delta: 0,
|
||||
x11_display: "",
|
||||
hardware_acceleration: false,
|
||||
keyword_highlights_enabled: false,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { WebglAddon } from "@xterm/addon-webgl";
|
||||
import type { Terminal } from "@xterm/xterm";
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { isTerminalTransparencyEnabled } from "@/lib/backgroundImage";
|
||||
import { resolveTerminalFontSize } from "@/lib/terminalFontSize";
|
||||
import type { TerminalColors } from "@/lib/themes";
|
||||
import { installMacImeCompatibilityPatch } from "@/lib/xtermMacImeCompatibility";
|
||||
import type { AppSettings } from "@/types/global";
|
||||
@@ -95,7 +96,10 @@ export function useTerminalSettings(
|
||||
if (terminalRef.current) {
|
||||
const options = terminalRef.current.options;
|
||||
options.fontFamily = appearance.font_family;
|
||||
options.fontSize = appearance.font_size;
|
||||
options.fontSize = resolveTerminalFontSize(
|
||||
appearance.font_size,
|
||||
terminalSettings.font_size_delta,
|
||||
);
|
||||
options.cursorBlink = appearance.cursor_blink;
|
||||
options.cursorStyle = appearance.cursor_style as "block" | "underline" | "bar";
|
||||
options.minimumContrastRatio = appearance.minimum_contrast_ratio;
|
||||
@@ -106,7 +110,13 @@ export function useTerminalSettings(
|
||||
requestAnimationFrame(() => fitAddonRef.current?.fit());
|
||||
}
|
||||
}
|
||||
}, [appearance, terminalRef, fitAddonRef, scheduleTextureRefresh]);
|
||||
}, [
|
||||
appearance,
|
||||
terminalSettings.font_size_delta,
|
||||
terminalRef,
|
||||
fitAddonRef,
|
||||
scheduleTextureRefresh,
|
||||
]);
|
||||
|
||||
// React to terminal core settings changes: scrollback
|
||||
useEffect(() => {
|
||||
|
||||
@@ -2,9 +2,9 @@ import { useCallback, useEffect, useRef } from "react";
|
||||
import { resolveShortcutKeys } from "@/hooks/useShortcutMap";
|
||||
import { matchesKeyEvent } from "@/lib/shortcutRegistry";
|
||||
import {
|
||||
DEFAULT_TERMINAL_FONT_SIZE,
|
||||
decreaseTerminalFontSize,
|
||||
increaseTerminalFontSize,
|
||||
decreaseTerminalFontSizeDelta,
|
||||
increaseTerminalFontSizeDelta,
|
||||
resetTerminalFontSizeDelta,
|
||||
} from "@/lib/terminalFontSize";
|
||||
import type { AppSettings } from "@/types/global";
|
||||
|
||||
@@ -22,25 +22,31 @@ export function useTerminalZoom(
|
||||
|
||||
const handleZoomIn = useCallback(() => {
|
||||
updateAppSettings((prev) => ({
|
||||
appearance: {
|
||||
...prev.appearance,
|
||||
font_size: increaseTerminalFontSize(prev.appearance.font_size),
|
||||
terminal: {
|
||||
...prev.terminal,
|
||||
font_size_delta: increaseTerminalFontSizeDelta(
|
||||
prev.appearance.font_size,
|
||||
prev.terminal.font_size_delta,
|
||||
),
|
||||
},
|
||||
}));
|
||||
}, [updateAppSettings]);
|
||||
|
||||
const handleZoomOut = useCallback(() => {
|
||||
updateAppSettings((prev) => ({
|
||||
appearance: {
|
||||
...prev.appearance,
|
||||
font_size: decreaseTerminalFontSize(prev.appearance.font_size),
|
||||
terminal: {
|
||||
...prev.terminal,
|
||||
font_size_delta: decreaseTerminalFontSizeDelta(
|
||||
prev.appearance.font_size,
|
||||
prev.terminal.font_size_delta,
|
||||
),
|
||||
},
|
||||
}));
|
||||
}, [updateAppSettings]);
|
||||
|
||||
const handleResetZoom = useCallback(() => {
|
||||
updateAppSettings((prev) => ({
|
||||
appearance: { ...prev.appearance, font_size: DEFAULT_TERMINAL_FONT_SIZE },
|
||||
terminal: { ...prev.terminal, font_size_delta: resetTerminalFontSizeDelta() },
|
||||
}));
|
||||
}, [updateAppSettings]);
|
||||
|
||||
|
||||
@@ -7,6 +7,26 @@ export function clampTerminalFontSize(fontSize: number): number {
|
||||
return Math.max(MIN_TERMINAL_FONT_SIZE, Math.min(MAX_TERMINAL_FONT_SIZE, Math.round(fontSize)));
|
||||
}
|
||||
|
||||
export function resolveTerminalFontSize(baseFontSize: number, fontSizeDelta = 0): number {
|
||||
return clampTerminalFontSize(baseFontSize + fontSizeDelta);
|
||||
}
|
||||
|
||||
export function increaseTerminalFontSizeDelta(baseFontSize: number, fontSizeDelta = 0): number {
|
||||
return (
|
||||
resolveTerminalFontSize(baseFontSize, fontSizeDelta + TERMINAL_FONT_SIZE_STEP) - baseFontSize
|
||||
);
|
||||
}
|
||||
|
||||
export function decreaseTerminalFontSizeDelta(baseFontSize: number, fontSizeDelta = 0): number {
|
||||
return (
|
||||
resolveTerminalFontSize(baseFontSize, fontSizeDelta - TERMINAL_FONT_SIZE_STEP) - baseFontSize
|
||||
);
|
||||
}
|
||||
|
||||
export function resetTerminalFontSizeDelta(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function increaseTerminalFontSize(fontSize: number): number {
|
||||
return clampTerminalFontSize(fontSize + TERMINAL_FONT_SIZE_STEP);
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -565,6 +565,7 @@ export type KeywordHighlightBuiltinRuleSettings = Record<string, boolean>;
|
||||
export interface TerminalSettings {
|
||||
scrollback_lines: number;
|
||||
keep_alive_interval: number;
|
||||
font_size_delta: number;
|
||||
x11_display?: string;
|
||||
hardware_acceleration: boolean;
|
||||
keyword_highlights_enabled: boolean;
|
||||
|
||||
Reference in new issue
Block a user