Skip to content

Commit a985053

Browse files
committed
feat(extras): add iTerm theme
1 parent a4629f0 commit a985053

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[default.extend-words]
22
noice = "noice"
3+
iterm = "iterm"
34

45
[files]
56
extend-exclude = ["CHANGELOG.md"]

lua/astrotheme/extras/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ M.extras = {
2020
foot = { ext = "ini", url = "https://codeberg.org/dnkl/foot", label = "Foot" },
2121
gitui = { ext = "ron", url = "https://github.com/extrawurst/gitui", label = "GitUI" },
2222
helix = { ext = "toml", url = "https://helix-editor.com/", label = "Helix" },
23+
iterm = { ext = "itermcolors", url = "https://iterm2.com/", label = "iTerm" },
2324
}
2425

2526
function M.setup()

lua/astrotheme/extras/iterm.lua

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
local util = require "astrotheme.extras"
2+
3+
local M = {}
4+
5+
local base_component = [[
6+
<dict>
7+
<key>Alpha Component</key>
8+
<real>%s</real>
9+
<key>Red Component</key>
10+
<real>%s</real>
11+
<key>Green Component</key>
12+
<real>%s</real>
13+
<key>Blue Component</key>
14+
<real>%s</real>
15+
<key>Color Space</key>
16+
<string>sRGB</string>
17+
</dict>]]
18+
19+
--- @param colors AstroThemePalette
20+
function M.generate(colors)
21+
local function calculate_component(hex, alpha)
22+
hex, alpha = hex:gsub("^#", ""), alpha or 1
23+
local r = string.format("%.16f", tonumber("0x" .. hex:sub(1, 2)) / 255)
24+
local g = string.format("%.16f", tonumber("0x" .. hex:sub(3, 4)) / 255)
25+
local b = string.format("%.16f", tonumber("0x" .. hex:sub(5, 6)) / 255)
26+
return base_component:format(tostring(alpha), r, g, b)
27+
end
28+
local function normalize_colors(_colors)
29+
local new_colors = {}
30+
for k, v in pairs(_colors) do
31+
if type(v) == "table" then
32+
new_colors[k] = normalize_colors(v)
33+
elseif v:match "^#" then
34+
new_colors[k] = calculate_component(v)
35+
else
36+
new_colors[k] = v
37+
end
38+
end
39+
return new_colors
40+
end
41+
local iterm_colors = normalize_colors(colors)
42+
iterm_colors.cursor_guide = calculate_component(colors.syntax.text, 0.25)
43+
iterm_colors.badge = calculate_component(colors.ui.red, 0.5)
44+
return util.template(
45+
[[
46+
<?xml version="1.0" encoding="UTF-8"?>
47+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48+
<plist version="1.0">
49+
<dict>
50+
<key>Ansi 0 Color</key>
51+
${term.black}
52+
<key>Ansi 1 Color</key>
53+
${term.red}
54+
<key>Ansi 2 Color</key>
55+
${term.green}
56+
<key>Ansi 3 Color</key>
57+
${term.yellow}
58+
<key>Ansi 4 Color</key>
59+
${term.blue}
60+
<key>Ansi 5 Color</key>
61+
${term.purple}
62+
<key>Ansi 6 Color</key>
63+
${term.cyan}
64+
<key>Ansi 7 Color</key>
65+
${term.white}
66+
<key>Ansi 8 Color</key>
67+
${term.bright_black}
68+
<key>Ansi 9 Color</key>
69+
${term.bright_red}
70+
<key>Ansi 10 Color</key>
71+
${term.bright_green}
72+
<key>Ansi 11 Color</key>
73+
${term.bright_yellow}
74+
<key>Ansi 12 Color</key>
75+
${term.bright_blue}
76+
<key>Ansi 13 Color</key>
77+
${term.bright_purple}
78+
<key>Ansi 14 Color</key>
79+
${term.bright_cyan}
80+
<key>Ansi 15 Color</key>
81+
${term.bright_white}
82+
<key>Background Color</key>
83+
${ui.base}
84+
<key>Badge Color</key>
85+
${ui.badge}
86+
<key>Bold Color</key>
87+
${ui.accent}
88+
<key>Cursor Color</key>
89+
${syntax.text}
90+
<key>Cursor Guide Color</key>
91+
${cursor_guide}
92+
<key>Cursor Text Color</key>
93+
${ui.base}
94+
<key>Foreground Color</key>
95+
${syntax.text}
96+
<key>Link Color</key>
97+
${syntax.blue}
98+
<key>Selected Text Color</key>
99+
${syntax.text}
100+
<key>Selection Color</key>
101+
${ui.selection}
102+
</dict>
103+
</plist>]],
104+
iterm_colors
105+
)
106+
end
107+
108+
return M

0 commit comments

Comments
 (0)