feat: add error popup system, progress bar, and log overlay

This commit is contained in:
objz committed 2025-07-19 16:23:45 +02:00
1 parent 252fe8e44a
commit 96b6f4e0e9
4 files changed
+244 -24

No files matched your search

+74 -24
View File
@@ -1,14 +1,13 @@
use ratatui::{
layout::Rect,
style::{Color, Style},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
Frame,
};
use tracing::Level;
use crate::tui::layout::FocusedArea;
use crate::tui::logging::STATUS_EVENTS;
use crate::tui::progress::PROGRESS;
use super::styled_title;
@@ -25,27 +24,78 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(border_color));
let latest = STATUS_EVENTS
.lock()
.ok()
.and_then(|events| events.back().cloned());
let inner = block.inner(area);
frame.render_widget(block, area);
let content = match latest {
Some(event) => {
let (label, label_color) = match event.level {
Level::ERROR => (" ERROR ", Color::Red),
Level::WARN => (" WARN ", Color::Yellow),
_ => (" INFO ", Color::White),
};
Paragraph::new(Line::from(vec![
Span::styled(label, Style::default().fg(Color::White).bg(label_color)),
Span::raw(" "),
Span::raw(event.message),
]))
let state = match PROGRESS.lock() {
Ok(s) => s.clone(),
Err(_) => {
let idle = Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray)));
frame.render_widget(idle, inner);
return;
}
None => Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray))),
};
frame.render_widget(content.block(block), area);
if state.current_action.is_none() {
let idle = Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray)));
frame.render_widget(idle, inner);
return;
}
let action_text = state.current_action.as_deref().unwrap_or("");
let sub_text = state.sub_action.as_deref().unwrap_or("");
let has_progress = state.progress.is_some();
let constraints = if has_progress {
vec![
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
]
} else {
vec![Constraint::Length(1), Constraint::Length(1)]
};
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(constraints)
.split(inner);
let mut chunk_idx = 0;
if has_progress {
if let Some((current, total)) = state.progress {
let ratio = if total > 0 {
(current as f64 / total as f64).min(1.0)
} else {
0.0
};
let pct = (ratio * 100.0) as u16;
let gauge = Gauge::default()
.gauge_style(
Style::default()
.fg(Color::Green)
.bg(Color::DarkGray)
.add_modifier(Modifier::BOLD),
)
.percent(pct);
frame.render_widget(gauge, chunks[chunk_idx]);
chunk_idx += 1;
}
}
let action_line = Paragraph::new(Line::from(vec![Span::styled(
action_text,
Style::default().fg(Color::White),
)]));
frame.render_widget(action_line, chunks[chunk_idx]);
chunk_idx += 1;
if !sub_text.is_empty() && chunk_idx < chunks.len() {
let sub_line = Paragraph::new(Line::from(vec![Span::styled(
sub_text,
Style::default().fg(Color::DarkGray),
)]));
frame.render_widget(sub_line, chunks[chunk_idx]);
}
}