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 24, 2023
1 parent f6b2342 commit 1db0d10
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
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,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 1db0d10

Please sign in to comment.