Repository: atuinsh/atuin (language: rust)

Issue:
Terminal left in Enhanced Keyboard mode
## Behavior:
 - Open a new terminal that supports kitty protocol
 - Type the up arrow to start atuin's history search
 - Open neovim
 - Enter INSERT mode
 - Observe that capital letters print out invalid unicode sequences
    - The `SHIFT` key, for example, prints out a character on its own 

I believe this is because the terminal is left in Enhanced Keyboard mode, which changes the keycodes of characters.
Unfortunately, this totally breaks the functionality of many programs I use.

## Expected Behavior:
 - Open a new terminal that supports kitty protocol
 - Type the up arrow to start atuin's history search
 - Open neovim
 - Enter INSERT mode
 - Observe that capital letters print capital letters
 
It looks like Atuin recently enabled Enhanced Keyboard mode here: e129f7a93eb1bc595201a6ec57ba586b3d9d4419

## Version
`18.0.0`



Discussion / hints:

Fix patch:
diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs
index 1a94e36dd0d..5401a269e3f 100644
--- a/atuin/src/command/client/search/interactive.rs
+++ b/atuin/src/command/client/search/interactive.rs
@@ -794,6 +794,9 @@ impl Stdout {
 
 impl Drop for Stdout {
     fn drop(&mut self) {
+        #[cfg(not(target_os = "windows"))]
+        execute!(self.stdout, PopKeyboardEnhancementFlags).unwrap();
+
         if !self.inline_mode {
             execute!(self.stdout, terminal::LeaveAlternateScreen).unwrap();
         }
@@ -804,9 +807,6 @@ impl Drop for Stdout {
         )
         .unwrap();
 
-        #[cfg(not(target_os = "windows"))]
-        execute!(self.stdout, PopKeyboardEnhancementFlags).unwrap();
-
         terminal::disable_raw_mode().unwrap();
     }
 }


Test patch: