Fixed windows dying when opening text files

This commit is contained in:
veeso
2021-06-19 15:06:49 +02:00
parent 4475e8c24c
commit 5a4a364250
5 changed files with 14 additions and 3 deletions
+1
View File
@@ -35,6 +35,7 @@ Released on 21/06/2021
- If the terminal window has less than 24 lines, then an error message is displayed in the auth activity - If the terminal window has less than 24 lines, then an error message is displayed in the auth activity
- Changed auth layout to absolute sizes - Changed auth layout to absolute sizes
- Bugfix: - Bugfix:
- Fixed termscp on Windows dying whenever opening a file with text editor
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2) - Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
- Fixed [Issue 44](https://github.com/veeso/termscp/issues/44): Could not move files to other paths in FTP - Fixed [Issue 44](https://github.com/veeso/termscp/issues/44): Could not move files to other paths in FTP
- Fixed [Issue 43](https://github.com/veeso/termscp/issues/43): Could not remove non-empty directories in FTP - Fixed [Issue 43](https://github.com/veeso/termscp/issues/43): Could not remove non-empty directories in FTP
@@ -113,6 +113,7 @@ impl FileTransferActivity {
error!("Failed to disable raw mode: {}", err); error!("Failed to disable raw mode: {}", err);
} }
// Leave alternate mode // Leave alternate mode
#[cfg(not(target_os = "windows"))]
if let Some(ctx) = self.context.as_mut() { if let Some(ctx) = self.context.as_mut() {
ctx.leave_alternate_screen(); ctx.leave_alternate_screen();
} }
@@ -127,6 +128,7 @@ impl FileTransferActivity {
), ),
Err(err) => return Err(format!("Could not open editor: {}", err)), Err(err) => return Err(format!("Could not open editor: {}", err)),
} }
#[cfg(not(target_os = "windows"))]
if let Some(ctx) = self.context.as_mut() { if let Some(ctx) = self.context.as_mut() {
// Clear screen // Clear screen
ctx.clear_screen(); ctx.clear_screen();
+2
View File
@@ -115,6 +115,7 @@ impl SetupActivity {
error!("Failed to disable raw mode: {}", err); error!("Failed to disable raw mode: {}", err);
} }
// Leave alternate mode // Leave alternate mode
#[cfg(not(target_os = "windows"))]
if let Some(ctx) = self.context.as_mut() { if let Some(ctx) = self.context.as_mut() {
ctx.leave_alternate_screen(); ctx.leave_alternate_screen();
} }
@@ -149,6 +150,7 @@ impl SetupActivity {
} }
} }
// Restore terminal // Restore terminal
#[cfg(not(target_os = "windows"))]
if let Some(ctx) = self.context.as_mut() { if let Some(ctx) = self.context.as_mut() {
// Clear screen // Clear screen
ctx.clear_screen(); ctx.clear_screen();
+2
View File
@@ -92,6 +92,7 @@ impl SetupActivity {
error!("Failed to disable raw mode: {}", err); error!("Failed to disable raw mode: {}", err);
} }
// Leave alternate mode // Leave alternate mode
#[cfg(not(target_os = "windows"))]
ctx.leave_alternate_screen(); ctx.leave_alternate_screen();
// Get result // Get result
let result: Result<(), String> = match ctx.config_client.as_ref() { let result: Result<(), String> = match ctx.config_client.as_ref() {
@@ -121,6 +122,7 @@ impl SetupActivity {
// Clear screen // Clear screen
ctx.clear_screen(); ctx.clear_screen();
// Enter alternate mode // Enter alternate mode
#[cfg(not(target_os = "windows"))]
ctx.enter_alternate_screen(); ctx.enter_alternate_screen();
// Re-enable raw mode // Re-enable raw mode
if let Err(err) = enable_raw_mode() { if let Err(err) = enable_raw_mode() {
+7 -3
View File
@@ -103,6 +103,7 @@ impl Context {
/// ### enter_alternate_screen /// ### enter_alternate_screen
/// ///
/// Enter alternate screen (gui window) /// Enter alternate screen (gui window)
#[cfg(not(target_os = "windows"))]
pub fn enter_alternate_screen(&mut self) { pub fn enter_alternate_screen(&mut self) {
match execute!( match execute!(
self.terminal.backend_mut(), self.terminal.backend_mut(),
@@ -190,9 +191,12 @@ mod tests {
assert!(ctx.get_error().is_some()); assert!(ctx.get_error().is_some());
assert!(ctx.get_error().is_none()); assert!(ctx.get_error().is_none());
// Try other methods // Try other methods
ctx.enter_alternate_screen(); #[cfg(not(target_os = "windows"))]
ctx.clear_screen(); {
ctx.leave_alternate_screen(); ctx.enter_alternate_screen();
ctx.clear_screen();
ctx.leave_alternate_screen();
}
drop(ctx); drop(ctx);
} }
} }