icon_theme.rs

  1use collections::HashMap;
  2use gpui::SharedString;
  3
  4use crate::Appearance;
  5
  6/// A family of icon themes.
  7pub struct IconThemeFamily {
  8    /// The unique ID for the icon theme family.
  9    pub id: String,
 10    /// The name of the icon theme family.
 11    pub name: SharedString,
 12    /// The author of the icon theme family.
 13    pub author: SharedString,
 14    /// The list of icon themes in the family.
 15    pub themes: Vec<IconTheme>,
 16}
 17
 18/// An icon theme.
 19#[derive(Debug, PartialEq)]
 20pub struct IconTheme {
 21    /// The unique ID for the icon theme.
 22    pub id: String,
 23    /// The name of the icon theme.
 24    pub name: SharedString,
 25    /// The appearance of the icon theme (e.g., light or dark).
 26    pub appearance: Appearance,
 27    /// The icons used for directories.
 28    pub directory_icons: DirectoryIcons,
 29    /// The icons used for chevrons.
 30    pub chevron_icons: ChevronIcons,
 31    /// The mapping of file types to icon definitions.
 32    pub file_icons: HashMap<String, IconDefinition>,
 33}
 34
 35/// The icons used for directories.
 36#[derive(Debug, PartialEq)]
 37pub struct DirectoryIcons {
 38    /// The path to the icon to use for a collapsed directory.
 39    pub collapsed: Option<SharedString>,
 40    /// The path to the icon to use for an expanded directory.
 41    pub expanded: Option<SharedString>,
 42}
 43
 44/// The icons used for chevrons.
 45#[derive(Debug, PartialEq)]
 46pub struct ChevronIcons {
 47    /// The path to the icon to use for a collapsed chevron.
 48    pub collapsed: Option<SharedString>,
 49    /// The path to the icon to use for an expanded chevron.
 50    pub expanded: Option<SharedString>,
 51}
 52
 53/// An icon definition.
 54#[derive(Debug, PartialEq)]
 55pub struct IconDefinition {
 56    /// The path to the icon file.
 57    pub path: SharedString,
 58}
 59
 60/// A mapping of a file type identifier to its corresponding icon.
 61const FILE_ICONS: &[(&str, &str)] = &[
 62    ("astro", "icons/file_icons/astro.svg"),
 63    ("audio", "icons/file_icons/audio.svg"),
 64    ("bun", "icons/file_icons/bun.svg"),
 65    ("c", "icons/file_icons/c.svg"),
 66    ("code", "icons/file_icons/code.svg"),
 67    ("coffeescript", "icons/file_icons/coffeescript.svg"),
 68    ("cpp", "icons/file_icons/cpp.svg"),
 69    ("css", "icons/file_icons/css.svg"),
 70    ("dart", "icons/file_icons/dart.svg"),
 71    ("default", "icons/file_icons/file.svg"),
 72    ("diff", "icons/file_icons/diff.svg"),
 73    ("docker", "icons/file_icons/docker.svg"),
 74    ("document", "icons/file_icons/book.svg"),
 75    ("elixir", "icons/file_icons/elixir.svg"),
 76    ("elm", "icons/file_icons/elm.svg"),
 77    ("erlang", "icons/file_icons/erlang.svg"),
 78    ("eslint", "icons/file_icons/eslint.svg"),
 79    ("font", "icons/file_icons/font.svg"),
 80    ("fsharp", "icons/file_icons/fsharp.svg"),
 81    ("gleam", "icons/file_icons/gleam.svg"),
 82    ("go", "icons/file_icons/go.svg"),
 83    ("graphql", "icons/file_icons/graphql.svg"),
 84    ("haskell", "icons/file_icons/haskell.svg"),
 85    ("hcl", "icons/file_icons/hcl.svg"),
 86    ("heroku", "icons/file_icons/heroku.svg"),
 87    ("html", "icons/file_icons/html.svg"),
 88    ("image", "icons/file_icons/image.svg"),
 89    ("java", "icons/file_icons/java.svg"),
 90    ("javascript", "icons/file_icons/javascript.svg"),
 91    ("json", "icons/file_icons/code.svg"),
 92    ("julia", "icons/file_icons/julia.svg"),
 93    ("kotlin", "icons/file_icons/kotlin.svg"),
 94    ("lock", "icons/file_icons/lock.svg"),
 95    ("log", "icons/file_icons/info.svg"),
 96    ("lua", "icons/file_icons/lua.svg"),
 97    ("metal", "icons/file_icons/metal.svg"),
 98    ("nim", "icons/file_icons/nim.svg"),
 99    ("nix", "icons/file_icons/nix.svg"),
100    ("ocaml", "icons/file_icons/ocaml.svg"),
101    ("phoenix", "icons/file_icons/phoenix.svg"),
102    ("php", "icons/file_icons/php.svg"),
103    ("prettier", "icons/file_icons/prettier.svg"),
104    ("prisma", "icons/file_icons/prisma.svg"),
105    ("python", "icons/file_icons/python.svg"),
106    ("r", "icons/file_icons/r.svg"),
107    ("react", "icons/file_icons/react.svg"),
108    ("roc", "icons/file_icons/roc.svg"),
109    ("ruby", "icons/file_icons/ruby.svg"),
110    ("rust", "icons/file_icons/rust.svg"),
111    ("sass", "icons/file_icons/sass.svg"),
112    ("scala", "icons/file_icons/scala.svg"),
113    ("settings", "icons/file_icons/settings.svg"),
114    ("storage", "icons/file_icons/database.svg"),
115    ("swift", "icons/file_icons/swift.svg"),
116    ("tcl", "icons/file_icons/tcl.svg"),
117    ("template", "icons/file_icons/html.svg"),
118    ("terminal", "icons/file_icons/terminal.svg"),
119    ("terraform", "icons/file_icons/terraform.svg"),
120    ("toml", "icons/file_icons/toml.svg"),
121    ("typescript", "icons/file_icons/typescript.svg"),
122    ("v", "icons/file_icons/v.svg"),
123    ("vcs", "icons/file_icons/git.svg"),
124    ("video", "icons/file_icons/video.svg"),
125    ("vue", "icons/file_icons/vue.svg"),
126    ("zig", "icons/file_icons/zig.svg"),
127];
128
129/// The name of the default icon theme.
130pub(crate) const DEFAULT_ICON_THEME_NAME: &str = "Zed (Default)";
131
132/// Returns the default icon theme.
133pub fn default_icon_theme() -> IconTheme {
134    IconTheme {
135        id: "zed".into(),
136        name: DEFAULT_ICON_THEME_NAME.into(),
137        appearance: Appearance::Dark,
138        directory_icons: DirectoryIcons {
139            collapsed: Some("icons/file_icons/folder.svg".into()),
140            expanded: Some("icons/file_icons/folder_open.svg".into()),
141        },
142        chevron_icons: ChevronIcons {
143            collapsed: Some("icons/file_icons/chevron_right.svg".into()),
144            expanded: Some("icons/file_icons/chevron_down.svg".into()),
145        },
146        file_icons: HashMap::from_iter(FILE_ICONS.into_iter().map(|(ty, path)| {
147            (
148                ty.to_string(),
149                IconDefinition {
150                    path: (*path).into(),
151                },
152            )
153        })),
154    }
155}