Skip to content

Commit db68d11

Browse files
committed
Enhance terminal line height settings
- Introduced terminal line height as a customizable setting in app settings. - Implemented functions to resolve and clamp terminal line height values. - Updated the terminal component to utilize the new line height setting. - Added UI elements in settings for users to adjust terminal line height with validation. - Expanded tests to cover the new line height functionality.
1 parent 58acf26 commit db68d11

4 files changed

Lines changed: 141 additions & 60 deletions

File tree

‎apps/web/src/appSettings.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import { describe, expect, it } from "vitest";
22

33
import {
44
clampTerminalFontSize,
5+
DEFAULT_TERMINAL_FONT_FAMILY,
6+
DEFAULT_TERMINAL_FONT_SIZE,
7+
DEFAULT_TERMINAL_LINE_HEIGHT,
8+
MAX_TERMINAL_LINE_HEIGHT,
9+
MIN_TERMINAL_LINE_HEIGHT,
510
getAppModelOptions,
611
getSlashModelOptions,
712
normalizeCustomModelSlugs,
813
parsePersistedSettings,
14+
resolveTerminalLineHeight,
915
resolveTerminalFontFamily,
1016
resolveAppServiceTier,
1117
shouldShowFastTierIcon,
@@ -20,8 +26,9 @@ function createPersistedSettings(overrides: Record<string, unknown>): string {
2026
enableAssistantStreaming: false,
2127
codexServiceTier: "auto",
2228
customCodexModels: [],
23-
terminalFontFamily: '"SF Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace',
24-
terminalFontSize: 12,
29+
terminalFontFamily: DEFAULT_TERMINAL_FONT_FAMILY,
30+
terminalFontSize: DEFAULT_TERMINAL_FONT_SIZE,
31+
terminalLineHeight: DEFAULT_TERMINAL_LINE_HEIGHT,
2532
...overrides,
2633
});
2734
}
@@ -142,6 +149,18 @@ describe("clampTerminalFontSize", () => {
142149
});
143150
});
144151

