Skip to content

Commit

Permalink
Restore the cursor shape when reedline exits
Browse files Browse the repository at this point in the history
  • Loading branch information
nibon7 committed Apr 22, 2023
1 parent f6b2342 commit 6c85aa0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/engine.rs
Expand Up @@ -30,9 +30,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 @@ -141,6 +142,15 @@ 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();
let _ignore = terminal::disable_raw_mode();
}

// 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 6c85aa0

Please sign in to comment.