mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
map: renamed App to Model
This commit is contained in:
@@ -5,6 +5,7 @@ use tui::widgets::ListState;
|
||||
#[derive(Clone)]
|
||||
pub struct IdList {
|
||||
pub state: ListState,
|
||||
// todo: mutex
|
||||
pub node_id: Vec<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
pub mod app;
|
||||
pub mod id_list;
|
||||
pub mod info_list;
|
||||
pub mod model;
|
||||
pub mod node_info;
|
||||
pub mod types;
|
||||
pub mod ui;
|
||||
|
||||
pub use app::App;
|
||||
pub use model::Model;
|
||||
pub use ui::ui;
|
||||
|
||||
@@ -16,7 +16,7 @@ use tui::{
|
||||
Terminal,
|
||||
};
|
||||
|
||||
use map::{id_list::IdList, info_list::InfoList, node_info::NodeInfo, ui, App};
|
||||
use map::{id_list::IdList, info_list::InfoList, node_info::NodeInfo, ui, Model};
|
||||
|
||||
struct Map {
|
||||
url: String,
|
||||
@@ -119,8 +119,8 @@ async fn main() -> Result<()> {
|
||||
|
||||
let id_list = IdList::new(ids);
|
||||
|
||||
//let app = Arc::new(App::new(id_list, info_list));
|
||||
let app = App::new(id_list, info_list);
|
||||
//let app = Arc::new(Model::new(id_list, info_list));
|
||||
let app = Model::new(id_list, info_list);
|
||||
|
||||
let nthreads = num_cpus::get();
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
@@ -143,7 +143,7 @@ async fn main() -> Result<()> {
|
||||
result
|
||||
}
|
||||
|
||||
async fn run_rpc(ex: Arc<Executor<'_>>, app: App) -> Result<()> {
|
||||
async fn run_rpc(ex: Arc<Executor<'_>>, app: Model) -> Result<()> {
|
||||
let client = Map::new("tcp://127.0.0.1:8000".to_string());
|
||||
|
||||
ex.spawn(poll(client, app)).detach();
|
||||
@@ -151,7 +151,7 @@ async fn run_rpc(ex: Arc<Executor<'_>>, app: App) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn poll(client: Map, _app: App) -> Result<()> {
|
||||
async fn poll(client: Map, _app: Model) -> Result<()> {
|
||||
loop {
|
||||
let reply = client.get_info().await?;
|
||||
|
||||
@@ -179,7 +179,7 @@ async fn poll(client: Map, _app: App) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
||||
async fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: Model) -> io::Result<()> {
|
||||
let mut asi = async_stdin();
|
||||
|
||||
terminal.clear()?;
|
||||
|
||||
@@ -8,19 +8,19 @@ use crate::{id_list::IdList, info_list::InfoList, node_info::NodeInfo};
|
||||
// arc reference
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct App {
|
||||
pub struct Model {
|
||||
pub id_list: IdList,
|
||||
pub info_list: InfoList,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new(id_list: IdList, info_list: InfoList) -> App {
|
||||
impl Model {
|
||||
pub fn new(id_list: IdList, info_list: InfoList) -> Model {
|
||||
//let infos = Vec::new();
|
||||
//let ids = Vec::new();
|
||||
|
||||
//let info_list = InfoList::new(infos);
|
||||
//let id_list = IdList::new(ids);
|
||||
App { id_list, info_list }
|
||||
Model { id_list, info_list }
|
||||
}
|
||||
|
||||
// TODO: implement this
|
||||
@@ -28,7 +28,7 @@ impl App {
|
||||
// Timer::after(dur).await;
|
||||
//}
|
||||
|
||||
pub async fn update(mut self, node_vec: Vec<NodeInfo>) -> App {
|
||||
pub async fn update(mut self, node_vec: Vec<NodeInfo>) -> Model {
|
||||
let ids = vec![node_vec[0].id.clone()];
|
||||
|
||||
for id in ids {
|
||||
@@ -42,11 +42,11 @@ impl App {
|
||||
}
|
||||
let info_list = self.info_list;
|
||||
|
||||
App { id_list, info_list }
|
||||
Model { id_list, info_list }
|
||||
}
|
||||
}
|
||||
|
||||
//impl Default for App {
|
||||
//impl Default for Model {
|
||||
// fn default() -> Self {
|
||||
// Self::new()
|
||||
// }
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::App;
|
||||
use crate::model::Model;
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
@@ -9,7 +9,7 @@ use tui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut app: App) {
|
||||
pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut app: Model) {
|
||||
let slice = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.margin(2)
|
||||
@@ -30,6 +30,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut app: App) {
|
||||
.block(Block::default().borders(Borders::ALL))
|
||||
.highlight_style(Style::default().fg(Color::LightCyan).add_modifier(Modifier::BOLD));
|
||||
|
||||
// needs to be mutable. could
|
||||
f.render_stateful_widget(nodes, slice[0], &mut app.id_list.state);
|
||||
|
||||
let index = app.info_list.index;
|
||||
@@ -37,7 +38,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut app: App) {
|
||||
render_info(app, f, index, slice);
|
||||
}
|
||||
|
||||
fn render_info<B: Backend>(app: App, f: &mut Frame<'_, B>, index: usize, slice: Vec<Rect>) {
|
||||
fn render_info<B: Backend>(app: Model, f: &mut Frame<'_, B>, index: usize, slice: Vec<Rect>) {
|
||||
let info = &app.info_list.infos;
|
||||
let id = &info[index].id;
|
||||
let connections = info[index].connections;
|
||||
|
||||
Reference in New Issue
Block a user