mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
dnetview: sleep for 2 sec between poll instead of 2000 sec
also cargo fmt and cleanup
This commit is contained in:
@@ -21,14 +21,14 @@ use std::{fs::File, io, io::Read};
|
||||
use async_std::sync::Arc;
|
||||
use clap::Parser;
|
||||
use easy_parallel::Parallel;
|
||||
use log::info;
|
||||
use simplelog::*;
|
||||
use smol::Executor;
|
||||
use termion::{async_stdin, event::Key, input::TermRead, raw::IntoRawMode};
|
||||
use log::{debug, info};
|
||||
use ratatui::{
|
||||
backend::{Backend, TermionBackend},
|
||||
Terminal,
|
||||
};
|
||||
use simplelog::*;
|
||||
use smol::Executor;
|
||||
use termion::{async_stdin, event::Key, input::TermRead, raw::IntoRawMode};
|
||||
|
||||
use darkfi::util::{
|
||||
async_util,
|
||||
@@ -76,12 +76,8 @@ impl DnetView {
|
||||
self.view.update(
|
||||
self.model.msg_map.lock().await.clone(),
|
||||
self.model.selectables.lock().await.clone(),
|
||||
//self.model.selectables2.lock().await.clone(),
|
||||
);
|
||||
|
||||
//debug!(target: "dnetview::render_view()", "ID MENU: {:?}", self.view.id_menu.ids);
|
||||
//debug!(target: "dnetview::render_view()", "SELECTABLES ID LIST: {:?}", self.model.selectables.lock().await.keys());
|
||||
|
||||
let mut err: Option<DnetViewError> = None;
|
||||
|
||||
terminal.draw(|f| match self.view.render(f) {
|
||||
@@ -127,7 +123,6 @@ impl DnetView {
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> DnetViewResult<()> {
|
||||
//debug!(target: "dnetview", "main() START");
|
||||
let args = Args::parse();
|
||||
|
||||
let log_level = get_log_level(args.verbose);
|
||||
|
||||
@@ -74,7 +74,7 @@ impl DataParser {
|
||||
}
|
||||
}
|
||||
self.parse_offline(node.name.clone()).await?;
|
||||
async_util::sleep(2000).await;
|
||||
async_util::sleep(2).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,14 +114,13 @@ impl DataParser {
|
||||
}
|
||||
|
||||
// Sleep until next poll
|
||||
async_util::sleep(2000).await;
|
||||
async_util::sleep(2).await;
|
||||
}
|
||||
}
|
||||
|
||||
// If poll times out, inititalize data structures with empty values.
|
||||
async fn parse_offline(&self, node_name: String) -> DnetViewResult<()> {
|
||||
debug!(target: "dnetview", "parse_offline() START");
|
||||
//let name = "Offline".to_string();
|
||||
let sort = Session::Offline;
|
||||
|
||||
let mut sessions: Vec<SessionInfo> = Vec::new();
|
||||
@@ -190,7 +189,6 @@ impl DataParser {
|
||||
true
|
||||
}
|
||||
};
|
||||
debug!("dnet_enabled? {}", dnet_enabled);
|
||||
|
||||
let hosts = self.parse_hosts(hosts).await?;
|
||||
let inbound = self.parse_session(inbound, &node_id, Session::Inbound).await?;
|
||||
@@ -439,9 +437,7 @@ impl DataParser {
|
||||
);
|
||||
session_info.push(session);
|
||||
}
|
||||
None => {
|
||||
return Err(DnetViewError::ValueIsNotObject)
|
||||
}
|
||||
None => return Err(DnetViewError::ValueIsNotObject),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Span, Line},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, List, ListItem, ListState, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
@@ -71,6 +71,7 @@ impl<'a> View {
|
||||
self.make_ordered_list();
|
||||
}
|
||||
|
||||
// We copy the values into a string to initialize List as a StatefulObject.
|
||||
fn update_id_menu(&mut self, selectables: HashMap<String, SelectableObject>) {
|
||||
for id in selectables.keys() {
|
||||
if !self.id_menu.ids.iter().any(|i| i == id) {
|
||||
@@ -79,6 +80,7 @@ impl<'a> View {
|
||||
}
|
||||
}
|
||||
|
||||
// We first add every selectable object into a hashmap to avoid duplicates.
|
||||
fn update_selectable(&mut self, selectables: HashMap<String, SelectableObject>) {
|
||||
for (id, obj) in selectables {
|
||||
self.selectables.insert(id, obj);
|
||||
@@ -183,11 +185,7 @@ impl<'a> View {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_left<B: Backend>(
|
||||
&mut self,
|
||||
f: &mut Frame<'_, B>,
|
||||
slice: Rect,
|
||||
) -> DnetViewResult<()> {
|
||||
fn render_left<B: Backend>(&mut self, f: &mut Frame<'_, B>, slice: Rect) -> DnetViewResult<()> {
|
||||
let style = Style::default();
|
||||
let mut nodes = Vec::new();
|
||||
|
||||
@@ -206,9 +204,8 @@ impl<'a> View {
|
||||
nodes.push(names);
|
||||
} else {
|
||||
if !node.dnet_enabled {
|
||||
let style = Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let style =
|
||||
Style::default().fg(Color::LightBlue).add_modifier(Modifier::BOLD);
|
||||
let mut name = String::new();
|
||||
name.push_str(&node.name);
|
||||
name.push_str("(dnetview is not enabled)");
|
||||
|
||||
Reference in New Issue
Block a user