Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

terminalTheme.ts

116 lines3.0 KB

1import { BUILT_IN_THEMES, getThemeColorsForAppearance } from "@t3tools/shared/themePalettes";
2​
3import {
4 getMobileThemeVariables,
5 themeColorToNativeColor,
6 type MobileThemeId,
7} from "../../lib/mobileTheme";
8​
9export type TerminalAppearanceScheme = "light" | "dark";
10​
11export interface TerminalTheme {
12 readonly background: string;
13 readonly foreground: string;
14 readonly mutedForeground: string;
15 readonly border: string;
16 readonly cursorForeground: string;
17 readonly cursorBackground: string;
18 readonly palette: readonly string[];
20​
21const PIERRE_LIGHT_THEME: TerminalTheme = {
22 // Pierre terminal palette with the app's shared screen background.
23 background: "#f2f2f7",
24 foreground: "#6C6C71",
25 mutedForeground: "#8E8E95",
26 border: "#eeeeef",
27 cursorForeground: "#009fff",
28 cursorBackground: "#f2f2f7",
29 palette: [
30 "#1F1F21",
31 "#ff2e3f",
32 "#0dbe4e",
33 "#ffca00",
34 "#009fff",
35 "#c635e4",
36 "#08c0ef",
37 "#c6c6c8",
38 "#1F1F21",
39 "#ff2e3f",
40 "#0dbe4e",
41 "#ffca00",
42 "#009fff",
43 "#c635e4",
44 "#08c0ef",
45 "#c6c6c8",
46 ],
47};
48​
49const PIERRE_DARK_THEME: TerminalTheme = {
50 // Pierre terminal palette with the app's shared screen background.
51 background: "#0a0a0a",
52 foreground: "#adadb1",
53 mutedForeground: "#8E8E95",
54 border: "#2e2e30",
55 cursorForeground: "#009fff",
56 cursorBackground: "#0a0a0a",
57 palette: [
58 "#141415",
59 "#ff2e3f",
60 "#0dbe4e",
61 "#ffca00",
62 "#009fff",
63 "#c635e4",
64 "#08c0ef",
65 "#c6c6c8",
66 "#141415",
67 "#ff2e3f",
68 "#0dbe4e",
69 "#ffca00",
70 "#009fff",
71 "#c635e4",
72 "#08c0ef",
73 "#c6c6c8",
74 ],
75};
76​
77export function getPierreTerminalTheme(scheme: TerminalAppearanceScheme): TerminalTheme {
78 return scheme === "light" ? PIERRE_LIGHT_THEME : PIERRE_DARK_THEME;
80​
81export function getMobileTerminalTheme(
82 themeId: MobileThemeId,
83 scheme: TerminalAppearanceScheme,
84): TerminalTheme {
85 const base = getPierreTerminalTheme(scheme);
86 if (themeId === "t3-code") return base;
87​
88 const theme = BUILT_IN_THEMES.find((candidate) => candidate.id === themeId) ?? BUILT_IN_THEMES[0];
89 const palette = getThemeColorsForAppearance(theme, scheme) ?? theme.colors;
90 const colors = getMobileThemeVariables(themeId, scheme);
91 const background = themeColorToNativeColor(palette.terminalBackground);
92 return {
93 ...base,
94 background,
95 foreground: themeColorToNativeColor(palette.terminalForeground),
96 mutedForeground: colors["--color-foreground-muted"],
97 border: colors["--color-border"],
98 cursorForeground: themeColorToNativeColor(palette.terminalCursor),
99 cursorBackground: background,
100 };
102​
103export function buildGhosttyThemeConfig(theme: TerminalTheme): string {
104 const lines = [
105 `background = ${theme.background}`,
106 `foreground = ${theme.foreground}`,
107 `cursor-color = ${theme.cursorForeground}`,
108 `cursor-text = ${theme.cursorBackground}`,
109 ];
110​
111 for (const [index, color] of theme.palette.entries()) {
112 lines.push(`palette = ${index}=${color}`);
113 }
114​
115 return `${lines.join("\n")}\n`;