// src/components/handlers/buffer_list.rs use crate::config::colors::themes::Theme; use crate::state::app::state::AppState; use ratatui::{ layout::{Alignment, Rect}, style::{Modifier, Style, Stylize}, text::{Line, Span}, widgets::Paragraph, // Removed Block and Borders Frame, }; use unicode_width::UnicodeWidthStr; pub fn render_buffer_list( f: &mut Frame, area: Rect, // Still 1 line high theme: &Theme, app_state: &AppState, ) { let mut current_buffer_name = "*scratch*"; // Default // Determine the active buffer name based on UI state if app_state.ui.show_intro { current_buffer_name = "Intro"; } else if app_state.ui.show_register { current_buffer_name = "Register"; } else if app_state.ui.show_login { current_buffer_name = "Login"; } else if app_state.ui.show_admin { current_buffer_name = "Admin Panel"; } else if app_state.ui.show_form { current_buffer_name = "Data Form"; } // Add more conditions if other views exist // --- Style Definitions --- // Use Powerline symbols if available, otherwise fallback // Ensure your terminal font supports these for the best look! const RIGHT_SEPARATOR: &str = ""; // U+E0B0 // const RIGHT_SEPARATOR: &str = ">"; // Fallback const LEFT_SEPARATOR: &str = ""; // U+E0B2 // const LEFT_SEPARATOR: &str = "<"; // Fallback let active_style = Style::default() .fg(theme.bg) // Text on active background .bg(theme.highlight); // Active background let separator_style_active_to_inactive = Style::default() .fg(theme.highlight) // Separator color matches the background it comes from .bg(theme.bg); // Background matches the area it points into let inactive_style = Style::default() .fg(theme.fg) // Default text color .bg(theme.bg); // Default background // --- Create Spans --- let buffer_text = format!(" {} ", current_buffer_name); // Add padding // Span 1: Left edge (no separator needed if it's the first element) // If you had multiple buffers, the *first* one wouldn't have a left separator. // let left_sep = Span::raw(""); // Example for first buffer // Span 2: The active buffer text let buffer_span = Span::styled(buffer_text.clone(), active_style); // Span 3: The right separator pointing away from the active buffer let right_sep = Span::styled( RIGHT_SEPARATOR, separator_style_active_to_inactive, ); // Span 4: Filler for the rest of the line let text_width = UnicodeWidthStr::width(buffer_text.as_str()); // Account for the width of the separator character (usually 1) let separator_width = UnicodeWidthStr::width(RIGHT_SEPARATOR); let total_used_width = (text_width + separator_width) as u16; let remaining_width = area.width.saturating_sub(total_used_width); let filler_span = Span::styled( " ".repeat(remaining_width as usize), inactive_style, // Filler uses inactive style ); // --- Combine into Line --- // Order: Buffer Text -> Right Separator -> Filler // (If multiple buffers: LeftSep -> Text -> RightSep -> LeftSep -> Text -> ...) let buffer_line = Line::from(vec![buffer_span, right_sep, filler_span]); // --- Render --- let paragraph = Paragraph::new(buffer_line).alignment(Alignment::Left); f.render_widget(paragraph, area); }