From 566bdf55ea8a400bdd7ecb48a49181d28c06ba9f Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Sat, 16 Apr 2022 10:47:47 +0200 Subject: [PATCH] dnetview: replace Vec with NodeInfo on model and view this commit fixes ui::ui(). it's a temporary measure until we finish the refactor. --- bin/dnetview/src/main.rs | 4 +- bin/dnetview/src/model.rs | 3 +- bin/dnetview/src/ui.rs | 84 +++++++++++++++++++-------------------- bin/dnetview/src/view.rs | 8 ++-- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index 9a0402f46..b4069fa52 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -258,10 +258,10 @@ async fn poll(client: DNetView, model: Arc) -> Result<()> { node_info.insert(&node_name, infos.clone()); // insert into model - for (key, _value) in node_info.clone() { + for (key, value) in node_info.clone() { model.id_list.node_id.lock().await.insert(key.to_string().clone()); // value - model.info_list.infos.lock().await.insert(key.to_string(), model_vec.clone()); + model.info_list.infos.lock().await.insert(key.to_string(), value); } } else { // TODO: error handling diff --git a/bin/dnetview/src/model.rs b/bin/dnetview/src/model.rs index e7513ef84..9f3d38e79 100644 --- a/bin/dnetview/src/model.rs +++ b/bin/dnetview/src/model.rs @@ -4,7 +4,6 @@ use fxhash::{FxHashMap, FxHashSet}; use serde::Deserialize; use tui::widgets::ListState; -#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum SelectableObject { // top level selectable object Node(NodeInfo), @@ -39,7 +38,7 @@ impl IdList { pub struct InfoList { pub index: Mutex, - pub infos: Mutex>>, + pub infos: Mutex>, } impl InfoList { diff --git a/bin/dnetview/src/ui.rs b/bin/dnetview/src/ui.rs index 6942e4f86..eed270ccf 100644 --- a/bin/dnetview/src/ui.rs +++ b/bin/dnetview/src/ui.rs @@ -27,48 +27,48 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { // render as a sub node match &view.info_list.infos.get(id) { Some(node) => { - //if !node.[0].outbound.iter().all(|node| node.is_empty) { - // lines.push(Spans::from(Span::styled(" Outgoing", Style::default()))); - //} - //for outbound in &node.outbound.clone() { - // for slot in outbound.slots.clone() { - // let addr = Span::styled(format!(" {}", slot.addr), style); - // let msg: Span = match slot.channel.last_status.as_str() { - // "recv" => Span::styled( - // format!(" [R: {}]", slot.channel.last_msg), - // style, - // ), - // "sent" => Span::styled( - // format!(" [S: {}]", slot.channel.last_msg), - // style, - // ), - // a => Span::styled(a.to_string(), style), - // }; - // lines.push(Spans::from(vec![addr, msg])); - // } - //} - //if !node.inbound.iter().all(|node| node.is_empty) { - // lines.push(Spans::from(Span::styled(" Incoming", Style::default()))); - //} - //for inbound in &node.inbound { - // let addr = Span::styled(format!(" {}", inbound.connected), style); - // let msg: Span = match inbound.channel.last_status.as_str() { - // "recv" => Span::styled( - // format!(" [R: {}]", inbound.channel.last_msg), - // style, - // ), - // "sent" => Span::styled( - // format!(" [R: {}]", inbound.channel.last_msg), - // style, - // ), - // a => Span::styled(a.to_string(), style), - // }; - // lines.push(Spans::from(vec![addr, msg])); - //} - //lines.push(Spans::from(Span::styled(" Manual", Style::default()))); - //for connect in &node.manual { - // lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style))); - //} + if !node.outbound.iter().all(|node| node.is_empty) { + lines.push(Spans::from(Span::styled(" Outgoing", Style::default()))); + } + for outbound in &node.outbound.clone() { + for slot in outbound.slots.clone() { + let addr = Span::styled(format!(" {}", slot.addr), style); + let msg: Span = match slot.channel.last_status.as_str() { + "recv" => Span::styled( + format!(" [R: {}]", slot.channel.last_msg), + style, + ), + "sent" => Span::styled( + format!(" [S: {}]", slot.channel.last_msg), + style, + ), + a => Span::styled(a.to_string(), style), + }; + lines.push(Spans::from(vec![addr, msg])); + } + } + if !node.inbound.iter().all(|node| node.is_empty) { + lines.push(Spans::from(Span::styled(" Incoming", Style::default()))); + } + for inbound in &node.inbound { + let addr = Span::styled(format!(" {}", inbound.connected), style); + let msg: Span = match inbound.channel.last_status.as_str() { + "recv" => Span::styled( + format!(" [R: {}]", inbound.channel.last_msg), + style, + ), + "sent" => Span::styled( + format!(" [R: {}]", inbound.channel.last_msg), + style, + ), + a => Span::styled(a.to_string(), style), + }; + lines.push(Spans::from(vec![addr, msg])); + } + lines.push(Spans::from(Span::styled(" Manual", Style::default()))); + for connect in &node.manual { + lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style))); + } } None => { // TODO diff --git a/bin/dnetview/src/view.rs b/bin/dnetview/src/view.rs index a8df70b61..cfd84b7f6 100644 --- a/bin/dnetview/src/view.rs +++ b/bin/dnetview/src/view.rs @@ -2,7 +2,7 @@ use fxhash::{FxHashMap, FxHashSet}; //use log::debug; use tui::widgets::ListState; -use crate::model::{NodeInfo, SelectableObject}; +use crate::model::NodeInfo; #[derive(Clone)] pub struct View { @@ -15,7 +15,7 @@ impl View { View { id_list, info_list } } - pub fn update(&mut self, infos: FxHashMap>) { + pub fn update(&mut self, infos: FxHashMap) { for (id, info) in infos { self.id_list.node_id.insert(id.clone()); self.info_list.infos.insert(id, info); @@ -69,11 +69,11 @@ impl IdListView { #[derive(Clone)] pub struct InfoListView { pub index: usize, - pub infos: FxHashMap>, + pub infos: FxHashMap, } impl InfoListView { - pub fn new(infos: FxHashMap>) -> InfoListView { + pub fn new(infos: FxHashMap) -> InfoListView { let index = 0; InfoListView { index, infos }