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