feat: integrate tui-logger, ratatui-textarea, throbber, tui-widget-list, tui-scrollview

This commit is contained in:
objz committed 2025-09-20 15:41:17 +02:00
1 parent c70d247a2b
commit 59ad22e6e8
10 files changed
+332 -270

No files matched your search

+59 -44
View File
@@ -1,17 +1,24 @@
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
text::Span,
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
use crate::tui::layout::FocusedArea;
use crate::tui::progress::PROGRESS;
use crate::tui::theme::THEME;
use super::styled_title;
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
pub fn render(
frame: &mut Frame,
area: Rect,
focused: FocusedArea,
throbber_state: &mut ThrobberState,
) {
let border_color = if focused == FocusedArea::Status {
Color::White
} else {
@@ -24,47 +31,36 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(border_color));
let inner = block.inner(area);
frame.render_widget(block, area);
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);
frame.render_widget(idle.block(block), area);
return;
}
};
if state.current_action.is_none() {
let idle = Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray)));
frame.render_widget(idle, inner);
frame.render_widget(idle.block(block), area);
return;
}
let inner = block.inner(area);
frame.render_widget(block, area);
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)]
};
match state.progress {
Some((current, total)) if total > 0 => {
let chunks = Layout::vertical([
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
])
.split(inner);
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 {
@@ -79,23 +75,42 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
.add_modifier(Modifier::BOLD),
)
.percent(pct);
frame.render_widget(gauge, chunks[chunk_idx]);
chunk_idx += 1;
frame.render_widget(gauge, chunks[0]);
frame.render_widget(
Paragraph::new(action_text).style(Style::default().fg(THEME.colors.foreground)),
chunks[1],
);
if !sub_text.is_empty() {
frame.render_widget(
Paragraph::new(sub_text)
.style(Style::default().fg(THEME.colors.border_unfocused)),
chunks[2],
);
}
}
_ => {
let chunks =
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).split(inner);
let throbber = Throbber::default()
.label(action_text)
.style(Style::default().fg(THEME.colors.foreground))
.throbber_style(
Style::default()
.fg(THEME.colors.border_focused)
.add_modifier(Modifier::BOLD),
);
frame.render_stateful_widget(throbber, chunks[0], throbber_state);
if !sub_text.is_empty() {
frame.render_widget(
Paragraph::new(sub_text)
.style(Style::default().fg(THEME.colors.border_unfocused)),
chunks[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]);
}
}