Restore the cursor shape when reedline exits (#574)

This commit is contained in:
nibon7 2023-04-25 02:08:24 +08:00 committed by GitHub
parent 3b60811f57
commit 86beb8793e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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},
};
@ -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();