From 4973bf8cbeed027c1d110e0faefdd43c32f71729 Mon Sep 17 00:00:00 2001 From: veeso Date: Mon, 4 Oct 2021 20:40:24 +0200 Subject: [PATCH] Fixed issue 70: Unable to type characters with CTRL+ALT --- CHANGELOG.md | 4 +- Cargo.lock | 4 +- Cargo.toml | 2 +- .../activities/filetransfer/actions/edit.rs | 2 - src/ui/activities/setup/actions.rs | 2 - src/ui/activities/setup/config.rs | 2 - src/ui/context.rs | 41 +++++++++++++++---- 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a16e073..fa5284d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,13 +51,15 @@ Released on 12/10/2021 - Enhancements: - Reuse mounts in UI, in order to reduce executable size - File list can now be "rewinded", which means that moving with arrows will now allow you to go from top to bottom of the list pressing `` and viceversa pressing ``. +- Bugfix: + - Fixed [Issue 70](https://github.com/veeso/termscp/issues/70): Unable to type characters with `CTRL+ALT` (e.g. italian layout `CTRL+ALT+ò` => `@`) due to a crossterm issue. Fixed with tui-realm-stdlib `0.6.3`. - Dependencies: - Added `notify_rust 4.5.3` - Added `rust-s3 0.27-rc4` - Added `self_update 0.27.0` - Updated `argh` to `0.1.6` - Updated `dirs` to `4.0.0` - - Updated `tui-realm-stdlib` to `0.6.2` + - Updated `tui-realm-stdlib` to `0.6.3` - Removed `ureq` ## 0.6.1 diff --git a/Cargo.lock b/Cargo.lock index de668e8..321d4d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2390,9 +2390,9 @@ dependencies = [ [[package]] name = "tui-realm-stdlib" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54af02e93599f275c1eb0286235c935f60501d7ae1b554cfb1c9c584ca0193ff" +checksum = "f159d383b40dec75e0541530bc3416318f5e0a8b6999db9df9b5efa6b122380e" dependencies = [ "textwrap", "tuirealm", diff --git a/Cargo.toml b/Cargo.toml index 8543eda..d5c9459 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ tempfile = "3.1.0" textwrap = "0.14.2" thiserror = "^1.0.0" toml = "0.5.8" -tui-realm-stdlib = "0.6.2" +tui-realm-stdlib = "0.6.3" tuirealm = "0.6.0" whoami = "1.1.1" wildmatch = "2.0.0" diff --git a/src/ui/activities/filetransfer/actions/edit.rs b/src/ui/activities/filetransfer/actions/edit.rs index ba064a6..eacb24b 100644 --- a/src/ui/activities/filetransfer/actions/edit.rs +++ b/src/ui/activities/filetransfer/actions/edit.rs @@ -113,7 +113,6 @@ impl FileTransferActivity { error!("Failed to disable raw mode: {}", err); } // Leave alternate mode - #[cfg(not(target_os = "windows"))] if let Some(ctx) = self.context.as_mut() { ctx.leave_alternate_screen(); } @@ -128,7 +127,6 @@ impl FileTransferActivity { ), Err(err) => return Err(format!("Could not open editor: {}", err)), } - #[cfg(not(target_os = "windows"))] if let Some(ctx) = self.context.as_mut() { // Clear screen ctx.clear_screen(); diff --git a/src/ui/activities/setup/actions.rs b/src/ui/activities/setup/actions.rs index b49753c..6be4711 100644 --- a/src/ui/activities/setup/actions.rs +++ b/src/ui/activities/setup/actions.rs @@ -182,7 +182,6 @@ impl SetupActivity { error!("Failed to disable raw mode: {}", err); } // Leave alternate mode - #[cfg(not(target_os = "windows"))] if let Some(ctx) = self.context.as_mut() { ctx.leave_alternate_screen(); } @@ -215,7 +214,6 @@ impl SetupActivity { } } // Restore terminal - #[cfg(not(target_os = "windows"))] if let Some(ctx) = self.context.as_mut() { // Clear screen ctx.clear_screen(); diff --git a/src/ui/activities/setup/config.rs b/src/ui/activities/setup/config.rs index 1a2e5cd..8e811c5 100644 --- a/src/ui/activities/setup/config.rs +++ b/src/ui/activities/setup/config.rs @@ -98,7 +98,6 @@ impl SetupActivity { error!("Failed to disable raw mode: {}", err); } // Leave alternate mode - #[cfg(not(target_os = "windows"))] ctx.leave_alternate_screen(); // Get result let result: Result<(), String> = match ctx.config().iter_ssh_keys().nth(idx) { @@ -123,7 +122,6 @@ impl SetupActivity { // Clear screen ctx.clear_screen(); // Enter alternate mode - #[cfg(not(target_os = "windows"))] ctx.enter_alternate_screen(); // Re-enable raw mode if let Err(err) = enable_raw_mode() { diff --git a/src/ui/context.rs b/src/ui/context.rs index 5750ef1..37ce545 100644 --- a/src/ui/context.rs +++ b/src/ui/context.rs @@ -33,9 +33,12 @@ use crate::system::config_client::ConfigClient; use crate::system::theme_provider::ThemeProvider; // Includes -use crossterm::event::DisableMouseCapture; -use crossterm::execute; -use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen}; +#[cfg(target_family = "unix")] +use crossterm::{ + event::DisableMouseCapture, + execute, + terminal::{EnterAlternateScreen, LeaveAlternateScreen}, +}; use std::io::{stdout, Stdout}; use tuirealm::tui::backend::CrosstermBackend; use tuirealm::tui::Terminal; @@ -64,15 +67,12 @@ impl Context { theme_provider: ThemeProvider, error: Option, ) -> Context { - // Create terminal - let mut stdout = stdout(); - assert!(execute!(stdout, EnterAlternateScreen).is_ok()); Context { ft_params: None, config_client, store: Store::init(), input_hnd: InputHandler::new(), - terminal: Terminal::new(CrosstermBackend::new(stdout)).unwrap(), + terminal: Terminal::new(CrosstermBackend::new(Self::stdout())).unwrap(), theme_provider, error, } @@ -141,7 +141,7 @@ impl Context { /// ### enter_alternate_screen /// /// Enter alternate screen (gui window) - #[cfg(not(target_os = "windows"))] + #[cfg(target_family = "unix")] pub fn enter_alternate_screen(&mut self) { match execute!( self.terminal.backend_mut(), @@ -153,9 +153,16 @@ impl Context { } } + /// ### enter_alternate_screen + /// + /// Enter alternate screen (gui window) + #[cfg(target_family = "windows")] + pub fn enter_alternate_screen(&self) {} + /// ### leave_alternate_screen /// /// Go back to normal screen (gui window) + #[cfg(target_family = "unix")] pub fn leave_alternate_screen(&mut self) { match execute!( self.terminal.backend_mut(), @@ -167,6 +174,12 @@ impl Context { } } + /// ### leave_alternate_screen + /// + /// Go back to normal screen (gui window) + #[cfg(target_family = "windows")] + pub fn leave_alternate_screen(&self) {} + /// ### clear_screen /// /// Clear terminal screen @@ -176,6 +189,18 @@ impl Context { Ok(_) => info!("Cleared screen"), } } + + #[cfg(target_family = "unix")] + fn stdout() -> Stdout { + let mut stdout = stdout(); + assert!(execute!(stdout, EnterAlternateScreen).is_ok()); + stdout + } + + #[cfg(target_family = "windows")] + fn stdout() -> Stdout { + stdout() + } } impl Drop for Context {