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", &["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", "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 "document",
104 &[
105 "doc", "docx", "mdx", "odp", "ods", "odt", "pdf", "ppt", "pptx", "rtf", "txt", "xls",
106 "xlsx",
107 ],
108 ),
109 ("elixir", &["eex", "ex", "exs", "heex"]),
110 ("elm", &["elm"]),
111 (
112 "erlang",
113 &[
114 "Emakefile",
115 "app.src",
116 "erl",
117 "escript",
118 "hrl",
119 "rebar.config",
120 "xrl",
121 "yrl",
122 ],
123 ),
124 (
125 "eslint",
126 &[
127 "eslint.config.cjs",
128 "eslint.config.cts",
129 "eslint.config.js",
130 "eslint.config.mjs",
131 "eslint.config.mts",
132 "eslint.config.ts",
133 "eslintrc",
134 "eslintrc.js",
135 "eslintrc.json",
136 ],
137 ),
138 ("font", &["otf", "ttf", "woff", "woff2"]),
139 ("fsharp", &["fs"]),
140 ("fsproj", &["fsproj"]),
141 ("gitlab", &["gitlab-ci.yml"]),
142 ("gleam", &["gleam"]),
143 ("go", &["go", "mod", "work"]),
144 ("graphql", &["gql", "graphql", "graphqls"]),
145 ("haskell", &["hs"]),
146 ("hcl", &["hcl"]),
147 ("html", &["htm", "html"]),
148 (
149 "image",
150 &[
151 "avif", "bmp", "gif", "heic", "heif", "ico", "j2k", "jfif", "jp2", "jpeg", "jpg",
152 "jxl", "png", "psd", "qoi", "svg", "tiff", "webp",
153 ],
154 ),
155 ("ipynb", &["ipynb"]),
156 ("java", &["java"]),
157 ("javascript", &["cjs", "js", "mjs"]),
158 ("json", &["json", "jsonc"]),
159 ("julia", &["jl"]),
160 ("kdl", &["kdl"]),
161 ("kotlin", &["kt"]),
162 ("lock", &["lock"]),
163 ("log", &["log"]),
164 ("lua", &["lua"]),
165 ("luau", &["luau"]),
166 ("markdown", &["markdown", "md"]),
167 ("metal", &["metal"]),
168 ("nim", &["nim", "nims", "nimble"]),
169 ("nix", &["nix"]),
170 ("ocaml", &["ml", "mli"]),
171 ("odin", &["odin"]),
172 ("php", &["php"]),
173 (
174 "prettier",
175 &[
176 "prettier.config.cjs",
177 "prettier.config.js",
178 "prettier.config.mjs",
179 "prettierignore",
180 "prettierrc",
181 "prettierrc.cjs",
182 "prettierrc.js",
183 "prettierrc.json",
184 "prettierrc.json5",
185 "prettierrc.mjs",
186 "prettierrc.toml",
187 "prettierrc.yaml",
188 "prettierrc.yml",
189 ],
190 ),
191 ("prisma", &["prisma"]),
192 ("puppet", &["pp"]),
193 ("python", &["py"]),
194 ("r", &["r", "R"]),
195 ("react", &["cjsx", "ctsx", "jsx", "mjsx", "mtsx", "tsx"]),
196 ("roc", &["roc"]),
197 ("ruby", &["rb"]),
198 ("rust", &["rs"]),
199 ("sass", &["sass", "scss"]),
200 ("scala", &["scala", "sc"]),
201 ("settings", &["conf", "ini", "yaml", "yml"]),
202 ("solidity", &["sol"]),
203 (
204 "storage",
205 &[
206 "accdb", "csv", "dat", "db", "dbf", "dll", "fmp", "fp7", "frm", "gdb", "ib", "ldf",
207 "mdb", "mdf", "myd", "myi", "pdb", "RData", "rdata", "sav", "sdf", "sql", "sqlite",
208 "tsv",
209 ],
210 ),
211 (
212 "stylelint",
213 &[
214 "stylelint.config.cjs",
215 "stylelint.config.js",
216 "stylelint.config.mjs",
217 "stylelintignore",
218 "stylelintrc",
219 "stylelintrc.cjs",
220 "stylelintrc.js",
221 "stylelintrc.json",
222 "stylelintrc.mjs",
223 "stylelintrc.yaml",
224 "stylelintrc.yml",
225 ],
226 ),
227 ("surrealql", &["surql"]),
228 ("svelte", &["svelte"]),
229 ("swift", &["swift"]),
230 ("tcl", &["tcl"]),
231 ("template", &["hbs", "plist", "xml"]),
232 (
233 "terminal",
234 &[
235 "bash",
236 "bash_aliases",
237 "bash_login",
238 "bash_logout",
239 "bash_profile",
240 "bashrc",
241 "fish",
242 "nu",
243 "profile",
244 "ps1",
245 "sh",
246 "zlogin",
247 "zlogout",
248 "zprofile",
249 "zsh",
250 "zsh_aliases",
251 "zsh_histfile",
252 "zsh_history",
253 "zshenv",
254 "zshrc",
255 ],
256 ),
257 ("terraform", &["tf", "tfvars"]),
258 ("toml", &["toml"]),
259 ("typescript", &["cts", "mts", "ts"]),
260 ("v", &["v", "vsh", "vv"]),
261 (
262 "vcs",
263 &[
264 "COMMIT_EDITMSG",
265 "EDIT_DESCRIPTION",
266 "MERGE_MSG",
267 "NOTES_EDITMSG",
268 "TAG_EDITMSG",
269 "gitattributes",
270 "gitignore",
271 "gitkeep",
272 "gitmodules",
273 ],
274 ),
275 ("vbproj", &["vbproj"]),
276 ("video", &["avi", "m4v", "mkv", "mov", "mp4", "webm", "wmv"]),
277 ("vs_sln", &["sln"]),
278 ("vs_suo", &["suo"]),
279 ("vue", &["vue"]),
280 ("vyper", &["vy", "vyi"]),
281 ("wgsl", &["wgsl"]),
282 ("zig", &["zig"]),
283];
284
285/// A mapping of a file type identifier to its corresponding icon.
286const FILE_ICONS: &[(&str, &str)] = &[
287 ("astro", "icons/file_icons/astro.svg"),
288 ("audio", "icons/file_icons/audio.svg"),
289 ("bicep", "icons/file_icons/file.svg"),
290 ("bun", "icons/file_icons/bun.svg"),
291 ("c", "icons/file_icons/c.svg"),
292 ("cairo", "icons/file_icons/cairo.svg"),
293 ("code", "icons/file_icons/code.svg"),
294 ("coffeescript", "icons/file_icons/coffeescript.svg"),
295 ("cpp", "icons/file_icons/cpp.svg"),
296 ("crystal", "icons/file_icons/file.svg"),
297 ("csharp", "icons/file_icons/file.svg"),
298 ("csproj", "icons/file_icons/file.svg"),
299 ("css", "icons/file_icons/css.svg"),
300 ("cue", "icons/file_icons/file.svg"),
301 ("dart", "icons/file_icons/dart.svg"),
302 ("default", "icons/file_icons/file.svg"),
303 ("diff", "icons/file_icons/diff.svg"),
304 ("docker", "icons/file_icons/docker.svg"),
305 ("document", "icons/file_icons/book.svg"),
306 ("elixir", "icons/file_icons/elixir.svg"),
307 ("elm", "icons/file_icons/elm.svg"),
308 ("erlang", "icons/file_icons/erlang.svg"),
309 ("eslint", "icons/file_icons/eslint.svg"),
310 ("font", "icons/file_icons/font.svg"),
311 ("fsharp", "icons/file_icons/fsharp.svg"),
312 ("fsproj", "icons/file_icons/file.svg"),
313 ("gitlab", "icons/file_icons/settings.svg"),
314 ("gleam", "icons/file_icons/gleam.svg"),
315 ("go", "icons/file_icons/go.svg"),
316 ("graphql", "icons/file_icons/graphql.svg"),
317 ("haskell", "icons/file_icons/haskell.svg"),
318 ("hcl", "icons/file_icons/hcl.svg"),
319 ("heroku", "icons/file_icons/heroku.svg"),
320 ("html", "icons/file_icons/html.svg"),
321 ("image", "icons/file_icons/image.svg"),
322 ("ipynb", "icons/file_icons/jupyter.svg"),
323 ("java", "icons/file_icons/java.svg"),
324 ("javascript", "icons/file_icons/javascript.svg"),
325 ("json", "icons/file_icons/code.svg"),
326 ("julia", "icons/file_icons/julia.svg"),
327 ("kdl", "icons/file_icons/kdl.svg"),
328 ("kotlin", "icons/file_icons/kotlin.svg"),
329 ("lock", "icons/file_icons/lock.svg"),
330 ("log", "icons/file_icons/info.svg"),
331 ("lua", "icons/file_icons/lua.svg"),
332 ("luau", "icons/file_icons/luau.svg"),
333 ("markdown", "icons/file_icons/book.svg"),
334 ("metal", "icons/file_icons/metal.svg"),
335 ("nim", "icons/file_icons/nim.svg"),
336 ("nix", "icons/file_icons/nix.svg"),
337 ("ocaml", "icons/file_icons/ocaml.svg"),
338 ("odin", "icons/file_icons/odin.svg"),
339 ("phoenix", "icons/file_icons/phoenix.svg"),
340 ("php", "icons/file_icons/php.svg"),
341 ("prettier", "icons/file_icons/prettier.svg"),
342 ("prisma", "icons/file_icons/prisma.svg"),
343 ("puppet", "icons/file_icons/puppet.svg"),
344 ("python", "icons/file_icons/python.svg"),
345 ("r", "icons/file_icons/r.svg"),
346 ("react", "icons/file_icons/react.svg"),
347 ("roc", "icons/file_icons/roc.svg"),
348 ("ruby", "icons/file_icons/ruby.svg"),
349 ("rust", "icons/file_icons/rust.svg"),
350 ("sass", "icons/file_icons/sass.svg"),
351 ("scala", "icons/file_icons/scala.svg"),
352 ("settings", "icons/file_icons/settings.svg"),
353 ("solidity", "icons/file_icons/file.svg"),
354 ("storage", "icons/file_icons/database.svg"),
355 ("stylelint", "icons/file_icons/javascript.svg"),
356 ("surrealql", "icons/file_icons/surrealql.svg"),
357 ("svelte", "icons/file_icons/html.svg"),
358 ("swift", "icons/file_icons/swift.svg"),
359 ("tcl", "icons/file_icons/tcl.svg"),
360 ("template", "icons/file_icons/html.svg"),
361 ("terminal", "icons/file_icons/terminal.svg"),
362 ("terraform", "icons/file_icons/terraform.svg"),
363 ("toml", "icons/file_icons/toml.svg"),
364 ("typescript", "icons/file_icons/typescript.svg"),
365 ("v", "icons/file_icons/v.svg"),
366 ("vbproj", "icons/file_icons/file.svg"),
367 ("vcs", "icons/file_icons/git.svg"),
368 ("video", "icons/file_icons/video.svg"),
369 ("vs_sln", "icons/file_icons/file.svg"),
370 ("vs_suo", "icons/file_icons/file.svg"),
371 ("vue", "icons/file_icons/vue.svg"),
372 ("vyper", "icons/file_icons/vyper.svg"),
373 ("wgsl", "icons/file_icons/wgsl.svg"),
374 ("zig", "icons/file_icons/zig.svg"),
375];
376
377/// Returns a mapping of file associations to icon keys.
378fn icon_keys_by_association(
379 associations_by_icon_key: &[(&str, &[&str])],
380) -> HashMap<String, String> {
381 let mut icon_keys_by_association = HashMap::default();
382 for (icon_key, associations) in associations_by_icon_key {
383 for association in *associations {
384 icon_keys_by_association.insert(association.to_string(), icon_key.to_string());
385 }
386 }
387
388 icon_keys_by_association
389}
390
391/// The name of the default icon theme.
392pub(crate) const DEFAULT_ICON_THEME_NAME: &str = "Zed (Default)";
393
394static DEFAULT_ICON_THEME: LazyLock<Arc<IconTheme>> = LazyLock::new(|| {
395 Arc::new(IconTheme {
396 id: "zed".into(),
397 name: DEFAULT_ICON_THEME_NAME.into(),
398 appearance: Appearance::Dark,
399 directory_icons: DirectoryIcons {
400 collapsed: Some("icons/file_icons/folder.svg".into()),
401 expanded: Some("icons/file_icons/folder_open.svg".into()),
402 },
403 named_directory_icons: HashMap::default(),
404 chevron_icons: ChevronIcons {
405 collapsed: Some("icons/file_icons/chevron_right.svg".into()),
406 expanded: Some("icons/file_icons/chevron_down.svg".into()),
407 },
408 file_stems: icon_keys_by_association(FILE_STEMS_BY_ICON_KEY),
409 file_suffixes: icon_keys_by_association(FILE_SUFFIXES_BY_ICON_KEY),
410 file_icons: HashMap::from_iter(FILE_ICONS.iter().map(|(ty, path)| {
411 (
412 ty.to_string(),
413 IconDefinition {
414 path: (*path).into(),
415 },
416 )
417 })),
418 })
419});
420
421/// Returns the default icon theme.
422pub fn default_icon_theme() -> Arc<IconTheme> {
423 DEFAULT_ICON_THEME.clone()
424}