fix(input): avoid enabling CSI-u flags on Windows
Write the Kitty keyboard protocol probe (ESC[>0u) on Windows instead of enabling disambiguation flags that crossterm does not decode there. Fixes #1599.
This commit is contained in:
@@ -11,7 +11,6 @@ use crossterm::{
|
||||
event::{
|
||||
self, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
|
||||
EnableFocusChange, EnableMouseCapture, Event, KeyCode, KeyEventKind, KeyModifiers,
|
||||
KeyboardEnhancementFlags,
|
||||
},
|
||||
execute,
|
||||
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
|
||||
@@ -20,7 +19,9 @@ use crossterm::{
|
||||
// PushKeyboardEnhancementFlags / PopKeyboardEnhancementFlags commands are
|
||||
// never referenced, so the imports are gated to avoid -D warnings failures.
|
||||
#[cfg(not(windows))]
|
||||
use crossterm::event::{PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags};
|
||||
use crossterm::event::{
|
||||
KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
|
||||
};
|
||||
use ratatui::{
|
||||
Frame, Terminal,
|
||||
layout::{Constraint, Direction, Layout, Rect, Size},
|
||||
@@ -6324,11 +6325,12 @@ fn push_keyboard_enhancement_flags<W: Write>(writer: &mut W) {
|
||||
// returns Unsupported on Windows (is_ansi_code_supported() == false), so
|
||||
// the ANSI escape is written directly on that platform. Modern Windows
|
||||
// terminals (VSCode integrated terminal, Windows Terminal ≥1.17) honour
|
||||
// the kitty keyboard protocol; terminals that do not silently discard it.
|
||||
// the kitty keyboard protocol but crossterm's event reader does not
|
||||
// decode CSI u sequences on Windows (issue #1599). Write \033[>0u to
|
||||
// probe the protocol without enabling any flags — Enter stays as \n.
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let flags = KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES.bits();
|
||||
if let Err(err) = write!(writer, "\x1b[>{}u", flags).and_then(|()| writer.flush()) {
|
||||
if let Err(err) = write!(writer, "\x1b[>0u").and_then(|()| writer.flush()) {
|
||||
tracing::debug!(
|
||||
target: "kitty_keyboard",
|
||||
?err,
|
||||
|
||||
@@ -165,8 +165,8 @@ fn push_keyboard_flags_writes_kitty_push_sequence_on_windows() {
|
||||
push_keyboard_enhancement_flags(&mut buf);
|
||||
let seq = String::from_utf8_lossy(&buf);
|
||||
assert!(
|
||||
seq.contains("\x1b[>1u"),
|
||||
"push_keyboard_enhancement_flags must write kitty push (\\x1b[>1u) on Windows (#1359); got: {seq:?}"
|
||||
seq.contains("\x1b[>0u"),
|
||||
"push_keyboard_enhancement_flags must write kitty probe (\\x1b[>0u) on Windows (#1599); got: {seq:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user