Upgrading footer
This commit is contained in:
parent
63496cfc93
commit
f4dca93598
5 changed files with 47 additions and 22 deletions
|
|
@ -25,3 +25,4 @@ uptime = Uptime
|
||||||
history = History
|
history = History
|
||||||
auto-update-enabled = Auto-update enabled ({interval} min)
|
auto-update-enabled = Auto-update enabled ({interval} min)
|
||||||
update-failed = Update failed: {error}
|
update-failed = Update failed: {error}
|
||||||
|
key-to-exit = Press 'q' to exit
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,4 @@ now = Agora
|
||||||
history = Historico
|
history = Historico
|
||||||
auto-update-enabled = Auto-atualização ativada ({interval} min)
|
auto-update-enabled = Auto-atualização ativada ({interval} min)
|
||||||
update-failed = Falha na atualização: {error}
|
update-failed = Falha na atualização: {error}
|
||||||
|
key-to-exit = Pressione 'q' para sair
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@ use crate::api::{UptimeKumaClient, UptimeKumaEndpoints};
|
||||||
use crate::core;
|
use crate::core;
|
||||||
use crate::data::{heartbeat::HeartbeatResponse, status_page::model::StatusPageResponse};
|
use crate::data::{heartbeat::HeartbeatResponse, status_page::model::StatusPageResponse};
|
||||||
use crate::i18n::{t, t_with_args};
|
use crate::i18n::{t, t_with_args};
|
||||||
use crate::ui::components::render_footer;
|
|
||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
components::{render_header, render_monitor_list},
|
components::{render_footer, render_header, render_monitor_list},
|
||||||
dashboard::model::DashboardViewState,
|
dashboard::model::DashboardViewState,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
@ -23,10 +22,10 @@ use ratatui::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
|
||||||
thread,
|
|
||||||
sync::mpsc,
|
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
io,
|
||||||
|
sync::mpsc,
|
||||||
|
thread,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -138,12 +137,21 @@ impl App {
|
||||||
} else {
|
} else {
|
||||||
render_monitor_list(frame, chunks[1], &self.state);
|
render_monitor_list(frame, chunks[1], &self.state);
|
||||||
}
|
}
|
||||||
render_footer(frame, chunks[2]);
|
|
||||||
|
let seconds_until_update = self
|
||||||
|
.update_interval
|
||||||
|
.checked_sub(self.last_update.elapsed())
|
||||||
|
.map(|d| d.as_secs() as u64)
|
||||||
|
.unwrap_or(30);
|
||||||
|
|
||||||
|
render_footer(frame, chunks[2], seconds_until_update);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_events(&mut self) -> io::Result<()> {
|
fn handle_events(&mut self) -> io::Result<()> {
|
||||||
if event::poll(Duration::from_millis(50))? {
|
let timeout = Duration::from_secs(1);
|
||||||
|
|
||||||
|
if event::poll(timeout)? {
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
if key.kind == KeyEventKind::Release {
|
if key.kind == KeyEventKind::Release {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,43 @@ use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
layout::{Alignment, Rect},
|
layout::{Alignment, Rect},
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
text::Span,
|
text::{Line, Span},
|
||||||
widgets::{Block, Borders, Paragraph},
|
widgets::{Block, Borders, Paragraph},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::i18n::t;
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
|
|
||||||
pub fn render_footer(frame: &mut Frame, area: Rect) {
|
pub fn render_footer(frame: &mut Frame, area: Rect, seconds_until_update: u64) {
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
let datatime_str = now.format("%Y-%m-%d %H:%M:%S").to_string();
|
let datatime_str = now.format("%Y-%m-%d %H:%M:%S").to_string();
|
||||||
|
let countdown_str = format!("↻ {}s", seconds_until_update);
|
||||||
|
|
||||||
let footer = Paragraph::new(Span::styled(
|
let text = Line::from(vec![
|
||||||
datatime_str,
|
Span::styled(
|
||||||
Style::default()
|
datatime_str,
|
||||||
.fg(Color::Gray)
|
Style::default()
|
||||||
.add_modifier(Modifier::BOLD),
|
.fg(Color::Gray)
|
||||||
))
|
.add_modifier(Modifier::BOLD),
|
||||||
.block(
|
),
|
||||||
Block::default()
|
Span::raw(" | "),
|
||||||
.borders(Borders::ALL)
|
Span::styled(
|
||||||
.border_style(Style::default().fg(Color::Blue)),
|
countdown_str,
|
||||||
)
|
Style::default()
|
||||||
.alignment(Alignment::Center);
|
.fg(Color::Yellow)
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
),
|
||||||
|
Span::raw(" | "),
|
||||||
|
Span::styled(t("key-to-exit"), Style::default().fg(Color::Gray)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let footer = Paragraph::new(text)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(Style::default().fg(Color::Blue)),
|
||||||
|
)
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
|
||||||
frame.render_widget(footer, area);
|
frame.render_widget(footer, area);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::ui::dashboard::model::DashboardViewState;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
layout::{Alignment, Rect},
|
layout::{Alignment, Rect},
|
||||||
style::{Color, Style, Stylize},
|
style::{Color, Style},
|
||||||
text::{Line, Span},
|
text::{Line, Span},
|
||||||
widgets::{Block, Borders, Paragraph},
|
widgets::{Block, Borders, Paragraph},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue