mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Probe Windows terminal colors without risking startup input (#40598)
## Why Windows Terminal and xterm.js can render a theme that differs from the underlying console color table. Querying that visible theme through OSC shares the console input queue with keystrokes, including input for security-sensitive startup prompts. ## What changed - Defer the Windows OSC color probe until protected startup decisions and the world-writable workspace scan have completed. - Preserve and replay unrelated console input records around the probe, while removing only valid OSC 10 and 11 replies and retaining the console palette as a fallback. - Require an explicit confirmation key after shortcuts select trust, sandbox, or world-writable warning choices, so a fragmented terminal reply cannot accept them. - Accept one- through four-digit OSC RGB components so the visible terminal palette is applied across supported response formats. ## Testing Added coverage for delayed startup scans, protected prompt confirmation, console-record replay, bracketed paste and malformed OSC preservation, RGB response parsing, and light-theme composer rendering. GitOrigin-RevId: b8ae456fe32c701ba3af31e9cc452fc4e8bffa22
This commit is contained in:
1 parent
1f5c9ba183
commit
70b5cfc73b
19 files changed
+1162
-149
No files matched your search
@@ -67,6 +67,17 @@ impl App {
|
||||
.any(|event| matches!(event, ThreadBufferedEvent::Request(_))))
|
||||
}
|
||||
|
||||
/// Wait until visible and queued startup decisions cannot consume a delayed OSC response.
|
||||
#[cfg(any(windows, test))]
|
||||
pub(super) fn ready_for_terminal_color_probe(&self, has_pending_app_events: bool) -> bool {
|
||||
!has_pending_app_events
|
||||
&& !self.chat_widget.has_active_view()
|
||||
&& !self.windows_sandbox.startup_world_writable_scan_pending
|
||||
&& !self.startup_pending_protected_request
|
||||
&& !self.has_queued_startup_protected_request()
|
||||
&& !self.chat_widget.has_pending_protected_request()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn run(
|
||||
tui: &mut tui::Tui,
|
||||
@@ -584,6 +595,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
.hide_world_writable_warning
|
||||
.unwrap_or(false);
|
||||
if should_check {
|
||||
app.windows_sandbox.startup_world_writable_scan_pending = true;
|
||||
let cwd = app.config.cwd.clone();
|
||||
let workspace_roots = app.config.effective_workspace_roots();
|
||||
let env_map: std::collections::HashMap<String, String> = std::env::vars().collect();
|
||||
@@ -596,6 +608,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
logs_base_dir,
|
||||
startup_permission_profile,
|
||||
tx,
|
||||
/*startup_scan*/ true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -625,6 +638,14 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
.restore_startup_draft_when_ready(&mut pending_startup_draft);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
let mut terminal_color_probe_pending = true;
|
||||
#[cfg(windows)]
|
||||
if app.ready_for_terminal_color_probe(!app_event_rx.is_empty()) {
|
||||
tui.probe_default_colors_after_protected_startup();
|
||||
terminal_color_probe_pending = false;
|
||||
}
|
||||
|
||||
let event_stream_started_at = Instant::now();
|
||||
tui.schedule_screen_size_recheck(Duration::ZERO);
|
||||
if let Err(err) = render_startup_frame(&mut app, tui) {
|
||||
@@ -802,6 +823,13 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
app.chat_widget
|
||||
.restore_startup_draft_when_ready(&mut pending_startup_draft);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if terminal_color_probe_pending
|
||||
&& app.ready_for_terminal_color_probe(!app_event_rx.is_empty())
|
||||
{
|
||||
tui.probe_default_colors_after_protected_startup();
|
||||
terminal_color_probe_pending = false;
|
||||
}
|
||||
}
|
||||
AppRunControl::Exit(reason) => break Ok(reason),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user