make DnvConfig a seperate crate and pass to ui

This commit is contained in:
lunar-mining
2022-03-08 10:01:16 +01:00
parent 0fadfe39d1
commit a3a8112f2e
4 changed files with 20 additions and 16 deletions

View File

@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};
pub const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../dnetview_config.toml");
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct DnvConfig {
pub nodes: Vec<IrcNode>,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct IrcNode {
pub node_id: String,
//pub rpc_url: String,
}

View File

@@ -1,8 +1,10 @@
pub mod config;
pub mod model;
pub mod options;
pub mod ui;
pub mod view;
pub use config::{DnvConfig, CONFIG_FILE_CONTENTS};
pub use model::{IdList, InfoList, Model, NodeInfo};
pub use options::ProgramOptions;
pub use ui::ui;

View File

@@ -11,7 +11,6 @@ use darkfi::{
use async_std::sync::Arc;
use easy_parallel::Parallel;
use log::{debug, info};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use simplelog::*;
use smol::Executor;
@@ -30,6 +29,7 @@ use tui::{
use url::Url;
use dnetview::{
config::{DnvConfig, CONFIG_FILE_CONTENTS},
model::{Connection, IdList, InfoList, NodeInfo},
options::ProgramOptions,
ui,
@@ -37,19 +37,6 @@ use dnetview::{
Model, View,
};
const CONFIG_FILE_CONTENTS: &[u8] = include_bytes!("../dnetview_config.toml");
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct DnvConfig {
pub nodes: Vec<IrcNode>,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct IrcNode {
pub node_id: String,
//pub rpc_url: String,
}
struct Map {
url: Url,
}
@@ -230,7 +217,7 @@ async fn render<B: Backend>(
loop {
view.update(model.info_list.infos.lock().await.clone());
terminal.draw(|f| {
ui::ui(f, view.clone());
ui::ui(f, view.clone(), &config);
})?;
for k in asi.by_ref().keys() {
match k.unwrap() {

View File

@@ -1,4 +1,5 @@
use crate::view::View;
use crate::DnvConfig;
use tui::{
backend::Backend,
@@ -9,7 +10,7 @@ use tui::{
Frame,
};
pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View, config: &DnvConfig) {
let slice = Layout::default()
.direction(Direction::Horizontal)
.margin(2)