Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore the cursor shape when reedline exits #574

Merged
merged 1 commit into from Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 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,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