Tui update 1 (#911)

* minor low-hanging TUI updates

* rustfmt

* make diff/height output clearer
This commit is contained in:
Yeastplume
2018-03-29 12:29:17 +01:00
committed by GitHub
parent 0fe27cc4e8
commit ea9a978c87
8 changed files with 58 additions and 21 deletions
+4 -11
View File
@@ -107,7 +107,6 @@ impl TableViewItem<MiningDeviceColumn> for CuckooMinerDeviceStats {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
enum DiffColumn {
BlockNumber,
Index,
Difficulty,
Time,
Duration,
@@ -117,7 +116,6 @@ impl DiffColumn {
fn _as_str(&self) -> &str {
match *self {
DiffColumn::BlockNumber => "Block Number",
DiffColumn::Index => "Block Index",
DiffColumn::Difficulty => "Network Difficulty",
DiffColumn::Time => "Block Time",
DiffColumn::Duration => "Duration",
@@ -132,7 +130,6 @@ impl TableViewItem<DiffColumn> for DiffBlock {
match column {
DiffColumn::BlockNumber => self.block_number.to_string(),
DiffColumn::Index => self.block_index.to_string(),
DiffColumn::Difficulty => self.difficulty.to_string(),
DiffColumn::Time => format!("{}", datetime).to_string(),
DiffColumn::Duration => format!("{}s", self.duration).to_string(),
@@ -145,7 +142,6 @@ impl TableViewItem<DiffColumn> for DiffBlock {
{
match column {
DiffColumn::BlockNumber => Ordering::Equal,
DiffColumn::Index => Ordering::Equal,
DiffColumn::Difficulty => Ordering::Equal,
DiffColumn::Time => Ordering::Equal,
DiffColumn::Duration => Ordering::Equal,
@@ -246,16 +242,13 @@ impl TUIStatusListener for TUIMiningView {
let diff_table_view = TableView::<DiffBlock, DiffColumn>::new()
.column(DiffColumn::BlockNumber, "Block Number", |c| {
c.width_percent(20)
})
.column(DiffColumn::Index, "Distance from Head", |c| {
c.width_percent(20)
c.width_percent(25)
})
.column(DiffColumn::Difficulty, "Network Difficulty", |c| {
c.width_percent(20)
c.width_percent(25)
})
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(20))
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(20));
.column(DiffColumn::Time, "Block Time", |c| c.width_percent(25))
.column(DiffColumn::Duration, "Duration", |c| c.width_percent(25));
let mining_difficulty_view = LinearLayout::new(Orientation::Vertical)
.child(diff_status_view)
+38 -5
View File
@@ -20,7 +20,8 @@ use grin::stats::{PeerStats, ServerStats};
use cursive::Cursive;
use cursive::view::View;
use cursive::views::{BoxView, Dialog};
use cursive::views::{BoxView, Dialog, LinearLayout, TextView};
use cursive::direction::Orientation;
use cursive::traits::*;
use tui::table::{TableView, TableViewItem};
@@ -53,7 +54,9 @@ impl TableViewItem<PeerColumn> for PeerStats {
match column {
PeerColumn::Address => self.addr.clone(),
PeerColumn::State => self.state.clone(),
PeerColumn::TotalDifficulty => self.total_difficulty.to_string(),
PeerColumn::TotalDifficulty => {
format!("{} D @ {} H", self.total_difficulty, self.height).to_string()
}
PeerColumn::Direction => self.direction.clone(),
PeerColumn::Version => self.version.to_string(),
}
@@ -86,20 +89,50 @@ impl TUIStatusListener for TUIPeerView {
c.width_percent(20)
})
.column(PeerColumn::Version, "Version", |c| c.width_percent(20));
let peer_status_view = BoxView::with_full_screen(
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
.title("Connected Peers"),
LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Total Peers: "))
.child(TextView::new(" ").with_id("peers_total")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Longest Chain: "))
.child(TextView::new(" ").with_id("longest_work_peer")),
)
.child(TextView::new(" "))
.child(
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
.title("Connected Peers"),
),
).with_id(VIEW_PEER_SYNC);
Box::new(peer_status_view)
}
fn update(c: &mut Cursive, stats: &ServerStats) {
let lp = stats
.peer_stats
.iter()
.max_by(|x, y| x.total_difficulty.cmp(&y.total_difficulty));
let lp_str = match lp {
Some(l) => format!(
"{} D @ {} H vs Us: {} D @ {} H",
l.total_difficulty, l.height, stats.head.total_difficulty, stats.head.height
).to_string(),
None => "".to_string(),
};
let _ = c.call_on_id(
TABLE_PEER_STATUS,
|t: &mut TableView<PeerStats, PeerColumn>| {
t.set_items(stats.peer_stats.clone());
},
);
let _ = c.call_on_id("peers_total", |t: &mut TextView| {
t.set_content(stats.peer_stats.len().to_string());
});
let _ = c.call_on_id("longest_work_peer", |t: &mut TextView| {
t.set_content(lp_str);
});
}
}
+8
View File
@@ -47,6 +47,11 @@ impl TUIStatusListener for TUIStatusView {
.child(TextView::new("Chain Height: "))
.child(TextView::new(" ").with_id("chain_height")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Total Difficulty: "))
.child(TextView::new(" ").with_id("basic_total_difficulty")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("------------------------")),
@@ -126,6 +131,9 @@ impl TUIStatusListener for TUIStatusView {
c.call_on_id("chain_height", |t: &mut TextView| {
t.set_content(stats.head.height.to_string());
});
c.call_on_id("basic_total_difficulty", |t: &mut TextView| {
t.set_content(stats.head.total_difficulty.to_string());
});
c.call_on_id("basic_mining_config_status", |t: &mut TextView| {
t.set_content(basic_mining_config_status);
});