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

terminalTheme.ts

140 lines3.3 KB

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