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