flake_edit/tui/components/footer/
view.rs

1use ratatui::{
2    buffer::Buffer,
3    layout::Rect,
4    text::{Line, Span},
5    widgets::{Paragraph, Widget},
6};
7
8use crate::tui::helpers::layouts;
9use crate::tui::style::{APP_NAME, FOOTER_STYLE, LABEL_STYLE};
10
11/// Footer widget with left and right content plus app name
12pub struct Footer<'a> {
13    left_spans: Vec<Span<'a>>,
14    right_spans: Vec<Span<'a>>,
15}
16
17impl<'a> Footer<'a> {
18    pub fn new(left_spans: Vec<Span<'a>>, right_spans: Vec<Span<'a>>) -> Self {
19        Self {
20            left_spans,
21            right_spans,
22        }
23    }
24}
25
26impl Widget for Footer<'_> {
27    fn render(self, area: Rect, buf: &mut Buffer) {
28        let footer_left = Line::from(self.left_spans);
29
30        let mut right = self.right_spans;
31        if !right.is_empty() {
32            right.push(Span::raw(" "));
33        }
34        right.push(Span::styled(format!(" {} ", APP_NAME), LABEL_STYLE));
35        let footer_right = Line::from(right).right_aligned();
36
37        let footer_cols = layouts::footer_columns(area);
38        Paragraph::new(footer_left)
39            .style(FOOTER_STYLE)
40            .render(footer_cols[0], buf);
41        Paragraph::new(footer_right)
42            .style(FOOTER_STYLE)
43            .render(footer_cols[1], buf);
44    }
45}