Fix
This commit is contained in:
parent
f2296ec82d
commit
01395ec920
3 changed files with 15 additions and 87 deletions
|
|
@ -1,6 +1,5 @@
|
|||
pub mod header;
|
||||
pub mod monitor_list;
|
||||
pub mod status_line;
|
||||
|
||||
pub use header::render_header;
|
||||
pub use monitor_list::render_monitor_list;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,14 @@ fn create_status_line_spans(status_history: &[MonitorStatus]) -> Vec<Span<'stati
|
|||
.take(STATUS_LINE_LENGTH)
|
||||
.collect();
|
||||
|
||||
spans.push(Span::styled(
|
||||
"(1h)",
|
||||
Style::default()
|
||||
.fg(Color::Gray)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
));
|
||||
spans.push(Span::raw(" "));
|
||||
|
||||
for status in recent_status.iter().rev() {
|
||||
let c = get_status_char(status);
|
||||
let color = get_status_color(status);
|
||||
|
|
@ -87,15 +95,13 @@ fn create_status_line_spans(status_history: &[MonitorStatus]) -> Vec<Span<'stati
|
|||
spans.push(Span::styled(c.to_string(), Style::default().fg(color)));
|
||||
}
|
||||
|
||||
if !spans.is_empty() {
|
||||
spans.push(Span::raw(" "));
|
||||
spans.push(Span::styled(
|
||||
"(24)",
|
||||
t("now"),
|
||||
Style::default()
|
||||
.fg(Color::Gray)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
));
|
||||
}
|
||||
|
||||
spans
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::Color,
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
i18n::t,
|
||||
ui::dashboard::model::{MonitorStatus, MonitorViewState},
|
||||
};
|
||||
|
||||
const STATUS_LINE_LENGTH: usize = 100;
|
||||
|
||||
pub fn render_status_line(frame: &mut Frame, area: Rect, monitor: &MonitorViewState) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([Constraint::Length(1), Constraint::Length(1)])
|
||||
.split(area);
|
||||
|
||||
let status_line = create_status_line(&monitor.status_history);
|
||||
let status_line_widget =
|
||||
Paragraph::new(status_line).block(Block::default().borders(Borders::NONE));
|
||||
|
||||
frame.render_widget(status_line_widget, chunks[0]);
|
||||
|
||||
let time_markers = Paragraph::new("1h".to_string())
|
||||
.alignment(Alignment::Left)
|
||||
.block(Block::default().borders(Borders::NONE));
|
||||
|
||||
frame.render_widget(time_markers, chunks[1]);
|
||||
|
||||
let now_markers = Paragraph::new(t("now"))
|
||||
.alignment(Alignment::Right)
|
||||
.block(Block::default().borders(Borders::NONE));
|
||||
|
||||
frame.render_widget(now_markers, chunks[1]);
|
||||
}
|
||||
|
||||
fn create_status_line(status_history: &[MonitorStatus]) -> String {
|
||||
let mut line = String::with_capacity(STATUS_LINE_LENGTH);
|
||||
|
||||
let points = status_history
|
||||
.iter()
|
||||
.take(STATUS_LINE_LENGTH)
|
||||
.chain(
|
||||
std::iter::repeat(&MonitorStatus::Unknown)
|
||||
.take(STATUS_LINE_LENGTH - status_history.len()),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for status in points {
|
||||
match status {
|
||||
MonitorStatus::Down => line.push_str("░"),
|
||||
MonitorStatus::Up => line.push_str("█"),
|
||||
MonitorStatus::Unknown => line.push_str(" "),
|
||||
}
|
||||
}
|
||||
line
|
||||
}
|
||||
|
||||
pub fn get_status_emoji(status: &MonitorStatus) -> &str {
|
||||
match status {
|
||||
MonitorStatus::Up => "✅",
|
||||
MonitorStatus::Down => "❌",
|
||||
MonitorStatus::Unknown => "❓",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_status_color(status: &MonitorStatus) -> Color {
|
||||
match status {
|
||||
MonitorStatus::Up => Color::Green,
|
||||
MonitorStatus::Down => Color::Red,
|
||||
MonitorStatus::Unknown => Color::Yellow,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue