diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 14c61536a3fca..9838fd898f1c1 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -648,7 +648,7 @@ impl EditorView { let lang = doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME); let config = editor.config(); - let icon = config.icons.mime.lang(lang); + let icon = config.icons.mime.get(lang); let text = format!( " {icon} {}{} ", diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index b096a47534229..0034db6169e32 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -424,7 +424,7 @@ where { let mime = &context.editor.config().icons.mime; - let icon = mime.lang(context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME)); + let icon = mime.get(context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME)); write(context, format!(" {} ", icon), None); } @@ -536,7 +536,7 @@ where let vcs = if head.is_empty() { format!("{head}") } else { - format!("{icon}{head}") + format!("{icon} {head}") }; write(context, vcs, None); diff --git a/helix-view/src/editor/config.rs b/helix-view/src/editor/config.rs index 5c7f53457c72d..db0fbe636db65 100644 --- a/helix-view/src/editor/config.rs +++ b/helix-view/src/editor/config.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Default, PartialEq, Eq, Clone)] +#[serde(default)] pub struct Icons { pub mime: Mime, pub lsp: Lsp, @@ -153,7 +154,7 @@ impl Lsp { } } -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default)] pub struct Diagnostic { hint: Option, info: Option, @@ -161,17 +162,6 @@ pub struct Diagnostic { error: Option, } -impl Default for Diagnostic { - fn default() -> Self { - Self { - hint: Some(String::from("○")), - info: Some(String::from("●")), - warning: Some(String::from("▲")), - error: Some(String::from("■")), - } - } -} - impl Diagnostic { const DEFAULT: &'static str = "●"; @@ -191,19 +181,11 @@ impl Diagnostic { } } -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default)] pub struct Vcs { icon: Option, } -impl Default for Vcs { - fn default() -> Self { - Self { - icon: Some(String::from(" ")), - } - } -} - impl Vcs { const DEFAULT: &'static str = ""; @@ -214,37 +196,21 @@ impl Vcs { } } -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Default)] pub struct Mime { directory: Option, + #[serde(flatten)] mime: HashMap, } -impl Default for Mime { - fn default() -> Self { - Self { - directory: None, - mime: { - let mut mime = HashMap::new(); - mime.insert(String::from("rust"), String::from("󱘗 ")); - mime.insert(String::from("markdown"), String::from(" ")); - mime.insert(String::from("css"), String::from("󰌜 ")); - mime.insert(String::from("toml"), String::from(" ")); - mime.insert(String::from("lock"), String::from("󱌼 ")); - mime.insert(String::from("text"), String::from(" ")); - mime - }, - } - } -} - impl Mime { pub fn directory(&self) -> &str { - self.directory.as_ref().map_or("🖿 ", |directory| directory) + self.directory.as_ref().map_or("", |directory| directory) } - pub fn lang(&self, mime: &str) -> &str { - self.mime.get(mime).map_or("*", |mime| mime) + // Returns the symbol that matches the name, if any, otherwise returns the name back. + pub fn get<'name, 'mime: 'name>(&'mime self, r#type: &'name str) -> &'name str { + self.mime.get(r#type).map_or(r#type, |mime| mime) } }