fix(tui): disable keyboard enhancements in wsl vscode

Centralize the keyboard-enhancement decision in
`codex-terminal-detection` and use it from both the main
TUI and `codex-cloud-tasks`. This also keeps the main
composer from advertising enhanced-key behavior when the
flags are intentionally disabled.

WSL users running inside the VS Code integrated terminal
can hit dead-key composition failures when Codex pushes
progressive keyboard enhancement flags. Disable those
flags in that environment and add coverage for the shared
policy.
This commit is contained in:
Felipe Coury
2026-04-03 13:06:33 -03:00
parent cc8fd0ff65
commit 0441bc180e
4 changed files with 121 additions and 17 deletions
+11 -8
View File
@@ -763,6 +763,7 @@ pub async fn run_main(cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> an
let backend = backend;
// Terminal setup
use codex_tui::should_enable_keyboard_enhancement;
use crossterm::ExecutableCommand;
use crossterm::event::DisableBracketedPaste;
use crossterm::event::EnableBracketedPaste;
@@ -781,14 +782,16 @@ pub async fn run_main(cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> an
stdout.execute(EnableBracketedPaste)?;
// Enable enhanced key reporting so Shift+Enter is distinguishable from Enter.
// Some terminals may not support these flags; ignore errors if enabling fails.
let _ = crossterm::execute!(
std::io::stdout(),
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
)
);
if should_enable_keyboard_enhancement() {
let _ = crossterm::execute!(
std::io::stdout(),
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
| KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS
)
);
}
let backend_ui = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend_ui)?;
terminal.clear()?;