mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
ui: check whether msg is sent or recv and display on the right
this is a quick fix to display info properly and ui.rs still needs a major cleanup and refactor.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::view::View;
|
||||
//use log::debug;
|
||||
use log::debug;
|
||||
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
@@ -39,62 +39,66 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
|
||||
}
|
||||
|
||||
fn render_info_left<B: Backend>(view: View, f: &mut Frame<'_, B>) {
|
||||
// TODO: this is a hack. there must be a better way of doing this.
|
||||
// e.g. a function called get_length()
|
||||
let length = render_outbound(view.clone(), f);
|
||||
let length = render_inbound(view.clone(), f, length);
|
||||
render_manual(view.clone(), f, length);
|
||||
//render_manual(view.clone(), f, length);
|
||||
}
|
||||
|
||||
fn render_manual<B: Backend>(view: View, f: &mut Frame<'_, B>, length: usize) {
|
||||
let new_num: u16 = length.try_into().unwrap();
|
||||
let title_slice = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.horizontal_margin(8)
|
||||
.vertical_margin(new_num)
|
||||
.constraints([Constraint::Percentage(100)].as_ref())
|
||||
.split(f.size());
|
||||
//fn render_manual<B: Backend>(view: View, f: &mut Frame<'_, B>, length: usize) {
|
||||
// let new_num: u16 = length.try_into().unwrap();
|
||||
// let title_slice = Layout::default()
|
||||
// .direction(Direction::Horizontal)
|
||||
// .horizontal_margin(8)
|
||||
// .vertical_margin(new_num)
|
||||
// .constraints([Constraint::Percentage(100)].as_ref())
|
||||
// .split(f.size());
|
||||
//
|
||||
// let info_slice = Layout::default()
|
||||
// .direction(Direction::Horizontal)
|
||||
// .horizontal_margin(10)
|
||||
// .vertical_margin(new_num)
|
||||
// .constraints([Constraint::Percentage(45), Constraint::Percentage(55)].as_ref())
|
||||
// .split(f.size());
|
||||
//
|
||||
// let info = &view.info_list.infos;
|
||||
// let mut title = Vec::new();
|
||||
// for id in &view.id_list.node_id {
|
||||
// match info.get(id) {
|
||||
// Some(_) => {
|
||||
// title.push(Spans::from(Span::styled("Manual:", Style::default())));
|
||||
// }
|
||||
// None => {
|
||||
// // TODO
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let mut man_info = Vec::new();
|
||||
// for id in &view.id_list.node_id {
|
||||
// match info.get(id) {
|
||||
// Some(connects) => {
|
||||
// man_info.push(Spans::from(""));
|
||||
// man_info.push(Spans::from(format!("Key: {}", connects.manual[0].key)));
|
||||
// man_info.push(Spans::from(""));
|
||||
// }
|
||||
// None => {
|
||||
// // TODO
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let info_graph = Paragraph::new(man_info).style(Style::default()).alignment(Alignment::Left);
|
||||
// let title_graph = Paragraph::new(title).style(Style::default()).alignment(Alignment::Left);
|
||||
//
|
||||
// f.render_widget(info_graph, info_slice[0]);
|
||||
// f.render_widget(title_graph, title_slice[0]);
|
||||
//}
|
||||
|
||||
let info_slice = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.horizontal_margin(10)
|
||||
.vertical_margin(new_num)
|
||||
.constraints([Constraint::Percentage(45), Constraint::Percentage(55)].as_ref())
|
||||
.split(f.size());
|
||||
|
||||
let info = &view.info_list.infos;
|
||||
let mut title = Vec::new();
|
||||
for id in &view.id_list.node_id {
|
||||
match info.get(id) {
|
||||
Some(_) => {
|
||||
title.push(Spans::from(Span::styled("Manual:", Style::default())));
|
||||
}
|
||||
None => {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut man_info = Vec::new();
|
||||
for id in &view.id_list.node_id {
|
||||
match info.get(id) {
|
||||
Some(connects) => {
|
||||
man_info.push(Spans::from(""));
|
||||
man_info.push(Spans::from(format!("Key: {}", connects.manual[0].key)));
|
||||
man_info.push(Spans::from(""));
|
||||
}
|
||||
None => {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let info_graph = Paragraph::new(man_info).style(Style::default()).alignment(Alignment::Left);
|
||||
let title_graph = Paragraph::new(title).style(Style::default()).alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(info_graph, info_slice[0]);
|
||||
f.render_widget(title_graph, title_slice[0]);
|
||||
}
|
||||
fn render_inbound<B: Backend>(view: View, f: &mut Frame<'_, B>, length: usize) -> usize {
|
||||
let mut inbound_info = Vec::new();
|
||||
let mut i_info = Vec::new();
|
||||
let mut msgs = Vec::new();
|
||||
// TODO: find better way of doing this
|
||||
let new_num: u16 = length.try_into().unwrap();
|
||||
let num = new_num + 3;
|
||||
@@ -129,20 +133,34 @@ fn render_inbound<B: Backend>(view: View, f: &mut Frame<'_, B>, length: usize) -
|
||||
match info.get(id) {
|
||||
Some(connects) => {
|
||||
if connects.inbound.is_empty() {
|
||||
inbound_info.push(Spans::from(""));
|
||||
inbound_info.push(Spans::from(format!("Connected: Null")));
|
||||
inbound_info.push(Spans::from(format!("Last msg: Null")));
|
||||
inbound_info.push(Spans::from(format!("Last status: Null")));
|
||||
i_info.push(Spans::from(""));
|
||||
i_info.push(Spans::from("Null"));
|
||||
msgs.push(Spans::from(""));
|
||||
msgs.push(Spans::from("[R: Null]"));
|
||||
msgs.push(Spans::from("[S: Null]"));
|
||||
} else {
|
||||
for connect in &connects.inbound {
|
||||
inbound_info.push(Spans::from(""));
|
||||
inbound_info.push(Spans::from(format!("Connected: {}", connect.connected)));
|
||||
inbound_info
|
||||
.push(Spans::from(format!("Last msg: {}", connect.channel.last_msg)));
|
||||
inbound_info.push(Spans::from(format!(
|
||||
"Last status: {}",
|
||||
connect.channel.last_status
|
||||
)));
|
||||
i_info.push(Spans::from(""));
|
||||
i_info.push(Spans::from(connect.connected.clone()));
|
||||
match connect.channel.last_status.as_str() {
|
||||
"recv" => {
|
||||
msgs.push(Spans::from(""));
|
||||
msgs.push(Spans::from(format!(
|
||||
"[R: {}]",
|
||||
connect.channel.last_msg
|
||||
)));
|
||||
}
|
||||
"sent" => {
|
||||
msgs.push(Spans::from(""));
|
||||
msgs.push(Spans::from(format!(
|
||||
"[S: {}]",
|
||||
connect.channel.last_msg
|
||||
)));
|
||||
}
|
||||
_ => {
|
||||
// TODO: handle these values
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,21 +170,24 @@ fn render_inbound<B: Backend>(view: View, f: &mut Frame<'_, B>, length: usize) -
|
||||
}
|
||||
}
|
||||
for _n in 1..info.len() {
|
||||
inbound_info.push(Spans::from(""))
|
||||
i_info.push(Spans::from(""))
|
||||
}
|
||||
|
||||
let info_graph =
|
||||
Paragraph::new(inbound_info.clone()).style(Style::default()).alignment(Alignment::Left);
|
||||
Paragraph::new(i_info.clone()).style(Style::default()).alignment(Alignment::Left);
|
||||
let msg_graph = Paragraph::new(msgs).style(Style::default()).alignment(Alignment::Right);
|
||||
let title_graph =
|
||||
Paragraph::new(title.clone()).style(Style::default()).alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(info_graph, info_slice[0]);
|
||||
f.render_widget(msg_graph, info_slice[0]);
|
||||
f.render_widget(title_graph, title_slice[0]);
|
||||
|
||||
return inbound_info.len() + title.len() + length + 2
|
||||
return i_info.len() + title.len() + length + 2;
|
||||
}
|
||||
|
||||
fn render_outbound<B: Backend>(view: View, f: &mut Frame<'_, B>) -> usize {
|
||||
// TODO: move all this boilerplate into functions
|
||||
let title_slice = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.horizontal_margin(8)
|
||||
@@ -195,14 +216,26 @@ fn render_outbound<B: Backend>(view: View, f: &mut Frame<'_, B>) -> usize {
|
||||
}
|
||||
|
||||
let mut slots = Vec::new();
|
||||
let mut msgs = Vec::new();
|
||||
for id in &view.id_list.node_id {
|
||||
match info.get(id) {
|
||||
Some(connects) => {
|
||||
for slot in &connects.outbound[0].slots {
|
||||
slots.push(Spans::from(""));
|
||||
slots.push(Spans::from(format!("Addr: {}", slot.addr)));
|
||||
slots.push(Spans::from(format!("Last msg: {}", slot.channel.last_msg)));
|
||||
slots.push(Spans::from(format!("Last status: {}", slot.channel.last_status)));
|
||||
slots.push(Spans::from(format!("{}", slot.addr)));
|
||||
match slot.channel.last_status.as_str() {
|
||||
"recv" => {
|
||||
msgs.push(Spans::from(""));
|
||||
msgs.push(Spans::from(format!("[R: {}]", slot.channel.last_msg)));
|
||||
}
|
||||
"sent" => {
|
||||
msgs.push(Spans::from(""));
|
||||
msgs.push(Spans::from(format!("[S: {}]", slot.channel.last_msg)));
|
||||
}
|
||||
_ => {
|
||||
// TODO: right now we do nothing with these values
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -210,20 +243,23 @@ fn render_outbound<B: Backend>(view: View, f: &mut Frame<'_, B>) -> usize {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _n in 1..info.len() {
|
||||
slots.push(Spans::from(""))
|
||||
}
|
||||
|
||||
let info_graph =
|
||||
let slots_graph =
|
||||
Paragraph::new(slots.clone()).style(Style::default()).alignment(Alignment::Left);
|
||||
let msgs_graph = Paragraph::new(msgs).style(Style::default()).alignment(Alignment::Right);
|
||||
let title_graph =
|
||||
Paragraph::new(title.clone()).style(Style::default()).alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(info_graph, info_slice[0]);
|
||||
f.render_widget(msgs_graph, info_slice[0]);
|
||||
f.render_widget(slots_graph, info_slice[0]);
|
||||
f.render_widget(title_graph, title_slice[0]);
|
||||
|
||||
let out_len = slots.len() + title.len();
|
||||
return out_len
|
||||
return out_len;
|
||||
}
|
||||
|
||||
fn render_info_right<B: Backend>(
|
||||
|
||||
Reference in New Issue
Block a user