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