Refactor: Change panes config from String to Style for consistent bg property access

This commit is contained in:
Carlos de Paula 2025-11-12 12:03:57 -03:00
parent b51c2e5fb6
commit 228dca9d94
3 changed files with 21 additions and 12 deletions

View file

@ -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() }
}

View file

@ -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::<ratatui::style::Color>() {
let parent_bg = THEME.app.panes.parent_bg();
if !parent_bg.is_empty() {
if let Ok(bg_color) = parent_bg.parse::<ratatui::style::Color>() {
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::<ratatui::style::Color>() {
let current_bg = THEME.app.panes.current_bg();
if !current_bg.is_empty() {
if let Ok(bg_color) = current_bg.parse::<ratatui::style::Color>() {
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::<ratatui::style::Color>() {
let preview_bg = THEME.app.panes.preview_bg();
if !preview_bg.is_empty() {
if let Ok(bg_color) = preview_bg.parse::<ratatui::style::Color>() {
let pane = chunks[2];
// Skip first and last row, leftmost and rightmost columns
let start_y = pane.top() + 1;

View file

@ -37,9 +37,9 @@ fn app() -> Composer<ComposerGet, ComposerSet> {
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),