-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
build.ts
executable file
·86 lines (78 loc) · 2.43 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env -S deno run --allow-write
import {
Colors,
flavorEntries,
FlavorName,
flavors,
} from "https://deno.land/x/catppuccin@v1.1.1/mod.ts";
import plist from "https://esm.sh/v135/plist@3.1.0";
type ITermColor = {
"Red Component": number;
"Green Component": number;
"Blue Component": number;
"Alpha Component": number;
"Color Space": "sRGB";
};
const termcolors = (flavorName: FlavorName, suffix?: "Dark" | "Light") => {
const { dark, ...flavor } = flavors[flavorName];
const colors = flavor.colorEntries.reduce((acc, [colorName, color]) => {
// iTerm needs rgb colors between 0.0 and 1.0
const [red, green, blue] = [color.rgb.r, color.rgb.g, color.rgb.b]
.map((v) => v / 255);
return {
[colorName]: {
"Red Component": red,
"Green Component": green,
"Blue Component": blue,
"Alpha Component": 1.0,
"Color Space": "sRGB",
},
...acc,
};
}, {} as Colors<ITermColor>);
const mappings = {
"Ansi 0 Color": dark ? colors.surface1 : colors.subtext1,
"Ansi 1 Color": colors.red,
"Ansi 2 Color": colors.green,
"Ansi 3 Color": colors.yellow,
"Ansi 4 Color": colors.blue,
"Ansi 5 Color": colors.pink,
"Ansi 6 Color": colors.teal,
"Ansi 7 Color": dark ? colors.subtext1 : colors.surface2,
"Ansi 8 Color": dark ? colors.surface2 : colors.subtext0,
"Ansi 9 Color": colors.red,
"Ansi 10 Color": colors.green,
"Ansi 11 Color": colors.yellow,
"Ansi 12 Color": colors.blue,
"Ansi 13 Color": colors.pink,
"Ansi 14 Color": colors.teal,
"Ansi 15 Color": dark ? colors.subtext0 : colors.surface1,
"Background Color": colors.base,
"Foreground Color": colors.text,
"Link Color": colors.sky,
"Bold Color": colors.text,
"Cursor Color": colors.rosewater,
"Cursor Text Color": colors.base,
"Cursor Guide Color": { ...colors.text, "Alpha Component": 0.07 },
"Selection Color": colors.surface2,
"Selected Text Color": colors.text,
};
return Object.entries(mappings).reduce(
(acc, [k, v]) => ({
[suffix ? `${k} (${suffix})` : k]: v,
...acc,
}),
{} as Record<string, ITermColor>,
);
};
flavorEntries.map(([flavorName]) => {
const combined = {
...termcolors(flavorName),
...termcolors("latte", "Light"),
...termcolors(flavorName, "Dark"),
};
Deno.writeTextFileSync(
`./colors/catppuccin-${flavorName}.itermcolors`,
plist.build(combined),
);
});