Skip to content

feat: install more terminal fonts #17289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,17 @@ type ValidateUserPasswordResponse struct {
// TerminalFontName is the name of supported terminal font
type TerminalFontName string

var TerminalFontNames = []TerminalFontName{TerminalFontUnknown, TerminalFontIBMPlexMono, TerminalFontFiraCode}
var TerminalFontNames = []TerminalFontName{
TerminalFontUnknown, TerminalFontIBMPlexMono, TerminalFontFiraCode,
TerminalFontSourceCodePro, TerminalFontJetBrainsMono,
}

const (
TerminalFontUnknown TerminalFontName = ""
TerminalFontIBMPlexMono TerminalFontName = "ibm-plex-mono"
TerminalFontFiraCode TerminalFontName = "fira-code"
TerminalFontUnknown TerminalFontName = ""
TerminalFontIBMPlexMono TerminalFontName = "ibm-plex-mono"
TerminalFontFiraCode TerminalFontName = "fira-code"
TerminalFontSourceCodePro TerminalFontName = "source-code-pro"
TerminalFontJetBrainsMono TerminalFontName = "jetbrains-mono"
)

type UserAppearanceSettings struct {
Expand Down
12 changes: 7 additions & 5 deletions docs/reference/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"@fontsource-variable/inter": "5.1.1",
"@fontsource/fira-code": "5.2.5",
"@fontsource/ibm-plex-mono": "5.1.1",
"@fontsource/jetbrains-mono": "5.2.5",
"@fontsource/source-code-pro": "5.2.5",
"@monaco-editor/react": "4.6.0",
"@mui/icons-material": "5.16.14",
"@mui/lab": "5.0.0-alpha.175",
Expand Down
16 changes: 16 additions & 0 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { Stack } from "components/Stack/Stack";
import { ThemeOverride } from "contexts/ThemeProvider";
import type { FC } from "react";
import themes, { DEFAULT_THEME, type Theme } from "theme";
import { DEFAULT_TERMINAL_FONT, terminalFontLabels } from "theme/constants";
import {
DEFAULT_TERMINAL_FONT,
terminalFontLabels,
terminalFonts,
} from "theme/constants";
import { Section } from "../Section";

export interface AppearanceFormProps {
Expand Down Expand Up @@ -115,7 +119,7 @@ export const AppearanceForm: FC<AppearanceFormProps> = ({
value={name}
control={<Radio />}
label={
<div css={{ fontFamily: terminalFontLabels[name] }}>
<div css={{ fontFamily: terminalFonts[name] }}>
{terminalFontLabels[name]}
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe("appearance page", () => {
theme_preference: "dark",
});

const ibmPlex = await screen.findByText("Fira Code");
await userEvent.click(ibmPlex);
const firaCode = await screen.findByText("Fira Code");
await userEvent.click(firaCode);

// Check if the API was called correctly
expect(API.updateAppearanceSettings).toHaveBeenCalledTimes(1);
Expand All @@ -61,4 +61,44 @@ describe("appearance page", () => {
theme_preference: "dark",
});
});

it("changes font to fira code, then back to web terminal font", async () => {
renderWithAuth(<AppearancePage />);

// given
jest
.spyOn(API, "updateAppearanceSettings")
.mockResolvedValueOnce({
...MockUser,
terminal_font: "fira-code",
theme_preference: "dark",
})
.mockResolvedValueOnce({
...MockUser,
terminal_font: "ibm-plex-mono",
theme_preference: "dark",
});

// when
const firaCode = await screen.findByText("Fira Code");
await userEvent.click(firaCode);

// then
expect(API.updateAppearanceSettings).toHaveBeenCalledTimes(1);
expect(API.updateAppearanceSettings).toHaveBeenCalledWith({
terminal_font: "fira-code",
theme_preference: "dark",
});

// when
const ibmPlex = await screen.findByText("Web Terminal Font");
await userEvent.click(ibmPlex);

// then
expect(API.updateAppearanceSettings).toHaveBeenCalledTimes(2);
expect(API.updateAppearanceSettings).toHaveBeenNthCalledWith(2, {
terminal_font: "ibm-plex-mono",
theme_preference: "dark",
});
});
});
12 changes: 11 additions & 1 deletion site/src/theme/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ export const BODY_FONT_FAMILY = `"Inter Variable", system-ui, sans-serif`;

export const terminalFonts: Record<TerminalFontName, string> = {
"fira-code": MONOSPACE_FONT_FAMILY.replace("IBM Plex Mono", "Fira Code"),
"jetbrains-mono": MONOSPACE_FONT_FAMILY.replace(
"IBM Plex Mono",
"JetBrains Mono",
),
"source-code-pro": MONOSPACE_FONT_FAMILY.replace(
"IBM Plex Mono",
"Source Code Pro",
),
"ibm-plex-mono": MONOSPACE_FONT_FAMILY,

"": MONOSPACE_FONT_FAMILY,
};
export const terminalFontLabels: Record<TerminalFontName, string> = {
"fira-code": "Fira Code",
"ibm-plex-mono": "IBM Plex Mono",
"jetbrains-mono": "JetBrains Mono",
"source-code-pro": "Source Code Pro",
"ibm-plex-mono": "Web Terminal Font",
"": "", // needed for enum completeness, otherwise fails the build
};
export const DEFAULT_TERMINAL_FONT = "ibm-plex-mono";
Expand Down
6 changes: 5 additions & 1 deletion site/src/theme/globalFonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import "@fontsource/ibm-plex-mono/400.css";
import "@fontsource/ibm-plex-mono/600.css";
// Main body copy font
import "@fontsource-variable/inter";
// Alternative font for Terminal
// Alternative fonts for Terminal
import "@fontsource/fira-code/400.css";
import "@fontsource/fira-code/600.css";
import "@fontsource/source-code-pro/400.css";
import "@fontsource/source-code-pro/600.css";
import "@fontsource/jetbrains-mono/400.css";
import "@fontsource/jetbrains-mono/600.css";
Loading