aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/terminal_modes.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/terminal_modes.rs b/src/terminal_modes.rs
index 8f0276e0..90ec512b 100644
--- a/src/terminal_modes.rs
+++ b/src/terminal_modes.rs
@@ -1,5 +1,7 @@
use std::io::{self, Write};
+#[cfg(not(windows))]
+use crossterm::event::{PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags};
#[cfg(any(not(windows), test))]
const DISABLE_HOST_MOUSE_REPORTING_SEQUENCE: &[u8] =
b"\x1b[?1006l\x1b[?1016l\x1b[?1015l\x1b[?1005l\x1b[?1003l\x1b[?1002l\x1b[?1000l";
@@ -24,8 +26,13 @@ pub(crate) fn set_host_kitty_keyboard_report_all<W: Write>(
if report_all_keys {
flags |= crossterm::event::KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES;
}
- write!(writer, "\x1b[={}u", flags.bits())?;
- writer.flush()
+ // Older iTerm2 releases clear the keyboard stack on SET, so a later pop
+ // cannot restore the host state. Replace only Herdr's top entry instead.
+ crossterm::execute!(
+ writer,
+ PopKeyboardEnhancementFlags,
+ PushKeyboardEnhancementFlags(flags)
+ )
}
#[cfg(windows)]
@@ -41,13 +48,13 @@ mod tests {
use super::*;
#[test]
- fn host_keyboard_report_all_only_changes_the_current_herdr_stack_entry() {
+ fn host_keyboard_report_all_replaces_the_current_herdr_stack_entry() {
let mut output = Vec::new();
set_host_kitty_keyboard_report_all(&mut output, true).unwrap();
set_host_kitty_keyboard_report_all(&mut output, false).unwrap();
- assert_eq!(output, b"\x1b[=15u\x1b[=7u");
+ assert_eq!(output, b"\x1b[<1u\x1b[>15u\x1b[<1u\x1b[>7u");
}
#[test]