-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use dark/light mode syncing colorscheme format (#18)
- Loading branch information
1 parent
c51f181
commit 7a71cf4
Showing
7 changed files
with
4,016 additions
and
1,440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,147 +1,86 @@ | ||
#!/usr/bin/env -S deno run --allow-write --allow-env | ||
import { variants } from "https://esm.sh/@catppuccin/palette@0.1.5"; | ||
import Handlebars from "https://esm.sh/handlebars@4.7.7"; | ||
#!/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"; | ||
|
||
const template = `<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
{{#each color}} | ||
<key>{{key}}</key> | ||
<dict> | ||
<key>Color Space</key> | ||
<string>sRGB</string> | ||
<key>Red Component</key> | ||
<real>{{col.red}}</real> | ||
<key>Green Component</key> | ||
<real>{{col.green}}</real> | ||
<key>Blue Component</key> | ||
<real>{{col.blue}}</real> | ||
<key>Alpha Component</key> | ||
<real>{{col.alpha}}</real> | ||
</dict> | ||
{{/each}} | ||
</dict> | ||
</plist>`; | ||
type ITermColor = { | ||
"Red Component": number; | ||
"Green Component": number; | ||
"Blue Component": number; | ||
"Alpha Component": number; | ||
"Color Space": "sRGB"; | ||
}; | ||
|
||
for (let [flavour, colors] of Object.entries(variants)) { | ||
const isLatte = flavour === "latte"; | ||
const termcolors = (flavorName: FlavorName, suffix?: "Dark" | "Light") => { | ||
const { dark, ...flavor } = flavors[flavorName]; | ||
|
||
colors = Object.fromEntries( | ||
Object.entries(colors).map(([key, value]) => { | ||
const [red, green, blue] = [ | ||
value.hex.slice(1, 3), | ||
value.hex.slice(3, 5), | ||
value.hex.slice(5, 7), | ||
].map((v) => parseInt(v, 16) / 255); | ||
return [key, { red, green, blue, alpha: 1 }]; | ||
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.surface1 : colors.subtext0, | ||
"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: 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>, | ||
); | ||
const termcolor = [ | ||
{ | ||
key: "Ansi 0 Color", | ||
col: isLatte ? colors.subtext1 : colors.surface1, | ||
}, | ||
{ | ||
key: "Ansi 1 Color", | ||
col: colors.red, | ||
}, | ||
{ | ||
key: "Ansi 2 Color", | ||
col: colors.green, | ||
}, | ||
{ | ||
key: "Ansi 3 Color", | ||
col: colors.yellow, | ||
}, | ||
{ | ||
key: "Ansi 4 Color", | ||
col: colors.blue, | ||
}, | ||
{ | ||
key: "Ansi 5 Color", | ||
col: colors.pink, | ||
}, | ||
{ | ||
key: "Ansi 6 Color", | ||
col: colors.teal, | ||
}, | ||
{ | ||
key: "Ansi 7 Color", | ||
col: isLatte ? colors.surface2 : colors.subtext1, | ||
}, | ||
{ | ||
key: "Ansi 8 Color", | ||
col: isLatte ? colors.subtext0 : colors.surface2, | ||
}, | ||
{ | ||
key: "Ansi 9 Color", | ||
col: colors.red, | ||
}, | ||
{ | ||
key: "Ansi 10 Color", | ||
col: colors.green, | ||
}, | ||
{ | ||
key: "Ansi 11 Color", | ||
col: colors.yellow, | ||
}, | ||
{ | ||
key: "Ansi 12 Color", | ||
col: colors.blue, | ||
}, | ||
{ | ||
key: "Ansi 13 Color", | ||
col: colors.pink, | ||
}, | ||
{ | ||
key: "Ansi 14 Color", | ||
col: colors.teal, | ||
}, | ||
{ | ||
key: "Ansi 15 Color", | ||
col: isLatte ? colors.surface1 : colors.subtext0, | ||
}, | ||
{ | ||
key: "Background Color", | ||
col: colors.base, | ||
}, | ||
{ | ||
key: "Foreground Color", | ||
col: colors.text, | ||
}, | ||
{ | ||
key: "Link Color", | ||
col: colors.sky, | ||
}, | ||
{ | ||
key: "Bold Color", | ||
col: colors.text, | ||
}, | ||
{ | ||
key: "Cursor Color", | ||
col: colors.rosewater, | ||
}, | ||
{ | ||
key: "Cursor Text Color", | ||
col: colors.base, | ||
}, | ||
{ | ||
key: "Cursor Guide Color", | ||
col: { ...colors.text, alpha: 0.07 }, | ||
}, | ||
{ | ||
key: "Selection Color", | ||
col: colors.surface2, | ||
}, | ||
{ | ||
key: "Selected Text Color", | ||
col: colors.text, | ||
}, | ||
]; | ||
const compiled = Handlebars.compile(template); | ||
}; | ||
|
||
flavorEntries.map(([flavorName]) => { | ||
const combined = { | ||
...termcolors(flavorName), | ||
...termcolors("latte", "Light"), | ||
...termcolors(flavorName, "Dark"), | ||
}; | ||
|
||
Deno.writeTextFileSync( | ||
`./colors/catppuccin-${flavour}.itermcolors`, | ||
compiled({ color: termcolor }), | ||
`./colors/catppuccin-${flavorName}.itermcolors`, | ||
plist.build(combined), | ||
); | ||
} | ||
}); |
Oops, something went wrong.