Native node: timestamp lokiin, node_id otsikkoon, yhdistetty-tila

This commit is contained in:
Jaakko Vanhala
2026-04-13 06:32:11 +03:00
parent 5b20ebe800
commit a3b95a56e8
3 changed files with 25 additions and 0 deletions

View File

@@ -23,3 +23,4 @@ dialoguer = "0.12.0"
ratatui = "0.29.0" ratatui = "0.29.0"
crossterm = { version = "0.28.1", features = ["event-stream"] } crossterm = { version = "0.28.1", features = ["event-stream"] }
tracing-appender = "0.2.4" tracing-appender = "0.2.4"
chrono = "0.4"

View File

@@ -401,6 +401,13 @@ async fn main() {
continue; continue;
} }
// Merkitään yhdistetyksi TUI:ssa
{
let mut st = tui_state.write().await;
st.status = "ACTIVE".to_string();
st.push_log("Network", "Yhdistetty hubiin".to_string(), None);
}
loop { loop {
tokio::select! { tokio::select! {
cmd = cmd_rx.recv() => { cmd = cmd_rx.recv() => {
@@ -497,6 +504,18 @@ async fn main() {
} }
} }
} }
// Node joined → oma node_id
if text.contains(r#""type":"node_joined""#) {
if let Ok(msg) = serde_json::from_str::<serde_json::Value>(&text) {
if let Some(nid) = msg.get("node_id").and_then(|v| v.as_u64()) {
let mut st = tui_state.write().await;
if st.node_id.is_none() {
st.node_id = Some(nid);
st.push_log("Network", format!("Node ID: #{}", nid), None);
}
}
}
}
// Verkon globaali tila // Verkon globaali tila
if text.contains(r#""type":"network_status""#) { if text.contains(r#""type":"network_status""#) {
if let Ok(status) = serde_json::from_str::<serde_json::Value>(&text) { if let Ok(status) = serde_json::from_str::<serde_json::Value>(&text) {

View File

@@ -21,6 +21,7 @@ pub struct LogEntry {
pub ty: String, pub ty: String,
pub msg: String, pub msg: String,
pub speed: Option<f64>, pub speed: Option<f64>,
pub timestamp: String,
} }
pub struct DashboardState { pub struct DashboardState {
@@ -62,7 +63,9 @@ impl DashboardState {
} }
pub fn push_log(&mut self, ty: &str, msg: String, speed: Option<f64>) { pub fn push_log(&mut self, ty: &str, msg: String, speed: Option<f64>) {
let now = chrono::Local::now().format("%H:%M:%S").to_string();
self.logs.push(LogEntry { self.logs.push(LogEntry {
timestamp: now,
ty: ty.to_string(), ty: ty.to_string(),
msg, msg,
speed, speed,
@@ -241,6 +244,8 @@ fn ui(f: &mut ratatui::Frame, st: &DashboardState) {
}; };
ratatui::text::Line::from(vec![ ratatui::text::Line::from(vec![
ratatui::text::Span::styled(&log.timestamp, Style::default().fg(Color::DarkGray)),
ratatui::text::Span::raw(" "),
ratatui::text::Span::styled(format!("{: <8}", log.ty), Style::default().fg(ty_color).add_modifier(Modifier::BOLD)), ratatui::text::Span::styled(format!("{: <8}", log.ty), Style::default().fg(ty_color).add_modifier(Modifier::BOLD)),
ratatui::text::Span::raw(" | "), ratatui::text::Span::raw(" | "),
ratatui::text::Span::styled(log.msg.clone(), Style::default().fg(Color::White)), ratatui::text::Span::styled(log.msg.clone(), Style::default().fg(Color::White)),