added active and total node count to cli status bar

(also added tunnel count scaffolding)
note the tunnel count introduces a warning. no bueno.
This commit is contained in:
Vincent van Haaff 2024-11-10 03:41:44 -08:00
parent fd53ef5509
commit 41a2872ee5
5 changed files with 50 additions and 3 deletions

View File

@ -72,6 +72,7 @@ struct UIState {
network_down_up: Dirty<(f32, f32)>,
connection_state: Dirty<ConnectionState>,
peers_state: Dirty<Vec<json::JsonValue>>,
tunnels_state: Dirty<Vec<json::JsonValue>>, // V: or whatever the tunnel type would be
node_id: Dirty<String>,
}
@ -85,6 +86,7 @@ impl UIState {
network_down_up: Dirty::new((0.0, 0.0)),
connection_state: Dirty::new(ConnectionState::Disconnected),
peers_state: Dirty::new(Vec::new()),
tunnels_state: Dirty::new(Vec::new()),
node_id: Dirty::new("".to_owned()),
}
}
@ -938,11 +940,41 @@ impl CursiveUI {
ColorStyle::highlight_inactive(),
);
status.append_styled("|", ColorStyle::highlight_inactive());
// Add tunnel status
status.append_styled(" No Tunnels ", ColorStyle::highlight_inactive());
// Check for tunnels first, fallback to node count if none
let tunnel_count = inner.ui_state.tunnels_state.get().len();
if tunnel_count > 0 {
status.append_styled(
format!(" {} Tunnels ", tunnel_count),
ColorStyle::highlight_inactive(),
);
} else {
status.append_styled(" No Tunnels ", ColorStyle::highlight_inactive());
}
status.append_styled("|", ColorStyle::highlight_inactive());
// Add connected vs total nodes count
let connected_nodes = inner.ui_state.peers_state.get().len();
let total_nodes = inner.ui_state.peers_state.get().iter()
.map(|peer| peer["node_ids"].len())
.sum::<usize>();
status.append_styled(
format!(" {} Connected ({} Nodes Found) ", connected_nodes, total_nodes),
ColorStyle::highlight_inactive(),
);
let tunnel_count = inner.ui_state.tunnels_state.get().len();
if tunnel_count > 0 {
status.append_styled(
format!(" {} Tunnels ", tunnel_count),
ColorStyle::highlight_inactive(),
);
} else {
let peer_count = inner.ui_state.peers_state.get().len();
status.append_styled(
format!(" {} Nodes ", peer_count),
ColorStyle::highlight_inactive(),
);
}
status.append_styled("|", ColorStyle::highlight_inactive());
};
statusbar.set_content(status);
}
@ -1330,6 +1362,11 @@ impl UISender for CursiveUISender {
}
let _ = self.cb_sink.send(Box::new(CursiveUI::update_cb));
}
fn set_tunnel_status(&mut self, tunnels: Option<Vec<json::JsonValue>>) {
let mut inner = self.inner.lock();
inner.ui_state.tunnels_state.set(tunnels.unwrap_or_default());
let _ = self.cb_sink.send(Box::new(CursiveUI::update_cb));
}
fn set_config(&mut self, config: &json::JsonValue) {
let mut inner = self.inner.lock();

View File

@ -348,6 +348,9 @@ impl UISender for InteractiveUISender {
) {
//
}
fn set_tunnel_status(&mut self, _tunnels: Option<Vec<json::JsonValue>>) {
//
}
fn set_config(&mut self, _config: &json::JsonValue) {
//
}

View File

@ -248,6 +248,9 @@ impl<R: AsyncRead + Unpin + Send + 'static, W: AsyncWrite + Unpin + Send + 'stat
) {
//
}
fn set_tunnel_status(&mut self, _tunnels: Option<Vec<json::JsonValue>>) {
//
}
fn set_config(&mut self, _config: &json::JsonValue) {
//
}

View File

@ -237,6 +237,9 @@ impl UISender for LogViewerUISender {
) {
//
}
fn set_tunnel_status(&mut self, _tunnels: Option<Vec<json::JsonValue>>) {
//
}
fn set_config(&mut self, _config: &json::JsonValue) {
//
}

View File

@ -34,6 +34,7 @@ pub trait UISender: Send {
bps_up: u64,
peers: Vec<json::JsonValue>,
);
fn set_tunnel_status(&mut self, tunnels: Option<Vec<json::JsonValue>>);
fn set_config(&mut self, config: &json::JsonValue);
fn set_connection_state(&mut self, state: ConnectionState);
fn add_node_event(&self, log_color: Level, event: &str);