From 3a4ea0fd679434617eb468520f147dd1a6293d6b Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Mon, 4 Mar 2024 19:12:56 -0300 Subject: [PATCH] fix terminal paste bug, some cleanup --- kinode/src/main.rs | 3 +-- kinode/src/terminal/mod.rs | 7 ++----- kinode/src/terminal/utils.rs | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index ffd26d49..6967518c 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -632,7 +632,6 @@ async fn main() { // abort all remaining tasks tasks.shutdown().await; - //let _ = crossterm::terminal::disable_raw_mode().unwrap(); let stdout = std::io::stdout(); let mut stdout = stdout.lock(); let _ = crossterm::execute!( @@ -640,7 +639,7 @@ async fn main() { crossterm::event::DisableBracketedPaste, crossterm::terminal::SetTitle(""), crossterm::style::SetForegroundColor(crossterm::style::Color::Red), - crossterm::style::Print(format!("\r\n{quit_msg}")), + crossterm::style::Print(format!("\r\n{quit_msg}\r\n")), crossterm::style::ResetColor, ); } diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 1dc186b1..c2f94330 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -29,10 +29,7 @@ impl RawMode { impl Drop for RawMode { fn drop(&mut self) { match disable_raw_mode() { - Ok(_) => { - // let is_enabled = crossterm::terminal::is_raw_mode_enabled(); - // println!("terminal: disabled raw mode successfully: {is_enabled:?}\r"); - } + Ok(_) => {} Err(e) => { println!("terminal: failed to disable raw mode: {e:?}\r"); } @@ -248,7 +245,7 @@ pub async fn terminal( // handle pasting of text from outside Event::Paste(pasted) => { current_line.insert_str(line_col, &pasted); - line_col = current_line.len(); + line_col = line_col + pasted.len(); cursor_col = std::cmp::min(line_col.try_into().unwrap_or(win_cols), win_cols); execute!( stdout, diff --git a/kinode/src/terminal/utils.rs b/kinode/src/terminal/utils.rs index 998971e9..59b4c252 100644 --- a/kinode/src/terminal/utils.rs +++ b/kinode/src/terminal/utils.rs @@ -29,8 +29,8 @@ impl CommandHistory { pub fn add(&mut self, line: String) { self.working_line = None; // only add line to history if it's not exactly the same - // as the previous line - if &line != self.lines.front().unwrap_or(&"".into()) { + // as the previous line and also not an empty line + if &line != self.lines.front().unwrap_or(&"".into()) && line != "" { let _ = writeln!(self.history_writer, "{}", &line); self.lines.push_front(line); }