fix: request keyboard enhancement flags for proper Release events
Root cause of both issues: terminals don't send Release events by default. When pressing W while holding A, terminal stops repeating A (but doesn't send Release), so A times out and strafing breaks. On key release, 400ms timeout means 400ms of extra movement. Fix: PushKeyboardEnhancementFlags(REPORT_EVENT_TYPES) in terminal init. This asks the terminal to send proper Press/Release/Repeat events for ALL keys, not just special ones. With Release events: - Key release is instant (no 400ms timeout delay) - Pressing W doesn't cancel A's held state (terminal sends Release only when A is actually released) - A/D strafing works while W is held Fallback: if terminal doesn't support enhancement flags (old xterm), got_release flag stays false and 150ms timeout is used. Once any Release event is received, all keys switch to Release-based mode (infinite timeout, rely on actual Release events). 109 tests, 0 warnings, 0 failures
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::io::{self, Write, stdout};
|
||||
use crossterm::{
|
||||
cursor::{Hide, MoveTo, Show},
|
||||
event::{DisableMouseCapture, EnableMouseCapture},
|
||||
event::{DisableMouseCapture, EnableMouseCapture, KeyboardEnhancementFlags, PushKeyboardEnhancementFlags, PopKeyboardEnhancementFlags},
|
||||
execute, queue,
|
||||
style::{Color, SetBackgroundColor, SetForegroundColor, ResetColor, Print},
|
||||
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen, size as term_size},
|
||||
@@ -53,6 +53,10 @@ impl Renderer for TerminalRenderer {
|
||||
stdout(),
|
||||
EnterAlternateScreen,
|
||||
Hide,
|
||||
PushKeyboardEnhancementFlags(
|
||||
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
|
||||
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
|
||||
),
|
||||
EnableMouseCapture,
|
||||
Clear(ClearType::All),
|
||||
)?;
|
||||
@@ -169,6 +173,7 @@ impl Renderer for TerminalRenderer {
|
||||
stdout(),
|
||||
ResetColor,
|
||||
Show,
|
||||
PopKeyboardEnhancementFlags,
|
||||
LeaveAlternateScreen,
|
||||
DisableMouseCapture,
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user