perfectly working buffer now

This commit is contained in:
filipriec
2025-04-15 00:18:42 +02:00
parent 779683de4b
commit f42790980d

View File

@@ -18,25 +18,10 @@ pub fn render_buffer_list(
app_state: &AppState,
) {
// --- Style Definitions ---
const RIGHT_SEPARATOR: &str = ""; // U+E0B0
const LEFT_SEPARATOR: &str = ""; // U+E0B2
let active_style = Style::default()
.fg(theme.bg)
.bg(theme.highlight);
let separator_style_active_to_inactive = Style::default()
.fg(theme.highlight)
.bg(theme.bg);
let separator_style_inactive_to_active = Style::default()
.fg(theme.highlight)
.bg(theme.bg);
let separator_style_inactive_to_inactive = Style::default()
.fg(theme.fg)
.bg(theme.bg);
let inactive_style = Style::default()
.fg(theme.fg)
.bg(theme.bg);
@@ -44,7 +29,6 @@ pub fn render_buffer_list(
// --- Create Spans ---
let mut spans = Vec::new();
let history = &app_state.ui.buffer_history;
let history_len = history.len();
let mut current_width = 0;
for (i, view) in history.iter().enumerate() {
@@ -52,44 +36,27 @@ pub fn render_buffer_list(
let buffer_name = view.display_name();
let buffer_text = format!(" {} ", buffer_name);
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
let separator_width = UnicodeWidthStr::width(RIGHT_SEPARATOR);
let needed_width = if i > 0 { separator_width } else { 0 } + text_width + separator_width;
// Calculate width needed for this buffer (separator + text)
let needed_width = text_width;
if current_width + needed_width > area.width as usize {
break;
}
if i > 0 {
let prev_is_active = i - 1 == app_state.ui.active_buffer_index;
let sep_style = if is_active {
separator_style_inactive_to_active
} else {
separator_style_inactive_to_inactive
};
spans.push(Span::styled(LEFT_SEPARATOR, sep_style));
current_width += separator_width;
}
// Add the buffer text itself
let text_style = if is_active { active_style } else { inactive_style };
spans.push(Span::styled(buffer_text, text_style));
current_width += text_width;
let next_is_active = i + 1 < history_len && i + 1 == app_state.ui.active_buffer_index;
let sep_style = if is_active {
separator_style_active_to_inactive
} else {
separator_style_inactive_to_inactive
};
spans.push(Span::styled(RIGHT_SEPARATOR, sep_style));
current_width += separator_width;
}
// --- Filler Span ---
let remaining_width = area.width.saturating_sub(current_width as u16);
spans.push(Span::styled(
" ".repeat(remaining_width as usize),
inactive_style,
));
// --- Render ---
let buffer_line = Line::from(spans);
let paragraph = Paragraph::new(buffer_line).alignment(Alignment::Left);
f.render_widget(paragraph, area);