mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
Refresh animated terminal titles without redrawing the TUI (#40618)
## Why Terminal title animations only need to update the title, but each animation tick previously requested a full TUI frame. ## What changed - Track the next terminal title refresh deadline on `ChatWidget`. - Have the foreground event loop refresh the title when that deadline expires. - Clear the deadline when title animations are disabled or the configured title is empty. ## Testing - Verify spinner and action-required animations set the expected refresh deadlines. - Verify refreshing an animated title does not enqueue a TUI draw request. GitOrigin-RevId: 269347cd48de4ad9ba9a0aef9ed105c25d1a7dae
This commit is contained in:
1 parent
ed42068c45
commit
6525b95dae
5 files changed
+56
-12
No files matched your search
@@ -6,8 +6,20 @@ use pretty_assertions::assert_eq;
|
||||
#[tokio::test]
|
||||
async fn terminal_title_shows_action_required_while_exec_approval_is_pending() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let (frame_requester, mut draw_rx) = FrameRequester::test_channel();
|
||||
chat.frame_requester = frame_requester;
|
||||
chat.bottom_pane.set_task_running(/*running*/ true);
|
||||
let before_refresh = Instant::now();
|
||||
chat.refresh_terminal_title();
|
||||
let spinner_interval = std::time::Duration::from_millis(/*millis*/ 100);
|
||||
assert!(
|
||||
(before_refresh + spinner_interval..=Instant::now() + spinner_interval)
|
||||
.contains(&chat.terminal_title_next_refresh.expect("spinner deadline"))
|
||||
);
|
||||
assert_eq!(
|
||||
draw_rx.try_recv(),
|
||||
Err(tokio::sync::mpsc::error::TryRecvError::Empty)
|
||||
);
|
||||
|
||||
let request = ExecApprovalRequestEvent {
|
||||
call_id: "call-action-required".into(),
|
||||
@@ -25,7 +37,17 @@ async fn terminal_title_shows_action_required_while_exec_approval_is_pending() {
|
||||
};
|
||||
handle_exec_approval_request(&mut chat, "sub-action-required", request);
|
||||
|
||||
let before_refresh = Instant::now();
|
||||
chat.terminal_title_animation_origin = before_refresh;
|
||||
chat.pre_draw_tick();
|
||||
let blink_interval = std::time::Duration::from_secs(/*secs*/ 1);
|
||||
assert!(
|
||||
(before_refresh + blink_interval..=Instant::now() + blink_interval).contains(
|
||||
&chat
|
||||
.terminal_title_next_refresh
|
||||
.expect("action-required deadline")
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
chat.last_terminal_title,
|
||||
@@ -43,6 +65,18 @@ async fn terminal_title_shows_action_required_while_exec_approval_is_pending() {
|
||||
assert!(title.contains("project"));
|
||||
assert!(!title.contains("Action Required"));
|
||||
assert!(chat.should_animate_terminal_title_spinner());
|
||||
|
||||
for (animations, title_items) in [(false, None), (true, Some(Vec::new()))] {
|
||||
chat.config.animations = true;
|
||||
chat.config.tui_terminal_title = None;
|
||||
chat.refresh_terminal_title();
|
||||
assert!(chat.terminal_title_next_refresh.is_some());
|
||||
|
||||
chat.config.animations = animations;
|
||||
chat.config.tui_terminal_title = title_items;
|
||||
chat.refresh_terminal_title();
|
||||
assert!(chat.terminal_title_next_refresh.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -78,7 +112,6 @@ async fn terminal_title_action_required_respects_spinner_setting() {
|
||||
async fn terminal_title_action_required_blinks_when_animations_are_enabled() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.bottom_pane.set_task_running(/*running*/ true);
|
||||
chat.terminal_title_animation_origin = Instant::now() - std::time::Duration::from_millis(1500);
|
||||
chat.refresh_terminal_title();
|
||||
|
||||
let request = ExecApprovalRequestEvent {
|
||||
@@ -97,6 +130,8 @@ async fn terminal_title_action_required_blinks_when_animations_are_enabled() {
|
||||
};
|
||||
handle_exec_approval_request(&mut chat, "sub-blink", request);
|
||||
|
||||
chat.terminal_title_animation_origin =
|
||||
Instant::now() - std::time::Duration::from_millis(/*millis*/ 1500);
|
||||
chat.pre_draw_tick();
|
||||
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user