From 7895493c846b3ed3770c2ced0edeab42a4865b56 Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Fri, 18 Mar 2022 09:11:06 +0100 Subject: [PATCH] ui: don't render Incoming sessions if they are empty --- bin/dnetview/src/ui.rs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/bin/dnetview/src/ui.rs b/bin/dnetview/src/ui.rs index c0e89edd3..8fd40d163 100644 --- a/bin/dnetview/src/ui.rs +++ b/bin/dnetview/src/ui.rs @@ -16,6 +16,8 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { let list_cnstrnts = vec![Constraint::Percentage(50), Constraint::Percentage(50)]; let mut nodes = Vec::new(); + // we write all the span data to a Vec for debugging purposes + //let mut data = Vec::new(); let style = Style::default(); for id in &view.id_list.node_id { @@ -25,8 +27,10 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { Some(node) => { for outbound in &node.outbound.clone() { lines.push(Spans::from(Span::styled(" Outgoing", style))); + //data.push("Outgoing"); for slot in outbound.slots.clone() { let addr = Span::styled(format!(" {}", slot.addr), style); + data.push(format!("{}", slot.addr)); if slot.channel.last_status.as_str() != "Null" { let msg: Span = match slot.channel.last_status.as_str() { "recv" => Span::styled( @@ -47,23 +51,25 @@ pub fn ui(f: &mut Frame<'_, B>, mut view: View) { } } for connect in &node.inbound { - lines.push(Spans::from(Span::styled(" Incoming", Style::default()))); - let addr = Span::styled(format!(" {}", connect.connected), style); - if connect.channel.last_status.as_str() != "Null" { - let msg: Span = match connect.channel.last_status.as_str() { - "recv" => Span::styled( - format!(" [R: {}]", connect.channel.last_msg), - style, - ), - "sent" => Span::styled( - format!(" [R: {}]", connect.channel.last_msg), - style, - ), - a => Span::styled(a.to_string(), style), - }; - lines.push(Spans::from(vec![addr, msg])); - } else { - lines.push(Spans::from(addr)); + if connect.connected != "Empty" { + lines.push(Spans::from(Span::styled(" Incoming", Style::default()))); + let addr = Span::styled(format!(" {}", connect.connected), style); + if connect.channel.last_status.as_str() != "Null" { + let msg: Span = match connect.channel.last_status.as_str() { + "recv" => Span::styled( + format!(" [R: {}]", connect.channel.last_msg), + style, + ), + "sent" => Span::styled( + format!(" [R: {}]", connect.channel.last_msg), + style, + ), + a => Span::styled(a.to_string(), style), + }; + lines.push(Spans::from(vec![addr, msg])); + } else { + lines.push(Spans::from(addr)); + } } } for connect in &node.manual {