ratatui_toolkit/widgets/code_diff/widget/methods/helpers/
render_sidebar.rs

1//! Helper function to render the sidebar file tree.
2
3use ratatui::buffer::Buffer;
4use ratatui::layout::Rect;
5use ratatui::style::Style;
6use ratatui::widgets::{Block, BorderType, Borders, Widget};
7
8use crate::widgets::code_diff::code_diff::CodeDiff;
9
10/// Renders the sidebar file tree.
11///
12/// # Arguments
13///
14/// * `diff` - The CodeDiff instance
15/// * `area` - The area to render the sidebar in
16/// * `buf` - The buffer to render to
17pub fn render_sidebar(diff: &CodeDiff, area: Rect, buf: &mut Buffer) {
18    if area.width < 3 || area.height < 3 {
19        return;
20    }
21
22    let theme = &diff.theme;
23
24    // Create border with focus indicator
25    let border_style = if diff.sidebar_focused {
26        Style::default().fg(theme.border_active)
27    } else {
28        Style::default().fg(theme.border)
29    };
30
31    let block = Block::default()
32        .borders(Borders::ALL)
33        .border_type(BorderType::Rounded)
34        .border_style(border_style)
35        .title(" Files ");
36
37    let inner_area = block.inner(area);
38    block.render(area, buf);
39
40    // Render the file tree widget
41    (&diff.file_tree).render(inner_area, buf);
42}