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

feat: upgrade crossterm #6783

Merged
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
33 changes: 11 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ blake2 = "0.10"
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = "0.14.0"
crossterm = { version = "0.25.0" }
crossterm = { version = "0.28" }
digest = "0.10"
dirs-next = "2.0"
futures = { version = "^0.3.16", default-features = false, features = [
Expand Down
11 changes: 11 additions & 0 deletions applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use log::trace;
use minotari_wallet::{error::WalletError, util::wallet_identity::WalletIdentity, WalletConfig, WalletSqlite};
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_comms::peer_manager::Peer;
Expand Down Expand Up @@ -136,6 +137,7 @@ impl<B: Backend> App<B> {
}

pub fn on_control_key(&mut self, c: char) {
trace!(target: LOG_TARGET, "on_control_key: {}", c);
match c {
'q' | 'c' => {
self.should_quit = true;
Expand All @@ -145,6 +147,7 @@ impl<B: Backend> App<B> {
}

pub fn on_key(&mut self, c: char) {
trace!(target: LOG_TARGET, "on_key: {}", c);
match c {
'\t' => {
self.tabs.next();
Expand All @@ -154,34 +157,42 @@ impl<B: Backend> App<B> {
}

pub fn on_backtab(&mut self) {
trace!(target: LOG_TARGET, "on_backtab");
self.tabs.previous();
}

pub fn on_up(&mut self) {
trace!(target: LOG_TARGET, "on_up");
self.tabs.on_up(&mut self.app_state);
}

pub fn on_down(&mut self) {
trace!(target: LOG_TARGET, "on_down");
self.tabs.on_down(&mut self.app_state);
}

pub fn on_f10(&mut self) {
trace!(target: LOG_TARGET, "on_f10");
self.should_quit = true;
}

pub fn on_right(&mut self) {
trace!(target: LOG_TARGET, "on_right");
self.tabs.next();
}

pub fn on_left(&mut self) {
trace!(target: LOG_TARGET, "on_left");
self.tabs.previous();
}

pub fn on_esc(&mut self) {
trace!(target: LOG_TARGET, "on_esc");
self.tabs.on_esc(&mut self.app_state);
}

pub fn on_backspace(&mut self) {
trace!(target: LOG_TARGET, "on_backspace");
self.tabs.on_backspace(&mut self.app_state);
}

Expand Down
63 changes: 47 additions & 16 deletions applications/minotari_console_wallet/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::io::{stdout, Stdout};

pub use app::*;
use crossterm::{
event::{KeyCode, KeyModifiers},
event::{KeyCode, KeyEventState, KeyModifiers},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
Expand Down Expand Up @@ -74,7 +74,9 @@ pub fn run(app: App<CrosstermBackend<Stdout>>) -> Result<(), ExitError> {
.map_err(|e| ExitError::new(ExitCode::WalletError, e))?;
crossterm_loop(app)
}

/// This is the main loop of the application UI using Crossterm based events
#[allow(clippy::too_many_lines)]
fn crossterm_loop(mut app: App<CrosstermBackend<Stdout>>) -> Result<(), ExitError> {
let events = CrosstermEvents::new();
enable_raw_mode().map_err(|e| {
Expand Down Expand Up @@ -108,25 +110,54 @@ fn crossterm_loop(mut app: App<CrosstermBackend<Stdout>>) -> Result<(), ExitErro
error!(target: LOG_TARGET, "Error drawing interface. {}", e);
ExitCode::InterfaceError
})?;
let event = events.next();
#[allow(clippy::blocks_in_conditions)]
match events.next().map_err(|e| {
match event.map_err(|e| {
error!(target: LOG_TARGET, "Error reading input event: {}", e);
ExitCode::InterfaceError
})? {
Event::Input(event) => match (event.code, event.modifiers) {
(KeyCode::Char(c), KeyModifiers::CONTROL) => app.on_control_key(c),
(KeyCode::Char(c), _) => app.on_key(c),
(KeyCode::Left, _) => app.on_left(),
(KeyCode::Up, _) => app.on_up(),
(KeyCode::Right, _) => app.on_right(),
(KeyCode::Down, _) => app.on_down(),
(KeyCode::Esc, _) => app.on_esc(),
(KeyCode::Backspace, _) => app.on_backspace(),
(KeyCode::Enter, _) => app.on_key('\n'),
(KeyCode::Tab, _) => app.on_key('\t'),
(KeyCode::BackTab, _) => app.on_backtab(),
(KeyCode::F(10), _) => app.on_f10(),
_ => {},
Event::Input(event) => {
trace!(target: LOG_TARGET, "event: '{:?}' '{}' '{:?}' '{}'",
event.code,
event.modifiers,
event.kind,
match event.state {
KeyEventState::KEYPAD => "KEYPAD",
KeyEventState::CAPS_LOCK => "CAPS_LOCK",
KeyEventState::NUM_LOCK => "NUM_LOCK",
_ => "NONE",
}
);
#[cfg(target_os = "windows")]
{
use crossterm::event::KeyEventKind;
let action_now = {
match (event.kind, event.modifiers, event.code) {
(KeyEventKind::Press, KeyModifiers::CONTROL, KeyCode::Char(c)) => c == 'q' || c == 'c',
(KeyEventKind::Press, _, KeyCode::F(c)) => c == 10,
(KeyEventKind::Release, _, _) => true,
(..) => false,
}
};
}
#[cfg(not(target_os = "windows"))]
let action_now = true;
match (event.code, event.modifiers, action_now) {
(_, _, false) => {},
(KeyCode::Char(c), KeyModifiers::CONTROL, _) => app.on_control_key(c),
(KeyCode::Char(c), _, _) => app.on_key(c),
(KeyCode::Left, _, _) => app.on_left(),
(KeyCode::Up, _, _) => app.on_up(),
(KeyCode::Right, _, _) => app.on_right(),
(KeyCode::Down, _, _) => app.on_down(),
(KeyCode::Esc, _, _) => app.on_esc(),
(KeyCode::Backspace, _, _) => app.on_backspace(),
(KeyCode::Enter, _, _) => app.on_key('\n'),
(KeyCode::Tab, _, _) => app.on_key('\t'),
(KeyCode::BackTab, _, _) => app.on_backtab(),
(KeyCode::F(10), _, _) => app.on_f10(),
_ => {},
}
},
Event::Tick => {
app.on_tick();
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bytes = "1.1"
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = { version = "0.14.0" }
crossterm = { version = "0.25.0" }
crossterm = { version = "0.28" }
futures = { version = "^0.3.16", features = ["async-await"] }
hex = "0.4.2"
hyper = { version = "0.14.12", features = ["default"] }
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bufstream = "0.1"
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive"] }
crossbeam = "0.8"
crossterm = { version = "0.25.0" }
crossterm = { version = "0.28" }
derivative = "2.2.0"
futures = "0.3"
hex = "0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
console-subscriber = "0.1.8"
config = { version = "0.14.0" }
crossterm = { version = "0.25.0", features = ["event-stream"] }
crossterm = { version = "0.28", features = ["event-stream"] }
derive_more = "0.99.17"
either = "1.6.1"
futures = { version = "^0.3.16", default-features = false, features = [
Expand Down
Loading