1use std::sync::{Arc, LazyLock};
2
3use collections::HashMap;
4use gpui::SharedString;
5
6use crate::Appearance;
7
8/// A family of icon themes.
9pub struct IconThemeFamily {
10 /// The unique ID for the icon theme family.
11 pub id: String,
12 /// The name of the icon theme family.
13 pub name: SharedString,
14 /// The author of the icon theme family.
15 pub author: SharedString,
16 /// The list of icon themes in the family.
17 pub themes: Vec<IconTheme>,
18}
19
20/// An icon theme.
21#[derive(Debug, PartialEq)]
22pub struct IconTheme {
23 /// The unique ID for the icon theme.
24 pub id: String,
25 /// The name of the icon theme.
26 pub name: SharedString,
27 /// The appearance of the icon theme (e.g., light or dark).
28 pub appearance: Appearance,
29 /// The icons used for directories.
30 pub directory_icons: DirectoryIcons,
31 /// The icons used for chevrons.
32 pub chevron_icons: ChevronIcons,
33 /// The mapping of file stems to their associated icon keys.
34 pub file_stems: HashMap<String, String>,
35 /// The mapping of file suffixes to their associated icon keys.
36 pub file_suffixes: HashMap<String, String>,
37 /// The mapping of icon keys to icon definitions.
38 pub file_icons: HashMap<String, IconDefinition>,
39}
40
41/// The icons used for directories.
42#[derive(Debug, PartialEq)]
43pub struct DirectoryIcons {
44 /// The path to the icon to use for a collapsed directory.
45 pub collapsed: Option<SharedString>,
46 /// The path to the icon to use for an expanded directory.
47 pub expanded: Option<SharedString>,
48}
49
50/// The icons used for chevrons.
51#[derive(Debug, PartialEq)]
52pub struct ChevronIcons {
53 /// The path to the icon to use for a collapsed chevron.
54 pub collapsed: Option<SharedString>,
55 /// The path to the icon to use for an expanded chevron.
56 pub expanded: Option<SharedString>,
57}
58
59/// An icon definition.
60#[derive(Debug, PartialEq)]
61pub struct IconDefinition {
62 /// The path to the icon file.
63 pub path: SharedString,
64}
65
66const FILE_STEMS_BY_ICON_KEY: &[(&str, &[&str])] = &[
67 ("docker", &["Dockerfile"]),
68 ("ruby", &["Podfile"]),
69 ("heroku", &["Procfile"]),
70];
71
72const FILE_SUFFIXES_BY_ICON_KEY: &[(&str, &[&str])] = &[
73 ("astro", &["astro"]),
74 (
75 "audio",
76 &[
77 "aac", "flac", "m4a", "mka", "mp3", "ogg", "opus", "wav", "wma", "wv",
78 ],
79 ),
80 ("backup", &["bak"]),
81 ("bicep", &["bicep"]),
82 ("bun", &["lockb"]),
83 ("c", &["c", "h"]),
84 ("code", &["handlebars", "metadata", "rkt", "scm"]),
85 ("coffeescript", &["coffee"]),
86 (
87 "cpp",
88 &["c++", "cc", "cpp", "cxx", "hh", "hpp", "hxx", "inl", "ixx"],
89 ),
90 ("crystal", &["cr", "ecr"]),
91 ("csharp", &["cs"]),
92 ("csproj", &["csproj"]),
93 ("css", &["css", "pcss", "postcss"]),
94 ("cue", &["cue"]),
95 ("dart", &["dart"]),
96 ("diff", &["diff"]),
97 (
98 "document",
99 &[
100 "doc", "docx", "mdx", "odp", "ods", "odt", "pdf", "ppt", "pptx", "rtf", "txt", "xls",
101 "xlsx",
102 ],
103 ),
104 ("elixir", &["eex", "ex", "exs", "heex"]),
105 ("elm", &["elm"]),
106 (
107 "erlang",
108 &[
109 "Emakefile",
110 "app.src",
111 "erl",
112 "escript",
113 "hrl",
114 "rebar.config",
115 "xrl",
116 "yrl",
117 ],
118 ),
119 (
120 "eslint",
121 &[
122 "eslint.config.cjs",
123 "eslint.config.cts",
124 "eslint.config.js",
125 "eslint.config.mjs",
126 "eslint.config.mts",
127 "eslint.config.ts",
128 "eslintrc",
129 "eslintrc.js",
130 "eslintrc.json",
131 ],
132 ),
133 ("font", &["otf", "ttf", "woff", "woff2"]),
134 ("fsharp", &["fs"]),
135 ("fsproj", &["fsproj"]),
136 ("gitlab", &["gitlab-ci.yml"]),
137 ("gleam", &["gleam"]),
138 ("go", &["go", "mod", "work"]),
139 ("graphql", &["gql", "graphql", "graphqls"]),
140 ("haskell", &["hs"]),
141 ("hcl", &["hcl"]),
142 ("html", &["htm", "html"]),
143 (
144 "image",
145 &[
146 "avif", "bmp", "gif", "heic", "heif", "ico", "j2k", "jfif", "jp2", "jpeg", "jpg",
147 "jxl", "png", "psd", "qoi", "svg", "tiff", "webp",
148 ],
149 ),
150 ("java", &["java"]),
151 ("javascript", &["cjs", "js", "mjs"]),
152 ("json", &["json"]),
153 ("julia", &["jl"]),
154 ("kotlin", &["kt"]),
155 ("lock", &["lock"]),
156 ("log", &["log"]),
157 ("lua", &["lua"]),
158 ("luau", &["luau"]),
159 ("markdown", &["markdown", "md"]),
160 ("metal", &["metal"]),
161 ("nim", &["nim"]),
162 ("nix", &["nix"]),
163 ("ocaml", &["ml", "mli"]),
164 ("php", &["php"]),
165 (
166 "prettier",
167 &[
168 "prettier.config.cjs",
169 "prettier.config.js",
170 "prettier.config.mjs",
171 "prettierignore",
172 "prettierrc",
173 "prettierrc.cjs",
174 "prettierrc.js",
175 "prettierrc.json",
176 "prettierrc.json5",
177 "prettierrc.mjs",
178 "prettierrc.toml",
179 "prettierrc.yaml",
180 "prettierrc.yml",
181 ],
182 ),
183 ("prisma", &["prisma"]),
184 ("python", &["py"]),
185 ("r", &["r", "R"]),
186 ("react", &["cjsx", "ctsx", "jsx", "mjsx", "mtsx", "tsx"]),
187 ("roc", &["roc"]),
188 ("ruby", &["rb"]),
189 ("rust", &["rs"]),
190 ("sass", &["sass", "scss"]),
191 ("scala", &["scala", "sc"]),
192 ("settings", &["conf", "ini", "yaml", "yml"]),
193 ("solidity", &["sol"]),
194 (
195 "storage",
196 &[
197 "accdb", "csv", "dat", "db", "dbf", "dll", "fmp", "fp7", "frm", "gdb", "ib", "jsonc",
198 "ldf", "mdb", "mdf", "myd", "myi", "pdb", "RData", "rdata", "sav", "sdf", "sql",
199 "sqlite", "tsv",
200 ],
201 ),
202 (
203 "stylelint",
204 &[
205 "stylelint.config.cjs",
206 "stylelint.config.js",
207 "stylelint.config.mjs",
208 "stylelintignore",
209 "stylelintrc",
210 "stylelintrc.cjs",
211 "stylelintrc.js",
212 "stylelintrc.json",
213 "stylelintrc.mjs",
214 "stylelintrc.yaml",
215 "stylelintrc.yml",
216 ],
217 ),
218 ("svelte", &["svelte"]),
219 ("swift", &["swift"]),
220 ("tcl", &["tcl"]),
221 ("template", &["hbs", "plist", "xml"]),
222 (
223 "terminal",
224 &[
225 "bash",
226 "bash_aliases",
227 "bash_login",
228 "bash_logout",
229 "bash_profile",
230 "bashrc",
231 "fish",
232 "nu",
233 "profile",
234 "ps1",
235 "sh",
236 "zlogin",
237 "zlogout",
238 "zprofile",
239 "zsh",
240 "zsh_aliases",
241 "zsh_histfile",
242 "zsh_history",
243 "zshenv",
244 "zshrc",
245 ],
246 ),
247 ("terraform", &["tf", "tfvars"]),
248 ("toml", &["toml"]),
249 ("typescript", &["cts", "mts", "ts"]),
250 ("v", &["v", "vsh", "vv"]),
251 (
252 "vcs",
253 &[
254 "COMMIT_EDITMSG",
255 "EDIT_DESCRIPTION",
256 "MERGE_MSG",
257 "NOTES_EDITMSG",
258 "TAG_EDITMSG",
259 "gitattributes",
260 "gitignore",
261 "gitkeep",
262 "gitmodules",
263 ],
264 ),
265 ("vbproj", &["vbproj"]),
266 ("video", &["avi", "m4v", "mkv", "mov", "mp4", "webm", "wmv"]),
267 ("vs_sln", &["sln"]),
268 ("vs_suo", &["suo"]),
269 ("vue", &["vue"]),
270 ("vyper", &["vy", "vyi"]),
271 ("wgsl", &["wgsl"]),
272 ("zig", &["zig"]),
273];
274
275/// A mapping of a file type identifier to its corresponding icon.
276const FILE_ICONS: &[(&str, &str)] = &[
277 ("astro", "icons/file_icons/astro.svg"),
278 ("audio", "icons/file_icons/audio.svg"),
279 ("bicep", "icons/file_icons/file.svg"),
280 ("bun", "icons/file_icons/bun.svg"),
281 ("c", "icons/file_icons/c.svg"),
282 ("code", "icons/file_icons/code.svg"),
283 ("coffeescript", "icons/file_icons/coffeescript.svg"),
284 ("cpp", "icons/file_icons/cpp.svg"),
285 ("crystal", "icons/file_icons/file.svg"),
286 ("csharp", "icons/file_icons/file.svg"),
287 ("csproj", "icons/file_icons/file.svg"),
288 ("css", "icons/file_icons/css.svg"),
289 ("cue", "icons/file_icons/file.svg"),
290 ("dart", "icons/file_icons/dart.svg"),
291 ("default", "icons/file_icons/file.svg"),
292 ("diff", "icons/file_icons/diff.svg"),
293 ("docker", "icons/file_icons/docker.svg"),
294 ("document", "icons/file_icons/book.svg"),
295 ("elixir", "icons/file_icons/elixir.svg"),
296 ("elm", "icons/file_icons/elm.svg"),
297 ("erlang", "icons/file_icons/erlang.svg"),
298 ("eslint", "icons/file_icons/eslint.svg"),
299 ("font", "icons/file_icons/font.svg"),
300 ("fsharp", "icons/file_icons/fsharp.svg"),
301 ("fsproj", "icons/file_icons/file.svg"),
302 ("gitlab", "icons/file_icons/settings.svg"),
303 ("gleam", "icons/file_icons/gleam.svg"),
304 ("go", "icons/file_icons/go.svg"),
305 ("graphql", "icons/file_icons/graphql.svg"),
306 ("haskell", "icons/file_icons/haskell.svg"),
307 ("hcl", "icons/file_icons/hcl.svg"),
308 ("heroku", "icons/file_icons/heroku.svg"),
309 ("html", "icons/file_icons/html.svg"),
310 ("image", "icons/file_icons/image.svg"),
311 ("java", "icons/file_icons/java.svg"),
312 ("javascript", "icons/file_icons/javascript.svg"),
313 ("json", "icons/file_icons/code.svg"),
314 ("julia", "icons/file_icons/julia.svg"),
315 ("kotlin", "icons/file_icons/kotlin.svg"),
316 ("lock", "icons/file_icons/lock.svg"),
317 ("log", "icons/file_icons/info.svg"),
318 ("lua", "icons/file_icons/lua.svg"),
319 ("luau", "icons/file_icons/luau.svg"),
320 ("markdown", "icons/file_icons/book.svg"),
321 ("metal", "icons/file_icons/metal.svg"),
322 ("nim", "icons/file_icons/nim.svg"),
323 ("nix", "icons/file_icons/nix.svg"),
324 ("ocaml", "icons/file_icons/ocaml.svg"),
325 ("phoenix", "icons/file_icons/phoenix.svg"),
326 ("php", "icons/file_icons/php.svg"),
327 ("prettier", "icons/file_icons/prettier.svg"),
328 ("prisma", "icons/file_icons/prisma.svg"),
329 ("python", "icons/file_icons/python.svg"),
330 ("r", "icons/file_icons/r.svg"),
331 ("react", "icons/file_icons/react.svg"),
332 ("roc", "icons/file_icons/roc.svg"),
333 ("ruby", "icons/file_icons/ruby.svg"),
334 ("rust", "icons/file_icons/rust.svg"),
335 ("sass", "icons/file_icons/sass.svg"),
336 ("scala", "icons/file_icons/scala.svg"),
337 ("settings", "icons/file_icons/settings.svg"),
338 ("solidity", "icons/file_icons/file.svg"),
339 ("storage", "icons/file_icons/database.svg"),
340 ("stylelint", "icons/file_icons/javascript.svg"),
341 ("svelte", "icons/file_icons/html.svg"),
342 ("swift", "icons/file_icons/swift.svg"),
343 ("tcl", "icons/file_icons/tcl.svg"),
344 ("template", "icons/file_icons/html.svg"),
345 ("terminal", "icons/file_icons/terminal.svg"),
346 ("terraform", "icons/file_icons/terraform.svg"),
347 ("toml", "icons/file_icons/toml.svg"),
348 ("typescript", "icons/file_icons/typescript.svg"),
349 ("v", "icons/file_icons/v.svg"),
350 ("vbproj", "icons/file_icons/file.svg"),
351 ("vcs", "icons/file_icons/git.svg"),
352 ("video", "icons/file_icons/video.svg"),
353 ("vs_sln", "icons/file_icons/file.svg"),
354 ("vs_suo", "icons/file_icons/file.svg"),
355 ("vue", "icons/file_icons/vue.svg"),
356 ("vyper", "icons/file_icons/vyper.svg"),
357 ("wgsl", "icons/file_icons/wgsl.svg"),
358 ("zig", "icons/file_icons/zig.svg"),
359];
360
361/// Returns a mapping of file associations to icon keys.
362fn icon_keys_by_association(
363 associations_by_icon_key: &[(&str, &[&str])],
364) -> HashMap<String, String> {
365 let mut icon_keys_by_association = HashMap::default();
366 for (icon_key, associations) in associations_by_icon_key {
367 for association in *associations {
368 icon_keys_by_association.insert(association.to_string(), icon_key.to_string());
369 }
370 }
371
372 icon_keys_by_association
373}
374
375/// The name of the default icon theme.
376pub(crate) const DEFAULT_ICON_THEME_NAME: &str = "Zed (Default)";
377
378static DEFAULT_ICON_THEME: LazyLock<Arc<IconTheme>> = LazyLock::new(|| {
379 Arc::new(IconTheme {
380 id: "zed".into(),
381 name: DEFAULT_ICON_THEME_NAME.into(),
382 appearance: Appearance::Dark,
383 directory_icons: DirectoryIcons {
384 collapsed: Some("icons/file_icons/folder.svg".into()),
385 expanded: Some("icons/file_icons/folder_open.svg".into()),
386 },
387 chevron_icons: ChevronIcons {
388 collapsed: Some("icons/file_icons/chevron_right.svg".into()),
389 expanded: Some("icons/file_icons/chevron_down.svg".into()),
390 },
391 file_stems: icon_keys_by_association(FILE_STEMS_BY_ICON_KEY),
392 file_suffixes: icon_keys_by_association(FILE_SUFFIXES_BY_ICON_KEY),
393 file_icons: HashMap::from_iter(FILE_ICONS.into_iter().map(|(ty, path)| {
394 (
395 ty.to_string(),
396 IconDefinition {
397 path: (*path).into(),
398 },
399 )
400 })),
401 })
402});
403
404/// Returns the default icon theme.
405pub fn default_icon_theme() -> Arc<IconTheme> {
406 DEFAULT_ICON_THEME.clone()
407}