Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cursive to 0.14 and update backend. #3291

Merged
merged 5 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .ci/win.patch

This file was deleted.

105 changes: 67 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ grin_p2p = { path = "./p2p", version = "4.0.0-alpha.1" }
grin_servers = { path = "./servers", version = "4.0.0-alpha.1" }
grin_util = { path = "./util", version = "4.0.0-alpha.1" }

[target.'cfg(windows)'.dependencies]
cursive = { version = "0.12", default-features = false, features = ["pancurses-backend"] }
[target.'cfg(windows)'.dependencies.pancurses]
version = "0.16.0"
features = ["win32"]
[target.'cfg(unix)'.dependencies]
cursive = "0.12"
[dependencies.cursive]
version = "0.14"
default-features = false
features = ["pancurses-backend"]

[build-dependencies]
built = "0.3"
Expand Down
8 changes: 4 additions & 4 deletions src/bin/tui/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use cursive::theme::{BaseColor, Color, ColorStyle};
use cursive::traits::Identifiable;
use cursive::view::View;
use cursive::views::BoxView;
use cursive::views::ResizedView;
use cursive::{Cursive, Printer};

use crate::tui::constants::VIEW_LOGS;
Expand All @@ -29,12 +29,12 @@ pub struct TUILogsView;

impl TUILogsView {
pub fn create() -> Box<dyn View> {
let logs_view = BoxView::with_full_screen(LogBufferView::new(200).with_id("logs"));
Box::new(logs_view.with_id(VIEW_LOGS))
let logs_view = ResizedView::with_full_screen(LogBufferView::new(200).with_name("logs"));
Box::new(logs_view.with_name(VIEW_LOGS))
}

pub fn update(c: &mut Cursive, entry: LogEntry) {
c.call_on_id("logs", |t: &mut LogBufferView| {
c.call_on_name("logs", |t: &mut LogBufferView| {
t.update(entry);
});
}
Expand Down
18 changes: 9 additions & 9 deletions src/bin/tui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use cursive::event::{EventResult, Key};
use cursive::view::Identifiable;
use cursive::view::View;
use cursive::views::{
BoxView, LinearLayout, OnEventView, SelectView, StackView, TextView, ViewRef,
LinearLayout, OnEventView, ResizedView, SelectView, StackView, TextView, ViewRef,
};
use cursive::Cursive;

Expand All @@ -30,7 +30,7 @@ use crate::tui::constants::{
};

pub fn create() -> Box<dyn View> {
let mut main_menu = SelectView::new().h_align(HAlign::Left).with_id(MAIN_MENU);
let mut main_menu = SelectView::new().h_align(HAlign::Left).with_name(MAIN_MENU);
main_menu
.get_mut()
.add_item("Basic Status", VIEW_BASIC_STATUS);
Expand All @@ -45,8 +45,8 @@ pub fn create() -> Box<dyn View> {
return;
}

let _ = s.call_on_id(ROOT_STACK, |sv: &mut StackView| {
let pos = sv.find_layer_from_id(v).unwrap();
let _ = s.call_on_name(ROOT_STACK, |sv: &mut StackView| {
let pos = sv.find_layer_from_name(v).unwrap();
sv.move_to_front(pos);
});
};
Expand All @@ -56,22 +56,22 @@ pub fn create() -> Box<dyn View> {
.get_mut()
.set_on_submit(|c: &mut Cursive, v: &str| {
if v == VIEW_MINING {
let _ = c.focus_id(SUBMENU_MINING_BUTTON);
let _ = c.focus_name(SUBMENU_MINING_BUTTON);
}
});
let main_menu = OnEventView::new(main_menu)
.on_pre_event('j', move |c| {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
let mut s: ViewRef<SelectView<&str>> = c.find_name(MAIN_MENU).unwrap();
s.select_down(1)(c);
Some(EventResult::Consumed(None));
})
.on_pre_event('k', move |c| {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
let mut s: ViewRef<SelectView<&str>> = c.find_name(MAIN_MENU).unwrap();
s.select_up(1)(c);
Some(EventResult::Consumed(None));
})
.on_pre_event(Key::Tab, move |c| {
let mut s: ViewRef<SelectView<&str>> = c.find_id(MAIN_MENU).unwrap();
let mut s: ViewRef<SelectView<&str>> = c.find_name(MAIN_MENU).unwrap();
if s.selected_id().unwrap() == s.len() - 1 {
s.set_selection(0)(c);
} else {
Expand All @@ -80,7 +80,7 @@ pub fn create() -> Box<dyn View> {
Some(EventResult::Consumed(None));
});
let main_menu = LinearLayout::new(Orientation::Vertical)
.child(BoxView::with_full_height(main_menu))
.child(ResizedView::with_full_height(main_menu))
.child(TextView::new("------------------"))
.child(TextView::new("Tab/Arrow : Cycle "))
.child(TextView::new("Enter : Select"))
Expand Down
78 changes: 39 additions & 39 deletions src/bin/tui/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use cursive::event::Key;
use cursive::traits::{Boxable, Identifiable};
use cursive::view::View;
use cursive::views::{
BoxView, Button, Dialog, LinearLayout, OnEventView, Panel, StackView, TextView,
Button, Dialog, LinearLayout, OnEventView, Panel, ResizedView, StackView, TextView,
};
use cursive::Cursive;
use std::time;
Expand Down Expand Up @@ -169,15 +169,15 @@ impl TUIStatusListener for TUIMiningView {
/// Create the mining view
fn create() -> Box<dyn View> {
let devices_button = Button::new_raw("Mining Server Status", |s| {
let _ = s.call_on_id("mining_stack_view", |sv: &mut StackView| {
let pos = sv.find_layer_from_id("mining_device_view").unwrap();
let _ = s.call_on_name("mining_stack_view", |sv: &mut StackView| {
let pos = sv.find_layer_from_name("mining_device_view").unwrap();
sv.move_to_front(pos);
});
})
.with_id(SUBMENU_MINING_BUTTON);
.with_name(SUBMENU_MINING_BUTTON);
let difficulty_button = Button::new_raw("Difficulty", |s| {
let _ = s.call_on_id("mining_stack_view", |sv: &mut StackView| {
let pos = sv.find_layer_from_id("mining_difficulty_view").unwrap();
let _ = s.call_on_name("mining_stack_view", |sv: &mut StackView| {
let pos = sv.find_layer_from_name("mining_difficulty_view").unwrap();
sv.move_to_front(pos);
});
});
Expand Down Expand Up @@ -212,61 +212,61 @@ impl TUIStatusListener for TUIMiningView {
let status_view = LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_config_status")),
.child(TextView::new(" ").with_name("stratum_config_status")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_is_running_status")),
.child(TextView::new(" ").with_name("stratum_is_running_status")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_num_workers_status")),
.child(TextView::new(" ").with_name("stratum_num_workers_status")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_block_height_status")),
.child(TextView::new(" ").with_name("stratum_block_height_status")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_difficulty_status")),
.child(TextView::new(" ").with_name("stratum_network_difficulty_status")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_network_hashrate")),
.child(TextView::new(" ").with_name("stratum_network_hashrate")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("stratum_edge_bits_status")),
.child(TextView::new(" ").with_name("stratum_edge_bits_status")),
);

let mining_device_view = LinearLayout::new(Orientation::Vertical)
.child(status_view)
.child(BoxView::with_full_screen(
Dialog::around(table_view.with_id(TABLE_MINING_STATUS).min_size((50, 20)))
.child(ResizedView::with_full_screen(
Dialog::around(table_view.with_name(TABLE_MINING_STATUS).min_size((50, 20)))
.title("Mining Workers"),
))
.with_id("mining_device_view");
.with_name("mining_device_view");

let diff_status_view = LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Tip Height: "))
.child(TextView::new("").with_id("diff_cur_height")),
.child(TextView::new("").with_name("diff_cur_height")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Difficulty Adjustment Window: "))
.child(TextView::new("").with_id("diff_adjust_window")),
.child(TextView::new("").with_name("diff_adjust_window")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Block Time: "))
.child(TextView::new("").with_id("diff_avg_block_time")),
.child(TextView::new("").with_name("diff_avg_block_time")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Average Difficulty: "))
.child(TextView::new("").with_id("diff_avg_difficulty")),
.child(TextView::new("").with_name("diff_avg_difficulty")),
);

let diff_table_view = TableView::<DiffBlock, DiffColumn>::new()
Expand All @@ -284,51 +284,51 @@ impl TUIStatusListener for TUIMiningView {

let mining_difficulty_view = LinearLayout::new(Orientation::Vertical)
.child(diff_status_view)
.child(BoxView::with_full_screen(
.child(ResizedView::with_full_screen(
Dialog::around(
diff_table_view
.with_id(TABLE_MINING_DIFF_STATUS)
.with_name(TABLE_MINING_DIFF_STATUS)
.min_size((50, 20)),
)
.title("Mining Difficulty Data"),
))
.with_id("mining_difficulty_view");
.with_name("mining_difficulty_view");

let view_stack = StackView::new()
.layer(mining_difficulty_view)
.layer(mining_device_view)
.with_id("mining_stack_view");
.with_name("mining_stack_view");

let mining_view = LinearLayout::new(Orientation::Vertical)
.child(mining_submenu)
.child(view_stack);

let mining_view = OnEventView::new(mining_view).on_pre_event(Key::Esc, move |c| {
let _ = c.focus_id(MAIN_MENU);
let _ = c.focus_name(MAIN_MENU);
});

Box::new(mining_view.with_id(VIEW_MINING))
Box::new(mining_view.with_name(VIEW_MINING))
}

/// update
fn update(c: &mut Cursive, stats: &ServerStats) {
c.call_on_id("diff_cur_height", |t: &mut TextView| {
c.call_on_name("diff_cur_height", |t: &mut TextView| {
t.set_content(stats.diff_stats.height.to_string());
});
c.call_on_id("diff_adjust_window", |t: &mut TextView| {
c.call_on_name("diff_adjust_window", |t: &mut TextView| {
t.set_content(stats.diff_stats.window_size.to_string());
});
let dur = time::Duration::from_secs(stats.diff_stats.average_block_time);
c.call_on_id("diff_avg_block_time", |t: &mut TextView| {
c.call_on_name("diff_avg_block_time", |t: &mut TextView| {
t.set_content(format!("{} Secs", dur.as_secs()).to_string());
});
c.call_on_id("diff_avg_difficulty", |t: &mut TextView| {
c.call_on_name("diff_avg_difficulty", |t: &mut TextView| {
t.set_content(stats.diff_stats.average_difficulty.to_string());
});

let mut diff_stats = stats.diff_stats.last_blocks.clone();
diff_stats.reverse();
let _ = c.call_on_id(
let _ = c.call_on_name(
TABLE_MINING_DIFF_STATUS,
|t: &mut TableView<DiffBlock, DiffColumn>| {
t.set_items(diff_stats);
Expand All @@ -351,28 +351,28 @@ impl TUIStatusListener for TUIMiningView {
);
let stratum_edge_bits = format!("Cuckoo Size: {}", stratum_stats.edge_bits);

c.call_on_id("stratum_config_status", |t: &mut TextView| {
c.call_on_name("stratum_config_status", |t: &mut TextView| {
t.set_content(stratum_enabled);
});
c.call_on_id("stratum_is_running_status", |t: &mut TextView| {
c.call_on_name("stratum_is_running_status", |t: &mut TextView| {
t.set_content(stratum_is_running);
});
c.call_on_id("stratum_num_workers_status", |t: &mut TextView| {
c.call_on_name("stratum_num_workers_status", |t: &mut TextView| {
t.set_content(stratum_num_workers);
});
c.call_on_id("stratum_block_height_status", |t: &mut TextView| {
c.call_on_name("stratum_block_height_status", |t: &mut TextView| {
t.set_content(stratum_block_height);
});
c.call_on_id("stratum_network_difficulty_status", |t: &mut TextView| {
c.call_on_name("stratum_network_difficulty_status", |t: &mut TextView| {
t.set_content(stratum_network_difficulty);
});
c.call_on_id("stratum_network_hashrate", |t: &mut TextView| {
c.call_on_name("stratum_network_hashrate", |t: &mut TextView| {
t.set_content(stratum_network_hashrate);
});
c.call_on_id("stratum_edge_bits_status", |t: &mut TextView| {
c.call_on_name("stratum_edge_bits_status", |t: &mut TextView| {
t.set_content(stratum_edge_bits);
});
let _ = c.call_on_id(
let _ = c.call_on_name(
TABLE_MINING_STATUS,
|t: &mut TableView<WorkerStats, StratumWorkerColumn>| {
t.set_items(worker_stats);
Expand Down
20 changes: 10 additions & 10 deletions src/bin/tui/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use cursive::direction::Orientation;
use cursive::event::Key;
use cursive::traits::{Boxable, Identifiable};
use cursive::view::View;
use cursive::views::{BoxView, Dialog, LinearLayout, OnEventView, TextView};
use cursive::views::{Dialog, LinearLayout, OnEventView, ResizedView, TextView};
use cursive::Cursive;

use crate::tui::constants::{MAIN_MENU, TABLE_PEER_STATUS, VIEW_PEER_SYNC};
Expand Down Expand Up @@ -136,28 +136,28 @@ impl TUIStatusListener for TUIPeerView {
})
.column(PeerColumn::Version, "Proto", |c| c.width_percent(6))
.column(PeerColumn::UserAgent, "User Agent", |c| c.width_percent(18));
let peer_status_view = BoxView::with_full_screen(
let peer_status_view = ResizedView::with_full_screen(
LinearLayout::new(Orientation::Vertical)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new(" ").with_id("peers_total")),
.child(TextView::new(" ").with_name("peers_total")),
)
.child(
LinearLayout::new(Orientation::Horizontal)
.child(TextView::new("Longest Chain: "))
.child(TextView::new(" ").with_id("longest_work_peer")),
.child(TextView::new(" ").with_name("longest_work_peer")),
)
.child(TextView::new(" "))
.child(
Dialog::around(table_view.with_id(TABLE_PEER_STATUS).min_size((50, 20)))
Dialog::around(table_view.with_name(TABLE_PEER_STATUS).min_size((50, 20)))
.title("Connected Peers"),
),
)
.with_id(VIEW_PEER_SYNC);
.with_name(VIEW_PEER_SYNC);

let peer_status_view =
OnEventView::new(peer_status_view).on_pre_event(Key::Esc, move |c| {
let _ = c.focus_id(MAIN_MENU);
let _ = c.focus_name(MAIN_MENU);
});

Box::new(peer_status_view)
Expand All @@ -179,13 +179,13 @@ impl TUIStatusListener for TUIPeerView {
.to_string(),
None => "".to_string(),
};
let _ = c.call_on_id(
let _ = c.call_on_name(
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| {
let _ = c.call_on_name("peers_total", |t: &mut TextView| {
t.set_content(format!(
"Total Peers: {} (Outbound: {})",
stats.peer_stats.len(),
Expand All @@ -196,7 +196,7 @@ impl TUIStatusListener for TUIPeerView {
.count(),
));
});
let _ = c.call_on_id("longest_work_peer", |t: &mut TextView| {
let _ = c.call_on_name("longest_work_peer", |t: &mut TextView| {
t.set_content(lp_str);
});
}
Expand Down
Loading