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