use ratatui::style::Style;
use super::PaneConfig;
impl PaneConfig {
pub fn with_title_style(mut self, style: Style) -> Self {
self.title_style = Some(style);
self
}
pub fn title_style(&self) -> Option<Style> {
self.title_style
}
}
#[cfg(test)]
mod tests {
use super::*;
use ratatui::style::Color;
#[test]
fn with_title_style_sets_field() {
let style = Style::default().fg(Color::Magenta);
let pane = PaneConfig::new("p").with_title("t").with_title_style(style);
assert_eq!(pane.title_style(), Some(style));
}
#[test]
fn title_style_default_none() {
let pane = PaneConfig::new("p");
assert_eq!(pane.title_style(), None);
}
#[test]
fn snapshot_pane_with_branded_title_style() {
use crate::component::RenderContext;
use crate::component::pane_layout::{PaneDirection, PaneLayout, PaneLayoutState};
use crate::component::test_utils::setup_render;
use ratatui::style::Modifier;
let panes = vec![
PaneConfig::new("left")
.with_title("Brand")
.with_title_style(
Style::default()
.fg(Color::Magenta)
.add_modifier(Modifier::BOLD),
)
.with_proportion(0.5),
PaneConfig::new("right")
.with_title("Plain")
.with_proportion(0.5),
];
let state = PaneLayoutState::new(PaneDirection::Horizontal, panes);
let (mut terminal, theme) = setup_render(40, 5);
terminal
.draw(|frame| {
PaneLayout::view_with(
&state,
&mut RenderContext::new(frame, frame.area(), &theme),
|_, _| {},
);
})
.unwrap();
let plain = terminal.backend().to_string();
let ansi = terminal.backend().to_ansi();
assert!(
ansi.contains("\x1b[35m"),
"expected magenta (35m) for branded title, got:\n{ansi}",
);
assert!(
ansi.contains("\x1b[1m"),
"expected BOLD (1m) for branded title, got:\n{ansi}",
);
insta::assert_snapshot!(plain);
}
#[test]
fn snapshot_pane_title_style_focus_invariant() {
use crate::component::RenderContext;
use crate::component::pane_layout::{PaneDirection, PaneLayout, PaneLayoutState};
use crate::component::test_utils::setup_render;
let style = Style::default().fg(Color::Magenta);
let panes = vec![
PaneConfig::new("focused")
.with_title("F")
.with_title_style(style)
.with_proportion(0.5),
PaneConfig::new("unfocused")
.with_title("U")
.with_title_style(style)
.with_proportion(0.5),
];
let state = PaneLayoutState::new(PaneDirection::Horizontal, panes);
let (mut terminal, theme) = setup_render(40, 5);
terminal
.draw(|frame| {
let mut ctx = RenderContext::new(frame, frame.area(), &theme);
ctx.focused = true;
PaneLayout::view_with(&state, &mut ctx, |_, _| {});
})
.unwrap();
let ansi = terminal.backend().to_ansi();
let plain = terminal.backend().to_string();
let magenta_count = ansi.matches("\x1b[35m").count();
assert!(
magenta_count >= 2,
"expected magenta (35m) at least twice (once per title regardless of focus), got {magenta_count} occurrences:\n{ansi}",
);
insta::assert_snapshot!(plain);
}
}