feat(tui): header shows TLS/token status and polling intervals
This commit is contained in:
parent
9a35306340
commit
67ecf36883
@ -67,6 +67,9 @@ pub struct App {
|
|||||||
|
|
||||||
// For reconnects
|
// For reconnects
|
||||||
ws_url: String,
|
ws_url: String,
|
||||||
|
// Security / status flags
|
||||||
|
pub is_tls: bool,
|
||||||
|
pub has_token: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@ -97,6 +100,8 @@ impl App {
|
|||||||
disks_interval: Duration::from_secs(5),
|
disks_interval: Duration::from_secs(5),
|
||||||
metrics_interval: Duration::from_millis(500),
|
metrics_interval: Duration::from_millis(500),
|
||||||
ws_url: String::new(),
|
ws_url: String::new(),
|
||||||
|
is_tls: false,
|
||||||
|
has_token: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +115,12 @@ impl App {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_status(mut self, is_tls: bool, has_token: bool) -> Self {
|
||||||
|
self.is_tls = is_tls;
|
||||||
|
self.has_token = has_token;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
&mut self,
|
&mut self,
|
||||||
url: &str,
|
url: &str,
|
||||||
@ -363,7 +374,15 @@ impl App {
|
|||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
draw_header(f, rows[0], self.last_metrics.as_ref());
|
draw_header(
|
||||||
|
f,
|
||||||
|
rows[0],
|
||||||
|
self.last_metrics.as_ref(),
|
||||||
|
self.is_tls,
|
||||||
|
self.has_token,
|
||||||
|
self.metrics_interval,
|
||||||
|
self.procs_interval,
|
||||||
|
);
|
||||||
|
|
||||||
// Top row: left CPU avg, right Per-core (full top-right)
|
// Top row: left CPU avg, right Per-core (full top-right)
|
||||||
let top_lr = ratatui::layout::Layout::default()
|
let top_lr = ratatui::layout::Layout::default()
|
||||||
@ -485,6 +504,8 @@ impl Default for App {
|
|||||||
disks_interval: Duration::from_secs(5),
|
disks_interval: Duration::from_secs(5),
|
||||||
metrics_interval: Duration::from_millis(500),
|
metrics_interval: Duration::from_millis(500),
|
||||||
ws_url: String::new(),
|
ws_url: String::new(),
|
||||||
|
is_tls: false,
|
||||||
|
has_token: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -272,7 +272,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut app = App::new().with_intervals(metrics_interval_ms, processes_interval_ms);
|
let is_tls = url.starts_with("wss://");
|
||||||
|
let has_token = url.contains("token=");
|
||||||
|
let mut app = App::new()
|
||||||
|
.with_intervals(metrics_interval_ms, processes_interval_ms)
|
||||||
|
.with_status(is_tls, has_token);
|
||||||
if parsed.dry_run {
|
if parsed.dry_run {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,22 @@
|
|||||||
//! Top header with hostname and CPU temperature indicator.
|
//! Top header with hostname and CPU temperature indicator.
|
||||||
|
|
||||||
use crate::types::Metrics;
|
use crate::types::Metrics;
|
||||||
|
use std::time::Duration;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
widgets::{Block, Borders},
|
widgets::{Block, Borders},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn draw_header(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) {
|
pub fn draw_header(
|
||||||
let title = if let Some(mm) = m {
|
f: &mut ratatui::Frame<'_>,
|
||||||
|
area: Rect,
|
||||||
|
m: Option<&Metrics>,
|
||||||
|
is_tls: bool,
|
||||||
|
has_token: bool,
|
||||||
|
metrics_interval: Duration,
|
||||||
|
procs_interval: Duration,
|
||||||
|
) {
|
||||||
|
let base = if let Some(mm) = m {
|
||||||
let temp = mm
|
let temp = mm
|
||||||
.cpu_temp_c
|
.cpu_temp_c
|
||||||
.map(|t| {
|
.map(|t| {
|
||||||
@ -21,12 +30,19 @@ pub fn draw_header(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>)
|
|||||||
format!("CPU Temp: {t:.1}°C {icon}")
|
format!("CPU Temp: {t:.1}°C {icon}")
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| "CPU Temp: N/A".into());
|
.unwrap_or_else(|| "CPU Temp: N/A".into());
|
||||||
format!(
|
format!("socktop — host: {} | {}", mm.hostname, temp)
|
||||||
"socktop — host: {} | {} (press 'q' to quit)",
|
|
||||||
mm.hostname, temp
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
"socktop — connecting... (press 'q' to quit)".into()
|
"socktop — connecting...".into()
|
||||||
};
|
};
|
||||||
|
let tls_txt = if is_tls { "🔒TLS" } else { "🔓WS" };
|
||||||
|
let tok_txt = if has_token { "🔑token" } else { "" };
|
||||||
|
let mi = metrics_interval.as_millis();
|
||||||
|
let pi = procs_interval.as_millis();
|
||||||
|
let intervals = format!("⏱{mi}ms metrics | {pi}ms procs");
|
||||||
|
let mut parts = vec![base, tls_txt.into()];
|
||||||
|
if !tok_txt.is_empty() { parts.push(tok_txt.into()); }
|
||||||
|
parts.push(intervals);
|
||||||
|
parts.push("(q to quit)".into());
|
||||||
|
let title = parts.join(" | ");
|
||||||
f.render_widget(Block::default().title(title).borders(Borders::BOTTOM), area);
|
f.render_widget(Block::default().title(title).borders(Borders::BOTTOM), area);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user