From 85fcfd8b64d0f17026ba61f1a59b04e9db6f1d8e Mon Sep 17 00:00:00 2001 From: eupn <36292692+eupn@users.noreply.github.com> Date: Wed, 16 Jan 2019 21:49:04 +0300 Subject: [PATCH] [TUI] Properly handle Esc in Peers and Mining, add Esc to the legend (#2371) --- src/bin/tui/menu.rs | 1 + src/bin/tui/mining.rs | 8 ++++---- src/bin/tui/peers.rs | 11 +++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bin/tui/menu.rs b/src/bin/tui/menu.rs index e1ee916d2..7fe3f511d 100644 --- a/src/bin/tui/menu.rs +++ b/src/bin/tui/menu.rs @@ -83,6 +83,7 @@ pub fn create() -> Box { .child(TextView::new("------------------")) .child(TextView::new("Tab/Arrow : Cycle ")) .child(TextView::new("Enter : Select")) + .child(TextView::new("Esc : Back ")) .child(TextView::new("Q : Quit ")); Box::new(main_menu) } diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index 5cf6f1d49..c67969f2c 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -184,10 +184,6 @@ impl TUIStatusListener for TUIMiningView { .child(Panel::new(devices_button)) .child(Panel::new(difficulty_button)); - let mining_submenu = OnEventView::new(mining_submenu).on_pre_event(Key::Esc, move |c| { - let _ = c.focus_id(MAIN_MENU); - }); - let table_view = TableView::::new() .column(StratumWorkerColumn::Id, "Worker ID", |c| c.width_percent(8)) .column(StratumWorkerColumn::IsConnected, "Connected", |c| { @@ -306,6 +302,10 @@ impl TUIStatusListener for TUIMiningView { .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); + }); + Box::new(mining_view.with_id(VIEW_MINING)) } diff --git a/src/bin/tui/peers.rs b/src/bin/tui/peers.rs index a3433bd33..8833dd5d1 100644 --- a/src/bin/tui/peers.rs +++ b/src/bin/tui/peers.rs @@ -22,12 +22,13 @@ use crate::tui::humansize::{file_size_opts::CONVENTIONAL, FileSize}; use chrono::prelude::*; use cursive::direction::Orientation; +use cursive::event::Key; use cursive::traits::{Boxable, Identifiable}; use cursive::view::View; -use cursive::views::{BoxView, Dialog, LinearLayout, TextView}; +use cursive::views::{BoxView, Dialog, LinearLayout, OnEventView, TextView}; use cursive::Cursive; -use crate::tui::constants::{TABLE_PEER_STATUS, VIEW_PEER_SYNC}; +use crate::tui::constants::{MAIN_MENU, TABLE_PEER_STATUS, VIEW_PEER_SYNC}; use crate::tui::table::{TableView, TableViewItem}; use crate::tui::types::TUIStatusListener; @@ -149,6 +150,12 @@ impl TUIStatusListener for TUIPeerView { ), ) .with_id(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); + }); + Box::new(peer_status_view) }