From b382ae1417a30c4dc31a96295ae154d06da8fbdc Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Sun, 13 Feb 2022 11:36:38 +0100 Subject: [PATCH] map: interate index and add debug statements --- bin/map/src/main.rs | 22 ++++++++++++++++++++-- bin/map/src/model.rs | 2 +- bin/map/src/view.rs | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bin/map/src/main.rs b/bin/map/src/main.rs index 27dfdcb14..5c360df49 100644 --- a/bin/map/src/main.rs +++ b/bin/map/src/main.rs @@ -186,9 +186,19 @@ async fn poll(client: Map, model: Arc) -> Result<()> { ]; for node in infos { + // update the index + let mut index = model.info_list.index.lock().await; + *index += 1; + + // write nodes model.info_list.infos.lock().await.push(node.clone()); + // write node id model.id_list.node_id.lock().await.push(node.clone().id); } + + //println!("MODEL INFO LIST: {:?}", model.info_list.infos.lock().await); + //println!("MODEL INFO INDEX: {:?}", model.info_list.index.lock().await); + //println!("MODEL ID LIST: {:?}", model.id_list.node_id.lock().await); } else { // TODO: error handling println!("Reply is an error"); @@ -203,12 +213,15 @@ async fn render(terminal: &mut Terminal, model: Arc) -> io terminal.clear()?; + //println!("RENDER INFO LIST: {:?}", model.info_list.infos.lock().await); + //println!("RENDER INFO INDEX: {:?}", model.info_list.index.lock().await); + //println!("RENDER ID LIST: {:?}", model.id_list.node_id.lock().await); + let mut info_vec = Vec::new(); for info in model.info_list.infos.lock().await.clone() { info_vec.push(info) } - let mut id_vec = Vec::new(); for id in model.id_list.node_id.lock().await.clone() { @@ -226,6 +239,11 @@ async fn render(terminal: &mut Terminal, model: Arc) -> io view.info_list.index = 0; loop { + //println!("RENDER INFO LIST: {:?}", model.info_list.infos.lock().await); + //println!("RENDER INFO INDEX: {:?}", model.info_list.index.lock().await); + //println!("RENDER ID LIST: {:?}", model.id_list.node_id.lock().await); + + //async_util::sleep(1).await; terminal.draw(|f| { ui::ui(f, view.clone()); })?; @@ -233,7 +251,7 @@ async fn render(terminal: &mut Terminal, model: Arc) -> io match k.unwrap() { Key::Char('q') => { terminal.clear()?; - return Ok(()) + return Ok(()); } Key::Char('j') => { view.id_list.next(); diff --git a/bin/map/src/model.rs b/bin/map/src/model.rs index 77650fabe..d488ce465 100644 --- a/bin/map/src/model.rs +++ b/bin/map/src/model.rs @@ -50,7 +50,7 @@ impl InfoList { //pub type NodeId = u32; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct NodeInfo { pub id: String, pub connections: usize, diff --git a/bin/map/src/view.rs b/bin/map/src/view.rs index b9dd1df6c..65d6a1b49 100644 --- a/bin/map/src/view.rs +++ b/bin/map/src/view.rs @@ -64,7 +64,11 @@ pub struct InfoListView { impl InfoListView { pub fn new(infos: Vec) -> InfoListView { - let index = 0; + let mut index = 0; + + for _info in infos.clone() { + index = index + 1 + } InfoListView { index, infos } }