152+
describe("resolveTerminalLineHeight", () => {
153+
it("falls back to the default option for invalid values", () => {
154+
expect(resolveTerminalLineHeight(undefined)).toBe(DEFAULT_TERMINAL_LINE_HEIGHT);
155+
});
156+
157+
it("clamps and rounds persisted values to the supported range", () => {
158+
expect(resolveTerminalLineHeight(0.8)).toBe(MIN_TERMINAL_LINE_HEIGHT);
159+
expect(resolveTerminalLineHeight(2.4)).toBe(MAX_TERMINAL_LINE_HEIGHT);
160+
expect(resolveTerminalLineHeight(1.236)).toBe(1.24);
161+
});
162+
});
163+
145164
describe("parsePersistedSettings", () => {
146165
it("clamps persisted terminal font sizes instead of discarding the settings payload", () => {
147166
expect(
@@ -150,12 +169,14 @@ describe("parsePersistedSettings", () => {
150169
confirmThreadDelete: false,
151170
terminalFontFamily: "Fira Code, monospace",
152171
terminalFontSize: 99,
172+
terminalLineHeight: 2.4,
153173
}),
154174
),
155175
).toMatchObject({
156176
confirmThreadDelete: false,
157177
terminalFontFamily: "Fira Code, monospace",
158178
terminalFontSize: 32,
179+
terminalLineHeight: 2,
159180
});
160181
});
161182

‎apps/web/src/appSettings.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const DEFAULT_TERMINAL_FONT_FAMILY =
1212
export const DEFAULT_TERMINAL_FONT_SIZE = 12;
1313
export const MIN_TERMINAL_FONT_SIZE = 8;
1414
export const MAX_TERMINAL_FONT_SIZE = 32;
15+
export const DEFAULT_TERMINAL_LINE_HEIGHT = 1.2;
16+
export const MIN_TERMINAL_LINE_HEIGHT = 1;
17+
export const MAX_TERMINAL_LINE_HEIGHT = 2;
1518
export const APP_SERVICE_TIER_OPTIONS = [
1619
{
1720
value: "auto",
@@ -57,6 +60,9 @@ const AppSettingsSchema = Schema.Struct({
5760
terminalFontSize: Schema.Number.pipe(
5861
Schema.withConstructorDefault(() => Option.some(DEFAULT_TERMINAL_FONT_SIZE)),
5962
),
63+
terminalLineHeight: Schema.Number.pipe(
64+
Schema.withConstructorDefault(() => Option.some(DEFAULT_TERMINAL_LINE_HEIGHT)),
65+
),
6066
});
6167
export type AppSettings = typeof AppSettingsSchema.Type;
6268
export interface AppModelOption {
@@ -132,12 +138,21 @@ export function clampTerminalFontSize(fontSize: number | null | undefined): numb
132138
return Math.min(Math.max(rounded, MIN_TERMINAL_FONT_SIZE), MAX_TERMINAL_FONT_SIZE);
133139
}
134140

141+
export function resolveTerminalLineHeight(lineHeight: number | null | undefined): number {
142+
if (typeof lineHeight !== "number" || !Number.isFinite(lineHeight)) {
143+
return DEFAULT_TERMINAL_LINE_HEIGHT;
144+
}
145+
const rounded = Math.round(lineHeight * 100) / 100;
146+
return Math.min(Math.max(rounded, MIN_TERMINAL_LINE_HEIGHT), MAX_TERMINAL_LINE_HEIGHT);
147+
}
148+
135149
function normalizeAppSettings(settings: AppSettings): AppSettings {
136150
return {
137151
...settings,
138152
customCodexModels: normalizeCustomModelSlugs(settings.customCodexModels, "codex"),
139153
terminalFontFamily: resolveTerminalFontFamily(settings.terminalFontFamily),
140154
terminalFontSize: clampTerminalFontSize(settings.terminalFontSize),
155+
terminalLineHeight: resolveTerminalLineHeight(settings.terminalLineHeight),
141156
};
142157
}
143158

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ interface TerminalViewportProps {
115115
runtimeEnv?: Record<string, string>;
116116
terminalFontFamily: string;
117117
terminalFontSize: number;
118+
terminalLineHeight: number;
118119
onSessionExited: () => void;
119120
focusRequestId: number;
120121
autoFocus: boolean;
@@ -129,6 +130,7 @@ function TerminalViewport({
129130
runtimeEnv,
130131
terminalFontFamily,
131132
terminalFontSize,
133+
terminalLineHeight,
132134
onSessionExited,
133135
focusRequestId,
134136
autoFocus,
@@ -154,7 +156,7 @@ function TerminalViewport({
154156
const fitAddon = new FitAddon();
155157
const terminal = new Terminal({
156158
cursorBlink: true,
157-
lineHeight: 1.2,
159+
lineHeight: terminalLineHeight,
158160
fontSize: terminalFontSize,
159161
scrollback: 5_000,
160162
fontFamily: terminalFontFamily,
@@ -419,12 +421,14 @@ function TerminalViewport({
419421

420422
const fontFamilyChanged = terminal.options.fontFamily !== terminalFontFamily;
421423
const fontSizeChanged = terminal.options.fontSize !== terminalFontSize;
422-
if (!fontFamilyChanged && !fontSizeChanged) {
424+
const lineHeightChanged = terminal.options.lineHeight !== terminalLineHeight;
425+
if (!fontFamilyChanged && !fontSizeChanged && !lineHeightChanged) {
423426
return;
424427
}
425428

426429
terminal.options.fontFamily = terminalFontFamily;
427430
terminal.options.fontSize = terminalFontSize;
431+
terminal.options.lineHeight = terminalLineHeight;
428432

429433
const wasAtBottom = terminal.buffer.active.viewportY >= terminal.buffer.active.baseY;
430434
const frame = window.requestAnimationFrame(() => {
@@ -448,7 +452,7 @@ function TerminalViewport({
448452
return () => {
449453
window.cancelAnimationFrame(frame);
450454
};
451-
}, [terminalFontFamily, terminalFontSize, terminalId, threadId]);
455+
}, [terminalFontFamily, terminalFontSize, terminalLineHeight, terminalId, threadId]);
452456

453457
useEffect(() => {
454458
const api = readNativeApi();
@@ -673,6 +677,7 @@ export default function ThreadTerminalDrawer({
673677
: "Close Terminal";
674678
const terminalFontFamily = appSettings.terminalFontFamily;
675679
const terminalFontSize = appSettings.terminalFontSize;
680+
const terminalLineHeight = appSettings.terminalLineHeight;
676681
const onSplitTerminalAction = useCallback(() => {
677682
if (hasReachedTerminalLimit) return;
678683
onSplitTerminal();
@@ -790,23 +795,21 @@ export default function ThreadTerminalDrawer({
790795
<div className="pointer-events-none absolute right-2 top-2 z-20">
791796
<div className="pointer-events-auto inline-flex items-center overflow-hidden rounded-md border border-border/80 bg-background/70">
792797
<TerminalActionButton
793-
className={`p-1 text-foreground/90 transition-colors ${
794-
hasReachedTerminalLimit
795-
? "cursor-not-allowed opacity-45 hover:bg-transparent"
796-
: "hover:bg-accent"
797-
}`}
798+
className={`p-1 text-foreground/90 transition-colors ${hasReachedTerminalLimit
799+
? "cursor-not-allowed opacity-45 hover:bg-transparent"
800+
: "hover:bg-accent"
801+
}`}
798802
onClick={onSplitTerminalAction}
799803
label={splitTerminalActionLabel}
800804
>
801805
<SquareSplitHorizontal className="size-3.25" />
802806
</TerminalActionButton>
803807
<div className="h-4 w-px bg-border/80" />
804808
<TerminalActionButton
805-
className={`p-1 text-foreground/90 transition-colors ${
806-
hasReachedTerminalLimit
807-
? "cursor-not-allowed opacity-45 hover:bg-transparent"
808-
: "hover:bg-accent"
809-
}`}
809+
className={`p-1 text-foreground/90 transition-colors ${hasReachedTerminalLimit
810+
? "cursor-not-allowed opacity-45 hover:bg-transparent"
811+
: "hover:bg-accent"
812+
}`}
810813
onClick={onNewTerminalAction}
811814
label={newTerminalActionLabel}
812815
>
@@ -837,9 +840,8 @@ export default function ThreadTerminalDrawer({
837840
{visibleTerminalIds.map((terminalId) => (
838841
<div
839842
key={terminalId}
840-
className={`min-h-0 min-w-0 border-l first:border-l-0 ${
841-
terminalId === resolvedActiveTerminalId ? "border-border" : "border-border/70"
842-
}`}
843+
className={`min-h-0 min-w-0 border-l first:border-l-0 ${terminalId === resolvedActiveTerminalId ? "border-border" : "border-border/70"
844+
}`}
843845
onMouseDown={() => {
844846
if (terminalId !== resolvedActiveTerminalId) {
845847
onActiveTerminalChange(terminalId);
@@ -854,6 +856,7 @@ export default function ThreadTerminalDrawer({
854856
{...(runtimeEnv ? { runtimeEnv } : {})}
855857
terminalFontFamily={terminalFontFamily}
856858
terminalFontSize={terminalFontSize}
859+
terminalLineHeight={terminalLineHeight}
857860
onSessionExited={() => onCloseTerminal(terminalId)}
858861
focusRequestId={focusRequestId}
859862
autoFocus={terminalId === resolvedActiveTerminalId}
@@ -874,6 +877,7 @@ export default function ThreadTerminalDrawer({
874877
{...(runtimeEnv ? { runtimeEnv } : {})}
875878
terminalFontFamily={terminalFontFamily}
876879
terminalFontSize={terminalFontSize}
880+
terminalLineHeight={terminalLineHeight}
877881
onSessionExited={() => onCloseTerminal(resolvedActiveTerminalId)}
878882
focusRequestId={focusRequestId}
879883
autoFocus
@@ -889,22 +893,20 @@ export default function ThreadTerminalDrawer({
889893
<div className="flex h-[22px] items-stretch justify-end border-b border-border/70">
890894
<div className="inline-flex h-full items-stretch">
891895
<TerminalActionButton
892-
className={`inline-flex h-full items-center px-1 text-foreground/90 transition-colors ${
893-
hasReachedTerminalLimit
894-
? "cursor-not-allowed opacity-45 hover:bg-transparent"
895-
: "hover:bg-accent/70"
896-
}`}
896+
className={`inline-flex h-full items-center px-1 text-foreground/90 transition-colors ${hasReachedTerminalLimit
897+
? "cursor-not-allowed opacity-45 hover:bg-transparent"
898+
: "hover:bg-accent/70"
899+
}`}
897900
onClick={onSplitTerminalAction}
898901
label={splitTerminalActionLabel}
899902
>
900903
<SquareSplitHorizontal className="size-3.25" />
901904
</TerminalActionButton>
902905
<TerminalActionButton
903-
className={`inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors ${
904-
hasReachedTerminalLimit
905-
? "cursor-not-allowed opacity-45 hover:bg-transparent"
906-
: "hover:bg-accent/70"
907-
}`}
906+
className={`inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors ${hasReachedTerminalLimit
907+
? "cursor-not-allowed opacity-45 hover:bg-transparent"
908+
: "hover:bg-accent/70"
909+
}`}
908910
onClick={onNewTerminalAction}
909911
label={newTerminalActionLabel}
910912
>
@@ -933,11 +935,10 @@ export default function ThreadTerminalDrawer({
933935
{showGroupHeaders && (
934936
<button
935937
type="button"
936-
className={`flex w-full items-center rounded px-1 py-0.5 text-[10px] uppercase tracking-[0.08em] ${
937-
isGroupActive
938-
? "bg-accent/70 text-foreground"
939-
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
940-
}`}
938+
className={`flex w-full items-center rounded px-1 py-0.5 text-[10px] uppercase tracking-[0.08em] ${isGroupActive
939+
? "bg-accent/70 text-foreground"
940+
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
941+
}`}
941942
onClick={() => onActiveTerminalChange(groupActiveTerminalId)}
942943
>
943944
{terminalGroup.terminalIds.length > 1
@@ -951,17 +952,15 @@ export default function ThreadTerminalDrawer({
951952
>
952953
{terminalGroup.terminalIds.map((terminalId) => {
953954
const isActive = terminalId === resolvedActiveTerminalId;
954-
const closeTerminalLabel = `Close ${
955-
terminalLabelById.get(terminalId) ?? "terminal"
956-
}${isActive && closeShortcutLabel ? ` (${closeShortcutLabel})` : ""}`;
955+
const closeTerminalLabel = `Close ${terminalLabelById.get(terminalId) ?? "terminal"
956+
}${isActive && closeShortcutLabel ? ` (${closeShortcutLabel})` : ""}`;
957957
return (
958958
<div
959959
key={terminalId}
960-
className={`group flex items-center gap-1 rounded px-1 py-0.5 text-[11px] ${
961-
isActive
962-
? "bg-accent text-foreground"
963-
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
964-
}`}
960+
className={`group flex items-center gap-1 rounded px-1 py-0.5 text-[11px] ${isActive
961+
? "bg-accent text-foreground"
962+
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
963+
}`}
965964
>
966965
{showGroupHeaders && (
967966
<span className="text-[10px] text-muted-foreground/80">└</span>

0 commit comments

Comments
 (0)