Skip to main content

mxr_tui/ui/
status_bar.rs

1use ratatui::prelude::*;
2use ratatui::widgets::*;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct StatusBarState {
6    pub mailbox_name: String,
7    pub total_count: usize,
8    pub unread_count: usize,
9    pub starred_count: usize,
10    pub sync_status: Option<String>,
11    pub status_message: Option<String>,
12    pub pending_mutation_count: usize,
13    pub pending_mutation_status: Option<String>,
14}
15
16pub fn draw(frame: &mut Frame, area: Rect, state: &StatusBarState, theme: &crate::theme::Theme) {
17    let sync_part = state.sync_status.as_deref().unwrap_or("not synced");
18
19    let status = if state
20        .status_message
21        .as_deref()
22        .is_some_and(|message| message.starts_with("Error:"))
23    {
24        state.status_message.clone().unwrap_or_default()
25    } else if state.pending_mutation_count > 0 {
26        let message = state
27            .pending_mutation_status
28            .as_deref()
29            .or(state.status_message.as_deref())
30            .unwrap_or("Working...");
31        format!("[pending:{}] {}", state.pending_mutation_count, message)
32    } else if let Some(msg) = state.status_message.as_deref() {
33        msg.to_string()
34    } else {
35        format!(
36            "={} [Msgs:{} New:{} Starred:{}]= {}",
37            state.mailbox_name,
38            state.total_count,
39            state.unread_count,
40            state.starred_count,
41            sync_part
42        )
43    };
44
45    let bar = Paragraph::new(status).style(
46        Style::default()
47            .bg(theme.hint_bar_bg)
48            .fg(theme.text_primary),
49    );
50
51    frame.render_widget(bar, area);
52}
53
54/// Format a sync status string for display.
55pub fn format_sync_status(unread: usize, sync_status: Option<&str>) -> String {
56    let sync_part = sync_status.unwrap_or("not synced");
57    format!("[INBOX] {} unread | {}", unread, sync_part)
58}