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

dnetview/ View: only render sessions if they are not empty

lunar-mining 4 лет назад
Родитель
Сommit
c6189e3b0f
2 измененных файлов с 23 добавлено и 9 удалено
  1. 3 2
      bin/dnetview/src/main.rs
  2. 20 7
      bin/dnetview/src/view.rs

+ 3 - 2
bin/dnetview/src/main.rs

@@ -303,6 +303,7 @@ async fn parse_manual(_manual: &Value, node_id: String) -> Result<SessionInfo> {
         ConnectInfo::new(connect_id, addr, is_empty, msg, status, state, msg_log, parent);
         ConnectInfo::new(connect_id, addr, is_empty, msg, status, state, msg_log, parent);
     connects.push(connect_info.clone());
     connects.push(connect_info.clone());
     let is_empty = is_empty_session(connects.clone());
     let is_empty = is_empty_session(connects.clone());
+    //let is_empty = false;
     let session_info =
     let session_info =
         SessionInfo::new(session_name, session_id, node_id, connects.clone(), is_empty);
         SessionInfo::new(session_name, session_id, node_id, connects.clone(), is_empty);
 
 
@@ -414,12 +415,12 @@ async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> Re
                     return Ok(())
                     return Ok(())
                 }
                 }
                 Key::Char('j') => {
                 Key::Char('j') => {
-                    view.active_ids.next();
+                    view.all_ids.next();
                     //view.info_list.next();
                     //view.info_list.next();
                     //debug!("ID LIST STATE {:?}", view.all_ids.state);
                     //debug!("ID LIST STATE {:?}", view.all_ids.state);
                 }
                 }
                 Key::Char('k') => {
                 Key::Char('k') => {
-                    view.active_ids.previous();
+                    view.all_ids.previous();
                     //view.info_list.previous();
                     //view.info_list.previous();
                     //debug!("ID LIST STATE {:?}", view.id_list.state);
                     //debug!("ID LIST STATE {:?}", view.id_list.state);
                 }
                 }

+ 20 - 7
bin/dnetview/src/view.rs

@@ -78,20 +78,25 @@ impl View {
         let list_cnstrnts = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
         let list_cnstrnts = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
 
 
         for info in self.info_list.infos.values() {
         for info in self.info_list.infos.values() {
+            self.active_ids.ids.insert(info.node_name.to_string());
             let name_span = Span::raw(&info.node_name);
             let name_span = Span::raw(&info.node_name);
             let lines = vec![Spans::from(name_span)];
             let lines = vec![Spans::from(name_span)];
             let names = ListItem::new(lines);
             let names = ListItem::new(lines);
             nodes.push(names);
             nodes.push(names);
             for child in &info.children {
             for child in &info.children {
-                let name = Span::styled(format!("    {}", child.session_name), style);
-                let lines = vec![Spans::from(name)];
-                let names = ListItem::new(lines);
-                nodes.push(names);
-                for child in &child.children {
-                    let name = Span::styled(format!("        {}", child.addr), style);
+                if !child.is_empty == true {
+                    self.active_ids.ids.insert(child.session_name.to_string());
+                    let name = Span::styled(format!("    {}", child.session_name), style);
                     let lines = vec![Spans::from(name)];
                     let lines = vec![Spans::from(name)];
                     let names = ListItem::new(lines);
                     let names = ListItem::new(lines);
                     nodes.push(names);
                     nodes.push(names);
+                    for child in &child.children {
+                        self.active_ids.ids.insert(child.addr.to_string());
+                        let name = Span::styled(format!("        {}", child.addr), style);
+                        let lines = vec![Spans::from(name)];
+                        let names = ListItem::new(lines);
+                        nodes.push(names);
+                    }
                 }
                 }
             }
             }
         }
         }
@@ -102,10 +107,18 @@ impl View {
             .constraints(list_cnstrnts)
             .constraints(list_cnstrnts)
             .split(f.size());
             .split(f.size());
 
 
+        debug!("DISPLAY NODES LEN: {}", nodes.len());
+        debug!("ACTIVE IDS LEN: {}", self.active_ids.ids.len());
+        debug!("ALL IDS LEN: {}", self.all_ids.ids.len());
+
+        debug!("DISPLAY NODES {:?}", nodes);
+        debug!("ACTIVE IDS {:?}", self.active_ids.ids);
+        debug!("ALL IDS {:?}", self.all_ids.ids);
+
         let nodes =
         let nodes =
             List::new(nodes).block(Block::default().borders(Borders::ALL)).highlight_symbol(">> ");
             List::new(nodes).block(Block::default().borders(Borders::ALL)).highlight_symbol(">> ");
 
 
-        f.render_stateful_widget(nodes, slice[0], &mut self.active_ids.state);
+        f.render_stateful_widget(nodes, slice[0], &mut self.all_ids.state);
     }
     }
 }
 }