Skip to main content

iris_reader/ui/
status.rs

1use ratatui::text::{Line, Span};
2
3use crate::theme::Theme;
4
5pub struct Status<'a> {
6    pub name: &'a str,
7    pub kind: &'a str,
8    pub current_line: usize,
9    pub total_lines: usize,
10    pub percent: usize,
11    pub wrap: bool,
12    pub search: Option<(usize, usize)>,
13}
14
15pub fn render(status: Status<'_>, theme: &Theme) -> Line<'static> {
16    let mut spans = vec![
17        Span::styled(format!(" {} ", status.name), theme.status_accent),
18        Span::styled(format!(" {} ", status.kind), theme.status),
19        Span::styled(format!(" {:>3}% ", status.percent.min(100)), theme.status),
20        Span::styled(
21            format!(
22                " Ln {}/{} ",
23                status.current_line.min(status.total_lines.max(1)),
24                status.total_lines.max(1)
25            ),
26            theme.status,
27        ),
28        Span::styled(
29            if status.wrap {
30                " Wrap:on "
31            } else {
32                " Wrap:off "
33            },
34            theme.status,
35        ),
36    ];
37
38    if let Some((current, total)) = status.search {
39        spans.push(Span::styled(
40            format!(" {current}/{total} matches "),
41            theme.status_accent,
42        ));
43        spans.push(Span::styled(" n/N next/prev ", theme.status));
44    }
45    spans.push(Span::styled(" ? Help ", theme.status_accent));
46    Line::from(spans)
47}