perfectly working buffer now
This commit is contained in:
@@ -18,25 +18,10 @@ pub fn render_buffer_list(
|
|||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
) {
|
) {
|
||||||
// --- Style Definitions ---
|
// --- Style Definitions ---
|
||||||
const RIGHT_SEPARATOR: &str = ""; // U+E0B0
|
|
||||||
const LEFT_SEPARATOR: &str = ""; // U+E0B2
|
|
||||||
|
|
||||||
let active_style = Style::default()
|
let active_style = Style::default()
|
||||||
.fg(theme.bg)
|
.fg(theme.bg)
|
||||||
.bg(theme.highlight);
|
.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()
|
let inactive_style = Style::default()
|
||||||
.fg(theme.fg)
|
.fg(theme.fg)
|
||||||
.bg(theme.bg);
|
.bg(theme.bg);
|
||||||
@@ -44,7 +29,6 @@ pub fn render_buffer_list(
|
|||||||
// --- Create Spans ---
|
// --- Create Spans ---
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
let history = &app_state.ui.buffer_history;
|
let history = &app_state.ui.buffer_history;
|
||||||
let history_len = history.len();
|
|
||||||
let mut current_width = 0;
|
let mut current_width = 0;
|
||||||
|
|
||||||
for (i, view) in history.iter().enumerate() {
|
for (i, view) in history.iter().enumerate() {
|
||||||
@@ -52,44 +36,27 @@ pub fn render_buffer_list(
|
|||||||
let buffer_name = view.display_name();
|
let buffer_name = view.display_name();
|
||||||
let buffer_text = format!(" {} ", buffer_name);
|
let buffer_text = format!(" {} ", buffer_name);
|
||||||
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
|
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 {
|
if current_width + needed_width > area.width as usize {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 {
|
// Add the buffer text itself
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let text_style = if is_active { active_style } else { inactive_style };
|
let text_style = if is_active { active_style } else { inactive_style };
|
||||||
spans.push(Span::styled(buffer_text, text_style));
|
spans.push(Span::styled(buffer_text, text_style));
|
||||||
current_width += text_width;
|
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);
|
let remaining_width = area.width.saturating_sub(current_width as u16);
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
" ".repeat(remaining_width as usize),
|
" ".repeat(remaining_width as usize),
|
||||||
inactive_style,
|
inactive_style,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// --- Render ---
|
||||||
let buffer_line = Line::from(spans);
|
let buffer_line = Line::from(spans);
|
||||||
let paragraph = Paragraph::new(buffer_line).alignment(Alignment::Left);
|
let paragraph = Paragraph::new(buffer_line).alignment(Alignment::Left);
|
||||||
f.render_widget(paragraph, area);
|
f.render_widget(paragraph, area);
|
||||||
|
|||||||
Reference in New Issue
Block a user