From 86beb8793e9fa910eada7929f50ea78207590a69 Mon Sep 17 00:00:00 2001 From: nibon7 Date: Tue, 25 Apr 2023 02:08:24 +0800 Subject: [PATCH] Restore the cursor shape when reedline exits (#574) --- src/engine.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 8bcfc4c..29d7097 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -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();