Skip to content

Commit

Permalink
Restore the cursor shape when reedline exits (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibon7 committed Apr 24, 2023
1 parent 3b60811 commit 86beb87
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/engine.rs
Expand Up @@ -33,9 +33,10 @@ use {
PromptHistorySearch, ReedlineMenu, Signal, UndoBehavior, ValidationResult, Validator,
},
crossterm::{
cursor::{SetCursorStyle, Show},
event,
event::{Event, KeyCode, KeyEvent, KeyModifiers},
terminal, Result,
terminal, QueueableCommand, Result,
},
std::{fs::File, io, io::Write, process::Command, time::Duration, time::SystemTime},
};
Expand Down Expand Up @@ -147,6 +148,14 @@ struct BufferEditor {

impl Drop for Reedline {
fn drop(&mut self) {
if self.cursor_shapes.is_some() {
let _ignore = terminal::enable_raw_mode();
let mut stdout = std::io::stdout();
let _ignore = stdout.queue(SetCursorStyle::DefaultUserShape);
let _ignore = stdout.queue(Show);
let _ignore = stdout.flush();
}

// Ensures that the terminal is in a good state if we panic semigracefully
// Calling `disable_raw_mode()` twice is fine with Linux
let _ignore = terminal::disable_raw_mode();
Expand Down

0 comments on commit 86beb87

Please sign in to comment.