Skip to content

Commit 10bd044

Browse files
authored
feat: add terminal font settings and built-in Nerd Font (#23391)
1 parent c09bcfe commit 10bd044

File tree

22 files changed

+105
-20
lines changed

22 files changed

+105
-20
lines changed
Binary file not shown.

packages/app/src/components/settings-general.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import {
1919
sansDefault,
2020
sansFontFamily,
2121
sansInput,
22+
terminalDefault,
23+
terminalFontFamily,
24+
terminalInput,
2225
useSettings,
2326
} from "@/context/settings"
2427
import { decode64 } from "@/utils/base64"
@@ -181,6 +184,7 @@ export const SettingsGeneral: Component = () => {
181184
const soundOptions = [noneSound, ...SOUND_OPTIONS]
182185
const mono = () => monoInput(settings.appearance.font())
183186
const sans = () => sansInput(settings.appearance.uiFont())
187+
const terminal = () => terminalInput(settings.appearance.terminalFont())
184188

185189
const soundSelectProps = (
186190
enabled: () => boolean,
@@ -451,6 +455,29 @@ export const SettingsGeneral: Component = () => {
451455
/>
452456
</div>
453457
</SettingsRow>
458+
459+
<SettingsRow
460+
title={language.t("settings.general.row.terminalFont.title")}
461+
description={language.t("settings.general.row.terminalFont.description")}
462+
>
463+
<div class="w-full sm:w-[220px]">
464+
<TextField
465+
data-action="settings-terminal-font"
466+
label={language.t("settings.general.row.terminalFont.title")}
467+
hideLabel
468+
type="text"
469+
value={terminal()}
470+
onChange={(value) => settings.appearance.setTerminalFont(value)}
471+
placeholder={terminalDefault}
472+
spellcheck={false}
473+
autocorrect="off"
474+
autocomplete="off"
475+
autocapitalize="off"
476+
class="text-12-regular"
477+
style={{ "font-family": terminalFontFamily(settings.appearance.terminalFont()) }}
478+
/>
479+
</div>
480+
</SettingsRow>
454481
</SettingsList>
455482
</div>
456483
)

packages/app/src/components/terminal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useLanguage } from "@/context/language"
1111
import { usePlatform } from "@/context/platform"
1212
import { useSDK } from "@/context/sdk"
1313
import { useServer } from "@/context/server"
14-
import { monoFontFamily, useSettings } from "@/context/settings"
14+
import { terminalFontFamily, useSettings } from "@/context/settings"
1515
import type { LocalPTY } from "@/context/terminal"
1616
import { disposeIfDisposable, getHoveredLinkText, setOptionIfSupported } from "@/utils/runtime-adapters"
1717
import { terminalWriter } from "@/utils/terminal-writer"
@@ -300,7 +300,7 @@ export const Terminal = (props: TerminalProps) => {
300300
})
301301

302302
createEffect(() => {
303-
const font = monoFontFamily(settings.appearance.font())
303+
const font = terminalFontFamily(settings.appearance.terminalFont())
304304
if (!term) return
305305
setOptionIfSupported(term, "fontFamily", font)
306306
scheduleFit()
@@ -360,7 +360,7 @@ export const Terminal = (props: TerminalProps) => {
360360
cols: restoreSize?.cols,
361361
rows: restoreSize?.rows,
362362
fontSize: 14,
363-
fontFamily: monoFontFamily(settings.appearance.font()),
363+
fontFamily: terminalFontFamily(settings.appearance.terminalFont()),
364364
allowTransparency: false,
365365
convertEol: false,
366366
theme: terminalColors(),

packages/app/src/context/settings.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Settings {
3939
fontSize: number
4040
mono: string
4141
sans: string
42+
terminal: string
4243
}
4344
keybinds: Record<string, string>
4445
permissions: {
@@ -50,13 +51,16 @@ export interface Settings {
5051

5152
export const monoDefault = "System Mono"
5253
export const sansDefault = "System Sans"
54+
export const terminalDefault = "JetBrainsMono Nerd Font Mono"
5355

5456
const monoFallback =
5557
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
5658
const sansFallback = 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
59+
const terminalFallback = '"JetBrainsMono Nerd Font Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
5760

5861
const monoBase = monoFallback
5962
const sansBase = sansFallback
63+
const terminalBase = terminalFallback
6064

6165
function input(font: string | undefined) {
6266
return font ?? ""
@@ -89,6 +93,14 @@ export function sansFontFamily(font: string | undefined) {
8993
return stack(font, sansBase)
9094
}
9195

96+
export function terminalInput(font: string | undefined) {
97+
return input(font)
98+
}
99+
100+
export function terminalFontFamily(font: string | undefined) {
101+
return stack(font, terminalBase)
102+
}
103+
92104
const defaultSettings: Settings = {
93105
general: {
94106
autoSave: true,
@@ -110,6 +122,7 @@ const defaultSettings: Settings = {
110122
fontSize: 14,
111123
mono: "",
112124
sans: "",
125+
terminal: "",
113126
},
114127
keybinds: {},
115128
permissions: {
@@ -233,6 +246,10 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
233246
setUIFont(value: string) {
234247
setStore("appearance", "sans", value.trim() ? value : "")
235248
},
249+
terminalFont: withFallback(() => store.appearance?.terminal, defaultSettings.appearance.terminal),
250+
setTerminalFont(value: string) {
251+
setStore("appearance", "terminal", value.trim() ? value : "")
252+
},
236253
},
237254
keybinds: {
238255
get: (action: string) => store.keybinds?.[action],

packages/app/src/i18n/ar.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ export const dict = {
565565
"settings.general.row.theme.title": "السمة",
566566
"settings.general.row.theme.description": "تخصيص سمة OpenCode.",
567567
"settings.general.row.font.title": "خط الكود",
568-
"settings.general.row.font.description": "خصّص الخط المستخدم في كتل التعليمات البرمجية والطرفيات",
568+
"settings.general.row.font.description": "خصّص الخط المستخدم في كتل التعليمات البرمجية",
569+
"settings.general.row.terminalFont.title": "Terminal Font",
570+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
569571
"settings.general.row.uiFont.title": "خط الواجهة",
570572
"settings.general.row.uiFont.description": "خصّص الخط المستخدم في الواجهة بأكملها",
571573
"settings.general.row.followup.title": "سلوك المتابعة",

packages/app/src/i18n/br.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ export const dict = {
572572
"settings.general.row.theme.title": "Tema",
573573
"settings.general.row.theme.description": "Personalize como o OpenCode é tematizado.",
574574
"settings.general.row.font.title": "Fonte de código",
575-
"settings.general.row.font.description": "Personalize a fonte usada em blocos de código e terminais",
575+
"settings.general.row.font.description": "Personalize a fonte usada em blocos de código",
576+
"settings.general.row.terminalFont.title": "Terminal Font",
577+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
576578
"settings.general.row.uiFont.title": "Fonte da interface",
577579
"settings.general.row.uiFont.description": "Personalize a fonte usada em toda a interface",
578580
"settings.general.row.followup.title": "Comportamento de acompanhamento",

packages/app/src/i18n/bs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,9 @@ export const dict = {
637637
"settings.general.row.theme.title": "Tema",
638638
"settings.general.row.theme.description": "Prilagodi temu OpenCode-a.",
639639
"settings.general.row.font.title": "Font za kod",
640-
"settings.general.row.font.description": "Prilagodi font koji se koristi u blokovima koda i terminalima",
640+
"settings.general.row.font.description": "Prilagodi font koji se koristi u blokovima koda",
641+
"settings.general.row.terminalFont.title": "Terminal Font",
642+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
641643
"settings.general.row.uiFont.title": "UI font",
642644
"settings.general.row.uiFont.description": "Prilagodi font koji se koristi u cijelom interfejsu",
643645
"settings.general.row.followup.title": "Ponašanje nadovezivanja",

packages/app/src/i18n/da.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ export const dict = {
632632
"settings.general.row.theme.title": "Tema",
633633
"settings.general.row.theme.description": "Tilpas hvordan OpenCode er temabestemt.",
634634
"settings.general.row.font.title": "Kode-skrifttype",
635-
"settings.general.row.font.description": "Tilpas skrifttypen, der bruges i kodeblokke og terminaler",
635+
"settings.general.row.font.description": "Tilpas skrifttypen, der bruges i kodeblokke",
636+
"settings.general.row.terminalFont.title": "Terminal Font",
637+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
636638
"settings.general.row.uiFont.title": "UI-skrifttype",
637639
"settings.general.row.uiFont.description": "Tilpas skrifttypen, der bruges i hele brugerfladen",
638640
"settings.general.row.followup.title": "Opfølgningsadfærd",

packages/app/src/i18n/de.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ export const dict = {
582582
"settings.general.row.theme.title": "Thema",
583583
"settings.general.row.theme.description": "Das Thema von OpenCode anpassen.",
584584
"settings.general.row.font.title": "Code-Schriftart",
585-
"settings.general.row.font.description": "Die in Codeblöcken und Terminals verwendete Schriftart anpassen",
585+
"settings.general.row.font.description": "Die in Codeblöcken verwendete Schriftart anpassen",
586+
"settings.general.row.terminalFont.title": "Terminal Font",
587+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
586588
"settings.general.row.uiFont.title": "UI-Schriftart",
587589
"settings.general.row.uiFont.description": "Die im gesamten Interface verwendete Schriftart anpassen",
588590
"settings.general.row.followup.title": "Verhalten bei Folgefragen",

packages/app/src/i18n/en.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ export const dict = {
735735
"settings.general.row.theme.title": "Theme",
736736
"settings.general.row.theme.description": "Customise how OpenCode is themed.",
737737
"settings.general.row.font.title": "Code Font",
738-
"settings.general.row.font.description": "Customise the font used in code blocks and terminals",
738+
"settings.general.row.font.description": "Customise the font used in code blocks",
739+
"settings.general.row.terminalFont.title": "Terminal Font",
740+
"settings.general.row.terminalFont.description": "Customise the font used in the terminal",
739741
"settings.general.row.uiFont.title": "UI Font",
740742
"settings.general.row.uiFont.description": "Customise the font used throughout the interface",
741743
"settings.general.row.followup.title": "Follow-up behavior",

0 commit comments

Comments
 (0)