Compare commits

...

1 Commits

Author SHA1 Message Date
jif-oai
9f8c85a4a7 fix: try to fix freezes of TUI 2026-01-26 23:16:56 +00:00
2 changed files with 37 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ fn codex_apps_mcp_server_config(config: &Config, auth: Option<&CodexAuth>) -> Mc
tool_timeout_sec: None,
enabled_tools: None,
disabled_tools: None,
scopes: None,
}
}

View File

@@ -248,7 +248,12 @@ impl<S: EventSource + Default + Unpin> TuiEventStream<S> {
Event::Paste(pasted) => Some(TuiEvent::Paste(pasted)),
Event::FocusGained => {
self.terminal_focused.store(true, Ordering::Relaxed);
// crossterm queries use the same global stdin reader that EventStream relies on.
// Drop/recreate the EventStream around any such query to avoid contention that can
// stall the UI on focus changes (e.g. after alt-tabbing back to the terminal).
self.broker.pause_events();
crate::terminal_palette::requery_default_colors();
self.broker.resume_events();
Some(TuiEvent::Draw)
}
Event::FocusLost => {
@@ -508,4 +513,35 @@ mod tests {
other => panic!("expected key event, got {other:?}"),
}
}
#[tokio::test(flavor = "current_thread")]
async fn focus_gained_recreates_event_source() {
let (broker, handle, _draw_tx, draw_rx, terminal_focused) = setup();
terminal_focused.store(false, Ordering::Relaxed);
let mut stream = make_stream(broker.clone(), draw_rx, terminal_focused.clone());
handle.send(Ok(Event::FocusGained));
let first = stream.next().await;
assert!(matches!(first, Some(TuiEvent::Draw)));
assert!(terminal_focused.load(Ordering::Relaxed));
{
let state = broker
.state
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
assert!(matches!(&*state, EventBrokerState::Start));
}
// Ensure the stream is still usable after the event source is recreated.
let expected_key = KeyEvent::new(KeyCode::Char('n'), KeyModifiers::NONE);
handle.send(Ok(Event::Key(expected_key)));
let second = stream.next().await;
match second {
Some(TuiEvent::Key(key)) => assert_eq!(key, expected_key),
other => panic!("expected key event, got {other:?}"),
}
}
}