Skip to content

Commit dfce006

Browse files
committed
feat: Allow custom hex accent color
1 parent bbe095f commit dfce006

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-23
lines changed

packages/catppuccin-vsc/package.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,45 @@
106106
"sky",
107107
"sapphire",
108108
"blue",
109-
"lavender"
109+
"lavender",
110+
"custom"
110111
]
111112
},
113+
"catppuccin.customAccentColors": {
114+
"scope": "application",
115+
"type": "object",
116+
"default": {
117+
"all": "#cba6f7"
118+
},
119+
"description": "Custom accent colors as hex codes. Only used when `accentColor` is set to `custom`. Use `all` for all flavors or specify per flavor (`latte`, `frappe`, `macchiato`, `mocha`).",
120+
"properties": {
121+
"all": {
122+
"type": "string",
123+
"pattern": "^#[0-9A-Fa-f]{6}$",
124+
"description": "Custom accent color for all flavors"
125+
},
126+
"latte": {
127+
"type": "string",
128+
"pattern": "^#[0-9A-Fa-f]{6}$",
129+
"description": "Custom accent color for Latte flavor"
130+
},
131+
"frappe": {
132+
"type": "string",
133+
"pattern": "^#[0-9A-Fa-f]{6}$",
134+
"description": "Custom accent color for Frappé flavor"
135+
},
136+
"macchiato": {
137+
"type": "string",
138+
"pattern": "^#[0-9A-Fa-f]{6}$",
139+
"description": "Custom accent color for Macchiato flavor"
140+
},
141+
"mocha": {
142+
"type": "string",
143+
"pattern": "^#[0-9A-Fa-f]{6}$",
144+
"description": "Custom accent color for Mocha flavor"
145+
}
146+
}
147+
},
112148
"catppuccin.workbenchMode": {
113149
"scope": "application",
114150
"type": "string",

packages/catppuccin-vsc/src/theme/extensions/gitlens.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { GitLensColors, ThemeContext } from "@/types";
22
import { opacity, shade, transparent } from "@/theme/utilities";
33

44
export default function colors(context: ThemeContext): Partial<GitLensColors> {
5-
const { palette, options } = context;
5+
const { palette, accent } = context;
66

77
const graphLaneColors = [
88
palette.mauve,
@@ -21,22 +21,16 @@ export default function colors(context: ThemeContext): Partial<GitLensColors> {
2121
palette.sky,
2222
];
2323

24-
const accentIndex = graphLaneColors.indexOf(palette[options.accent]);
24+
const accentIndex = graphLaneColors.indexOf(accent);
2525

2626
return {
2727
"gitlens.gutterBackgroundColor": opacity(palette.surface0, 0.3),
2828
"gitlens.gutterForegroundColor": palette.text,
29-
"gitlens.gutterUncommittedForegroundColor": palette[options.accent],
29+
"gitlens.gutterUncommittedForegroundColor": accent,
3030
"gitlens.trailingLineBackgroundColor": transparent,
3131
"gitlens.trailingLineForegroundColor": opacity(palette.text, 0.3),
32-
"gitlens.lineHighlightBackgroundColor": opacity(
33-
palette[options.accent],
34-
0.15,
35-
),
36-
"gitlens.lineHighlightOverviewRulerColor": opacity(
37-
palette[options.accent],
38-
0.8,
39-
),
32+
"gitlens.lineHighlightBackgroundColor": opacity(accent, 0.15),
33+
"gitlens.lineHighlightOverviewRulerColor": opacity(accent, 0.8),
4034
"gitlens.openAutolinkedIssueIconColor": palette.green,
4135
"gitlens.closedAutolinkedIssueIconColor": palette.mauve,
4236
"gitlens.closedPullRequestIconColor": palette.red,
@@ -63,10 +57,8 @@ export default function colors(context: ThemeContext): Partial<GitLensColors> {
6357
"gitlens.decorations.statusMergingOrRebasingForegroundColor":
6458
palette.yellow,
6559
"gitlens.decorations.workspaceRepoMissingForegroundColor": palette.subtext0,
66-
"gitlens.decorations.workspaceCurrentForegroundColor":
67-
palette[options.accent],
68-
"gitlens.decorations.workspaceRepoOpenForegroundColor":
69-
palette[options.accent],
60+
"gitlens.decorations.workspaceCurrentForegroundColor": accent,
61+
"gitlens.decorations.workspaceRepoOpenForegroundColor": accent,
7062
"gitlens.decorations.worktreeHasUncommittedChangesForegroundColor":
7163
palette.peach,
7264
"gitlens.decorations.worktreeMissingForegroundColor": palette.maroon,

packages/catppuccin-vsc/src/theme/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const defaultOptions: ThemeOptions = {
2121
bracketMode: "rainbow",
2222
extraBordersEnabled: false,
2323
customUIColors: {},
24+
customAccentColors: {},
2425
syncWithIconPack: true,
2526
};
2627

@@ -48,12 +49,20 @@ export const compileTheme = (
4849
...options.colorOverrides?.[flavor],
4950
};
5051

52+
const accent =
53+
options.accent === "custom"
54+
? (options.customAccentColors?.[flavor] ??
55+
options.customAccentColors?.all ??
56+
palette.mauve)
57+
: palette[options.accent];
58+
5159
const context: ThemeContext = {
5260
flavor,
5361
palette,
5462
paletteAnsi,
5563
options,
5664
isLatte: flavor === "latte",
65+
accent,
5766
};
5867

5968
return {

packages/catppuccin-vsc/src/theme/ui/azureDataStudio.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import type { ThemeContext } from "@/types";
55
* deprecated in VSCode.
66
*/
77
const azureDataStudio = (context: ThemeContext): Record<string, string> => {
8-
const { options, palette } = context;
9-
const accent = palette[options.accent];
8+
const { palette, accent } = context;
109

1110
return {
1211
"button.secondaryBorder": accent,

packages/catppuccin-vsc/src/theme/ui/customNames.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ const parseCustomUiColor = (k: string, v: string): [string, number] => {
4747
const hexColorRegex = /^#([\dA-Fa-f]{3,4}){1,2}$/;
4848

4949
const customNamedColors = (context: ThemeContext): CustomNamedColors => {
50-
const { flavor, palette, options } = context;
51-
const accent = palette[options.accent];
50+
const { flavor, palette, options, accent } = context;
5251

5352
const customUIColors = {
5453
...options.customUIColors.all,

packages/catppuccin-vsc/src/theme/uiColors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import uiCustomizations from "./ui";
66
export const getUiColors = (
77
context: ThemeContext,
88
): Partial<Record<keyof WorkbenchColors, string>> => {
9-
const { palette, paletteAnsi, options, isLatte } = context;
9+
const { palette, paletteAnsi, options, isLatte, accent } = context;
1010

11-
const accent = palette[options.accent];
1211
const dropBackground = opacity(accent, 0.2);
1312
const border = options.extraBordersEnabled
1413
? opacity(palette.overlay1, 0.15)

packages/catppuccin-vsc/src/types/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type * from "@catppuccin/vsc-typegen/types/errorlens";
1717
export type * from "@catppuccin/vsc-typegen/types/github-pull-request";
1818
export type * from "@catppuccin/vsc-typegen/types/gitlens";
1919

20-
export type CatppuccinAccent = AccentName;
20+
export type CatppuccinAccent = AccentName | "custom";
2121
export type CatppuccinFlavor = FlavorName;
2222
export { type ColorName } from "@catppuccin/palette";
2323
export type CatppuccinWorkbenchMode = "default" | "flat" | "minimal";
@@ -41,6 +41,8 @@ export type ColorOverrides = Partial<
4141

4242
export type CustomUIColors = Partial<FlavorsPlusAll<Record<string, string>>>;
4343

44+
export type CustomAccentColors = Partial<FlavorsPlusAll<string>>;
45+
4446
export type ThemeOptions = {
4547
/** The accent color to use */
4648
accent: CatppuccinAccent;
@@ -71,6 +73,11 @@ export type ThemeOptions = {
7173
*/
7274
customUIColors: CustomUIColors;
7375

76+
/**
77+
* Controls whether to sync the currently active Catppuccin flavor with the [Catppuccin Icon Pack](https://github.com/catppuccin/vscode-icons)
78+
*/
79+
customAccentColors: CustomAccentColors;
80+
7481
/**
7582
* Controls whether to sync the currently active Catppuccin flavor with the [Catppuccin Icon Pack](https://github.com/catppuccin/vscode-icons)
7683
*/
@@ -90,4 +97,5 @@ export type ThemeContext = {
9097
paletteAnsi: CatppuccinPaletteAnsi;
9198
options: ThemeOptions;
9299
isLatte: boolean;
100+
accent: string;
93101
};

packages/catppuccin-vsc/src/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
CatppuccinWorkbenchMode,
1919
ColorOverrides,
2020
CustomUIColors,
21+
CustomAccentColors,
2122
ThemeOptions,
2223
ThemePaths,
2324
} from "./types";
@@ -120,6 +121,7 @@ export const getConfiguration = (): ThemeOptions => {
120121
bracketMode: config.get<CatppuccinBracketMode>("bracketMode"),
121122
extraBordersEnabled: config.get<boolean>("extraBordersEnabled"),
122123
customUIColors: config.get<CustomUIColors>("customUIColors"),
124+
customAccentColors: config.get<CustomAccentColors>("customAccentColors"),
123125
syncWithIconPack: config.get<boolean>("syncWithIconPack"),
124126
} satisfies Partial<ThemeOptions>;
125127
return {

0 commit comments

Comments
 (0)