use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::Paragraph,
Frame,
};
use crate::tui::app::App;
pub fn draw(frame: &mut Frame, app: &App, area: Rect) {
let mut spans = Vec::new();
let (status_symbol, status_color) = if app.watch_state.is_running() {
("◐", Color::Yellow)
} else if app.watch_state.is_clean() {
("✓", Color::Green)
} else if app.watch_state.error_count() > 0 {
("✗", Color::Red)
} else {
("!", Color::Yellow)
};
spans.push(Span::styled(
format!(" {} ", status_symbol),
Style::default()
.fg(status_color)
.add_modifier(Modifier::BOLD),
));
let status_msg = app
.status_message
.as_deref()
.unwrap_or(app.watch_state.status_message());
spans.push(Span::styled(
format!("{} ", status_msg),
Style::default().fg(Color::White),
));
spans.push(Span::styled("│", Style::default().fg(Color::DarkGray)));
let error_count = app.watch_state.error_count();
let warning_count = app.watch_state.warning_count();
let info_count = app.watch_state.info_count();
spans.push(Span::styled(
format!(" E:{}", error_count),
Style::default().fg(if error_count > 0 {
Color::Red
} else {
Color::DarkGray
}),
));
spans.push(Span::styled(
format!(" W:{}", warning_count),
Style::default().fg(if warning_count > 0 {
Color::Yellow
} else {
Color::DarkGray
}),
));
spans.push(Span::styled(
format!(" I:{} ", info_count),
Style::default().fg(if info_count > 0 {
Color::Cyan
} else {
Color::DarkGray
}),
));
spans.push(Span::styled("│", Style::default().fg(Color::DarkGray)));
let runs = app.watch_state.total_runs();
spans.push(Span::styled(
format!(" Runs: {} ", runs),
Style::default().fg(Color::DarkGray),
));
spans.push(Span::styled("│", Style::default().fg(Color::DarkGray)));
spans.push(Span::styled(
" q:Quit r:Rerun ?:Help ",
Style::default().fg(Color::DarkGray),
));
let status =
Paragraph::new(Line::from(spans)).style(Style::default().bg(Color::Rgb(30, 30, 30)));
frame.render_widget(status, area);
}
#[cfg(test)]
mod tests {
}