Просмотр исходного кода

bug fix: only render title if it's not empty

lunar-mining 4 лет назад
Родитель
Сommit
d773815e63
1 измененных файлов с 43 добавлено и 55 удалено
  1. 43 55
      bin/dnetview/src/ui.rs

+ 43 - 55
bin/dnetview/src/ui.rs

@@ -26,70 +26,59 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
         data.push(id.to_string());
 
         match &view.info_list.infos.get(id) {
-            // TODO:
-            //      1. Only print 'outbound' or 'inbound':
-            //              * if in/outbound is not empty
-            //              * only print it once
-            //
-            //      2. Fix error whereby duplicates outbounds are being printed (nested loop)
             Some(node) => {
-                if !node.outbound.is_empty() {
+                if !node.outbound.iter().all(|node| node.is_empty == true) {
                     lines.push(Spans::from(Span::styled("   Outgoing", Style::default())));
                     data.push("Outgoing".to_string());
-                    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));
-                            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),
-                            };
-                            data.push(format!("{}", slot.channel.last_msg));
-                            lines.push(Spans::from(vec![addr, msg]));
-                        }
+                }
+                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));
+                        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),
+                        };
+                        data.push(format!("{}", slot.channel.last_msg));
+                        lines.push(Spans::from(vec![addr, msg]));
                     }
                 }
-                if !node.inbound.is_empty() {
+                if !node.inbound.iter().all(|node| node.is_empty == true) {
                     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]));
-                        }
-                    }
                 }
-                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 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]));
                     }
                 }
+                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));
+                }
             }
             None => {
                 // TODO
@@ -97,7 +86,6 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
             }
         }
 
-        //debug!("{:?}", data);
         let ids = ListItem::new(lines);
         nodes.push(ids);
     }