mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-24 00:53:37 +03:00
fix terminal paste bug, some cleanup
This commit is contained in:
parent
e87b7f9e49
commit
3a4ea0fd67
@ -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,
|
||||
);
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user