Przeglądaj źródła

dnetview/ View: update to new data structure

lunar-mining 4 lat temu
rodzic
commit
ef167d4d32
3 zmienionych plików z 12 dodań i 12 usunięć
  1. 1 1
      bin/dnetview/src/main.rs
  2. 1 1
      bin/dnetview/src/ui.rs
  3. 10 10
      bin/dnetview/src/view.rs

+ 1 - 1
bin/dnetview/src/main.rs

@@ -414,7 +414,7 @@ async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> Re
     view.info_list.index = 0;
 
     loop {
-        //view.update(model.info_list.infos.lock().await.clone());
+        view.update(model.infos.lock().await.clone());
         terminal.draw(|f| {
             ui::ui(f, view.clone());
         })?;

+ 1 - 1
bin/dnetview/src/ui.rs

@@ -20,7 +20,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
 
     // lines.push(sublist)
     // either have one hashmap w value as enum or have type info in hashset
-    for id in &view.id_list.node_id {
+    for id in &view.id_list.ids {
         let id_span = Span::raw(id.to_string());
         let mut lines = vec![Spans::from(id_span)];
 

+ 10 - 10
bin/dnetview/src/view.rs

@@ -2,7 +2,7 @@ use fxhash::{FxHashMap, FxHashSet};
 //use log::debug;
 use tui::widgets::ListState;
 
-use crate::model::NodeInfo;
+use crate::model::SelectableObject;
 
 #[derive(Clone)]
 pub struct View {
@@ -15,9 +15,9 @@ impl View {
         View { id_list, info_list }
     }
 
-    pub fn update(&mut self, infos: FxHashMap<String, NodeInfo>) {
+    pub fn update(&mut self, infos: FxHashMap<String, SelectableObject>) {
         for (id, info) in infos {
-            self.id_list.node_id.insert(id.clone());
+            self.id_list.ids.insert(id.clone());
             self.info_list.infos.insert(id, info);
         }
     }
@@ -26,17 +26,17 @@ impl View {
 #[derive(Clone)]
 pub struct IdListView {
     pub state: ListState,
-    pub node_id: FxHashSet<String>,
+    pub ids: FxHashSet<String>,
 }
 
 impl IdListView {
-    pub fn new(node_id: FxHashSet<String>) -> IdListView {
-        IdListView { state: ListState::default(), node_id }
+    pub fn new(ids: FxHashSet<String>) -> IdListView {
+        IdListView { state: ListState::default(), ids }
     }
     pub fn next(&mut self) {
         let i = match self.state.selected() {
             Some(i) => {
-                if i >= self.node_id.len() - 1 {
+                if i >= self.ids.len() - 1 {
                     0
                 } else {
                     i + 1
@@ -51,7 +51,7 @@ impl IdListView {
         let i = match self.state.selected() {
             Some(i) => {
                 if i == 0 {
-                    self.node_id.len() - 1
+                    self.ids.len() - 1
                 } else {
                     i - 1
                 }
@@ -69,11 +69,11 @@ impl IdListView {
 #[derive(Clone)]
 pub struct InfoListView {
     pub index: usize,
-    pub infos: FxHashMap<String, NodeInfo>,
+    pub infos: FxHashMap<String, SelectableObject>,
 }
 
 impl InfoListView {
-    pub fn new(infos: FxHashMap<String, NodeInfo>) -> InfoListView {
+    pub fn new(infos: FxHashMap<String, SelectableObject>) -> InfoListView {
         let index = 0;
 
         InfoListView { index, infos }