From 6165a9fb96cd3a86309de5db422237249d321b26 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Fri, 18 Mar 2022 18:43:07 +0100 Subject: [PATCH] bug fix: stop rendering outbound recursively move outbound outside loop --- bin/dnetview/src/main.rs | 6 ++--- bin/dnetview/src/ui.rs | 57 +++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index 6d0ae5649..22dc27740 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -225,11 +225,11 @@ async fn poll(client: Map, model: Arc) -> Result<()> { ); slots.push(new_slot) } - let is_empty = is_empty_outbound(slots.clone()); - let oinfo = OutboundInfo::new(is_empty, slots.clone()); - oconnects.push(oinfo); } + let is_empty = is_empty_outbound(slots.clone()); + let oinfo = OutboundInfo::new(is_empty, slots.clone()); + oconnects.push(oinfo); let infos = NodeInfo { outbound: oconnects, manual: mconnects, inbound: iconnects }; let mut node_info = HashMap::new(); diff --git a/bin/dnetview/src/ui.rs b/bin/dnetview/src/ui.rs index 8a399dd4c..901c67ca7 100644 --- a/bin/dnetview/src/ui.rs +++ b/bin/dnetview/src/ui.rs @@ -33,14 +33,10 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { // // 2. Fix error whereby duplicates outbounds are being printed (nested loop) Some(node) => { - // create the title if !node.outbound.is_empty() { lines.push(Spans::from(Span::styled(" Outgoing", Style::default()))); data.push("Outgoing".to_string()); - } - for outbound in &node.outbound.clone() { - debug!("{:?}", outbound); - if outbound.is_empty == false { + for outbound in &node.outbound.clone() { for slot in outbound.slots.clone() { let addr = Span::styled(format!(" {}", slot.addr), style); data.push(format!("{}", slot.addr)); @@ -60,38 +56,39 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { } } } - // create the title if !node.inbound.is_empty() { lines.push(Spans::from(Span::styled(" Incoming", Style::default()))); data.push("Incoming".to_string()); - } - for inbound in &node.inbound { - if inbound.is_empty == false { - let addr = Span::styled(format!(" {}", inbound.connected), style); - data.push(format!("{}", inbound.connected)); - 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), - }; - data.push(format!("{}", inbound.channel.last_msg)); - lines.push(Spans::from(vec![addr, msg])); + for inbound in &node.inbound { + if inbound.is_empty == false { + let addr = Span::styled(format!(" {}", inbound.connected), style); + data.push(format!("{}", inbound.connected)); + 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), + }; + data.push(format!("{}", inbound.channel.last_msg)); + lines.push(Spans::from(vec![addr, msg])); + } } } - // create the title if !node.manual.is_empty() { lines.push(Spans::from(Span::styled(" Manual", Style::default()))); data.push("Manual".to_string()); - } - for connect in &node.manual { - lines.push(Spans::from(Span::styled(format!(" {}", connect.key), style))); - data.push(format!("{}", connect.key)); + for connect in &node.manual { + lines.push(Spans::from(Span::styled( + format!(" {}", connect.key), + style, + ))); + data.push(format!("{}", connect.key)); + } } } None => { @@ -100,7 +97,7 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { } } - debug!("{:?}", data); + //debug!("{:?}", data); let ids = ListItem::new(lines); nodes.push(ids); }