From 6c85aa0eac9ada0a6d6fd2f01127371468b25f6c Mon Sep 17 00:00:00 2001 From: nibon7 Date: Sat, 22 Apr 2023 13:46:03 +0800 Subject: [PATCH] Restore the cursor shape when reedline exits --- src/engine.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 08cf5c1c..e963ae45 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -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}, }; @@ -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();