Преглед изворни кода

map: increment index on next()

lunar-mining пре 4 година
родитељ
комит
616f7a71e4
3 измењених фајлова са 13 додато и 10 уклоњено
  1. 1 2
      bin/map/src/app.rs
  2. 8 4
      bin/map/src/list.rs
  3. 4 4
      bin/map/src/ui.rs

+ 1 - 2
bin/map/src/app.rs

@@ -10,7 +10,6 @@ use std::collections::HashMap;
 #[derive(Clone)]
 pub struct App {
     pub node_list: StatefulList,
-    pub show_popup: bool,
 }
 
 impl App {
@@ -26,7 +25,7 @@ impl App {
                 hashmap.insert(id.to_string(), info.to_string());
             }
         }
-        App { node_list: StatefulList::new(hashmap), show_popup: false }
+        App { node_list: StatefulList::new(hashmap) }
     }
 
     fn get_node_id() -> Vec<String> {

+ 8 - 4
bin/map/src/list.rs

@@ -11,7 +11,12 @@ pub struct NodeExtra {
 impl NodeExtra {
     pub fn new() -> NodeExtra {
         let mut index = 0;
-        NodeExtra { index, noise: String::new() }
+        let noise = Self::make_noise();
+        NodeExtra { index, noise }
+    }
+
+    pub fn make_noise() -> String {
+        String::new("USEFUL NODE INFO")
     }
 }
 #[derive(Clone)]
@@ -29,16 +34,14 @@ impl StatefulList {
     pub fn next(&mut self) {
         let index = self.nodex.index;
 
-        // index
         let i = match self.state.selected() {
             Some(i) => {
                 if i >= self.nodes.len() - 1 {
-                    //index = 0;
                     0
                 } else {
-                    //index + 1;
                     i + 1
                 }
+                index == i;
             }
             None => 0,
         };
@@ -53,6 +56,7 @@ impl StatefulList {
                 } else {
                     i - 1
                 }
+                index == i;
             }
             None => 0,
         };

+ 4 - 4
bin/map/src/ui.rs

@@ -39,8 +39,7 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
 
     let nodes = List::new(nodes)
         .block(Block::default())
-        .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD));
-    //.highlight_symbol(">> ");
+        .highlight_style(Style::default().bg(Color::Red).add_modifier(Modifier::BOLD));
 
     f.render_stateful_widget(nodes, slice[0], &mut app.node_list.state);
 
@@ -49,6 +48,9 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
         info_vec.push(Spans::from(val.to_string()))
     }
 
+    let graph = Paragraph::new(info_vec).block(Block::default()).style(Style::default());
+
+    //let 
     //let info: Vec<ListItem> = app
     //    .node_list
     //    .nodes
@@ -60,8 +62,6 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
     //    })
     //    .collect();
 
-    let graph = Paragraph::new(info_vec).block(Block::default()).style(Style::default());
-
     //let info = List::new(info)
     //    .block(Block::default())
     //    .highlight_style(Style::default().bg(Color::Black).add_modifier(Modifier::BOLD))