From 228dca9d945eef4807f70dc06f5009140344cc5e Mon Sep 17 00:00:00 2001 From: Carlos de Paula Date: Wed, 12 Nov 2025 12:03:57 -0300 Subject: [PATCH] Refactor: Change panes config from String to Style for consistent bg property access --- yazi-config/src/theme/theme.rs | 12 +++++++++--- yazi-fm/src/root.rs | 15 +++++++++------ yazi-plugin/src/theme/theme.rs | 6 +++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 371b585c..fff8fb6f 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -43,11 +43,11 @@ pub struct App { #[derive(Deserialize, DeserializeOver2)] pub struct AppPanes { #[serde(default)] - pub parent: String, + pub parent: Style, #[serde(default)] - pub current: String, + pub current: Style, #[serde(default)] - pub preview: String, + pub preview: Style, } #[derive(Deserialize, DeserializeOver2)] @@ -250,3 +250,9 @@ impl Theme { impl App { pub fn bg_color(&self) -> String { self.overall.bg.map(|c| c.to_string()).unwrap_or_default() } } + +impl AppPanes { + pub fn parent_bg(&self) -> String { self.parent.bg.map(|c| c.to_string()).unwrap_or_default() } + pub fn current_bg(&self) -> String { self.current.bg.map(|c| c.to_string()).unwrap_or_default() } + pub fn preview_bg(&self) -> String { self.preview.bg.map(|c| c.to_string()).unwrap_or_default() } +} diff --git a/yazi-fm/src/root.rs b/yazi-fm/src/root.rs index e7a8a867..8ec5782c 100644 --- a/yazi-fm/src/root.rs +++ b/yazi-fm/src/root.rs @@ -98,8 +98,9 @@ impl Widget for Root<'_> { // Apply pane backgrounds (if configured) // Skip borders: top/bottom rows and left/right edges where borders are drawn - if !THEME.app.panes.parent.is_empty() { - if let Ok(bg_color) = THEME.app.panes.parent.parse::() { + let parent_bg = THEME.app.panes.parent_bg(); + if !parent_bg.is_empty() { + if let Ok(bg_color) = parent_bg.parse::() { let pane = chunks[0]; // Skip first and last row, leftmost and rightmost columns let start_y = pane.top() + 1; @@ -116,8 +117,9 @@ impl Widget for Root<'_> { } } - if !THEME.app.panes.current.is_empty() { - if let Ok(bg_color) = THEME.app.panes.current.parse::() { + let current_bg = THEME.app.panes.current_bg(); + if !current_bg.is_empty() { + if let Ok(bg_color) = current_bg.parse::() { let pane = chunks[1]; // Skip first and last row (no vertical borders for current pane) let start_y = pane.top() + 1; @@ -132,8 +134,9 @@ impl Widget for Root<'_> { } } - if !THEME.app.panes.preview.is_empty() { - if let Ok(bg_color) = THEME.app.panes.preview.parse::() { + let preview_bg = THEME.app.panes.preview_bg(); + if !preview_bg.is_empty() { + if let Ok(bg_color) = preview_bg.parse::() { let pane = chunks[2]; // Skip first and last row, leftmost and rightmost columns let start_y = pane.top() + 1; diff --git a/yazi-plugin/src/theme/theme.rs b/yazi-plugin/src/theme/theme.rs index 5084e1e3..1eaedcff 100644 --- a/yazi-plugin/src/theme/theme.rs +++ b/yazi-plugin/src/theme/theme.rs @@ -37,9 +37,9 @@ fn app() -> Composer { b"panes" => lua .create_table_from([ - ("parent", lua.create_string(&a.panes.parent)?), - ("current", lua.create_string(&a.panes.current)?), - ("preview", lua.create_string(&a.panes.preview)?), + ("parent", Style::from(a.panes.parent).into_lua(lua)?), + ("current", Style::from(a.panes.current).into_lua(lua)?), + ("preview", Style::from(a.panes.preview).into_lua(lua)?), ])? .into_lua(lua), _ => Ok(Value::Nil),