diff --git a/yazi-binding/src/icon.rs b/yazi-binding/src/icon.rs index cef7fe07..1a8486d1 100644 --- a/yazi-binding/src/icon.rs +++ b/yazi-binding/src/icon.rs @@ -7,8 +7,9 @@ use crate::{Style, cached_field}; pub struct Icon { inner: &'static yazi_config::Icon, - v_text: Option, - v_style: Option, + v_text: Option, + v_style: Option, + v_hovered_text: Option, } impl Deref for Icon { @@ -19,7 +20,7 @@ impl Deref for Icon { impl From<&'static yazi_config::Icon> for Icon { fn from(icon: &'static yazi_config::Icon) -> Self { - Self { inner: icon, v_text: None, v_style: None } + Self { inner: icon, v_text: None, v_style: None, v_hovered_text: None } } } @@ -27,5 +28,8 @@ impl UserData for Icon { fn add_fields>(fields: &mut F) { cached_field!(fields, text, |lua, me| lua.create_string(&me.text)); cached_field!(fields, style, |_, me| Ok(Style::from(me.style))); + cached_field!(fields, hovered_text, |lua, me| { + me.hovered_text.as_ref().map(|s| lua.create_string(s)).transpose() + }); } } diff --git a/yazi-config/preset/theme-dark.toml b/yazi-config/preset/theme-dark.toml index 1d36e9d0..89c7b8bb 100644 --- a/yazi-config/preset/theme-dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -997,7 +997,7 @@ conds = [ { if = "dummy", text = "", fg = "#f44336" }, # Fallback - { if = "dir", text = "", fg = "#03a9f4" }, + { if = "dir", text = "", fg = "#03a9f4", hovered_text = "" }, { if = "exec", text = "", fg = "#8bc34a" }, { if = "!dir", text = "", fg = "#ffffff" }, ] diff --git a/yazi-config/src/icon.rs b/yazi-config/src/icon.rs index d19cdc21..fe418474 100644 --- a/yazi-config/src/icon.rs +++ b/yazi-config/src/icon.rs @@ -2,6 +2,7 @@ use crate::Style; #[derive(Clone, Debug)] pub struct Icon { - pub text: String, - pub style: Style, + pub text: String, + pub style: Style, + pub hovered_text: Option, } diff --git a/yazi-config/src/theme/icon.rs b/yazi-config/src/theme/icon.rs index e0b13699..5522b544 100644 --- a/yazi-config/src/theme/icon.rs +++ b/yazi-config/src/theme/icon.rs @@ -132,15 +132,22 @@ impl<'de> Deserialize<'de> for PatIcons { { #[derive(Deserialize)] struct Shadow { - url: Pattern, - text: String, - fg: Option, + url: Pattern, + text: String, + fg: Option, + hovered_text: Option, } Ok(Self( >::deserialize(deserializer)? .into_iter() - .map(|s| (s.url, I { text: s.text, style: Style { fg: s.fg, ..Default::default() } })) + .map(|s| { + (s.url, I { + text: s.text, + style: Style { fg: s.fg, ..Default::default() }, + hovered_text: s.hovered_text, + }) + }) .collect(), )) } @@ -162,15 +169,22 @@ impl<'de> Deserialize<'de> for StrIcons { { #[derive(Deserialize)] struct Shadow { - name: String, - text: String, - fg: Option, + name: String, + text: String, + fg: Option, + hovered_text: Option, } Ok(Self( >::deserialize(deserializer)? .into_iter() - .map(|s| (s.name, I { text: s.text, style: Style { fg: s.fg, ..Default::default() } })) + .map(|s| { + (s.name, I { + text: s.text, + style: Style { fg: s.fg, ..Default::default() }, + hovered_text: s.hovered_text, + }) + }) .collect(), )) } @@ -192,16 +206,47 @@ impl<'de> Deserialize<'de> for CondIcons { { #[derive(Deserialize)] struct Shadow { - r#if: Condition, - text: String, - fg: Option, + r#if: Condition, + text: String, + fg: Option, + hovered_text: Option, } Ok(Self( >::deserialize(deserializer)? .into_iter() - .map(|s| (s.r#if, I { text: s.text, style: Style { fg: s.fg, ..Default::default() } })) + .map(|s| { + (s.r#if, I { + text: s.text, + style: Style { fg: s.fg, ..Default::default() }, + hovered_text: s.hovered_text, + }) + }) .collect(), )) } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_icon_struct_with_hovered_text() { + let icon = I { + text: "normal_icon".to_string(), + style: Style::default(), + hovered_text: Some("hovered_icon".to_string()), + }; + + assert_eq!(icon.text, "normal_icon"); + assert_eq!(icon.hovered_text, Some("hovered_icon".to_string())); + } + #[test] + fn test_icon_struct_without_hovered_text() { + let icon = + I { text: "normal_icon".to_string(), style: Style::default(), hovered_text: None }; + + assert_eq!(icon.text, "normal_icon"); + assert_eq!(icon.hovered_text, None); + } +} diff --git a/yazi-plugin/preset/components/entity.lua b/yazi-plugin/preset/components/entity.lua index aad13b12..86e38a71 100644 --- a/yazi-plugin/preset/components/entity.lua +++ b/yazi-plugin/preset/components/entity.lua @@ -30,7 +30,8 @@ function Entity:icon() if not icon then return "" elseif self._file.is_hovered then - return icon.text .. " " + local text = icon.hovered_text or icon.text + return text .. " " else return ui.Line(icon.text .. " "):style(icon.style) end