mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve TUI status timing when the status row is hidden (#41913)
## Why Streaming can temporarily hide the status row, but its elapsed time is still needed when the row returns and when the final `Worked for` duration falls back to the local clock. Approval prompts must also keep that clock paused. ## What changed - Own the pause-aware status timer in the bottom pane independently of the optional status row. - Preserve elapsed time and modal pause state while hiding or restoring the row, and reset the clock for new turns and Windows sandbox setup. - Use the independent timer as the fallback for the final turn duration. ## Testing Add timer unit coverage and TUI tests for hidden rows, outstanding approvals, fallback turn durations, and fresh Windows sandbox setup clocks. GitOrigin-RevId: a77931e465d5aedd4a8cd606a3a3117d1bb37ce7
This commit is contained in:
1 parent
5f79a92e39
commit
17e8101699
10 files changed
+295
-147
No files matched your search
@@ -1,6 +1,6 @@
|
||||
//! A live task status row rendered above the composer while the agent is busy.
|
||||
//!
|
||||
//! The row owns spinner timing, the optional interrupt hint, and short inline
|
||||
//! The row renders a separately owned clock, the optional interrupt hint, and short inline
|
||||
//! context (for example, the unified-exec background-process summary). Keeping
|
||||
//! these pieces on one line avoids vertical layout churn in the bottom pane.
|
||||
|
||||
@@ -32,6 +32,9 @@ use crate::tui::FrameRequester;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::word_wrap_lines;
|
||||
|
||||
mod timer;
|
||||
pub(crate) use timer::StatusTimer;
|
||||
|
||||
pub(crate) const STATUS_DETAILS_DEFAULT_MAX_LINES: usize = 3;
|
||||
const DETAILS_PREFIX: &str = " └ ";
|
||||
|
||||
@@ -52,9 +55,6 @@ pub(crate) struct StatusIndicatorWidget {
|
||||
show_interrupt_hint: bool,
|
||||
interrupt_binding: Option<ShortcutHint>,
|
||||
|
||||
elapsed_running: Duration,
|
||||
last_resume_at: Instant,
|
||||
is_paused: bool,
|
||||
app_event_tx: AppEventSender,
|
||||
frame_requester: FrameRequester,
|
||||
animations_enabled: bool,
|
||||
@@ -90,10 +90,6 @@ impl StatusIndicatorWidget {
|
||||
inline_message: None,
|
||||
show_interrupt_hint: true,
|
||||
interrupt_binding: Some(key_hint::plain(KeyCode::Esc).into()),
|
||||
elapsed_running: Duration::ZERO,
|
||||
last_resume_at: Instant::now(),
|
||||
is_paused: false,
|
||||
|
||||
app_event_tx,
|
||||
frame_requester,
|
||||
animations_enabled,
|
||||
@@ -156,45 +152,8 @@ impl StatusIndicatorWidget {
|
||||
self.interrupt_binding = binding;
|
||||
}
|
||||
|
||||
pub(crate) fn pause_timer(&mut self) {
|
||||
self.pause_timer_at(Instant::now());
|
||||
}
|
||||
|
||||
pub(crate) fn resume_timer(&mut self) {
|
||||
self.resume_timer_at(Instant::now());
|
||||
}
|
||||
|
||||
pub(crate) fn pause_timer_at(&mut self, now: Instant) {
|
||||
if self.is_paused {
|
||||
return;
|
||||
}
|
||||
self.elapsed_running += now.saturating_duration_since(self.last_resume_at);
|
||||
self.is_paused = true;
|
||||
}
|
||||
|
||||
pub(crate) fn resume_timer_at(&mut self, now: Instant) {
|
||||
if !self.is_paused {
|
||||
return;
|
||||
}
|
||||
self.last_resume_at = now;
|
||||
self.is_paused = false;
|
||||
self.frame_requester.schedule_frame();
|
||||
}
|
||||
|
||||
fn elapsed_duration_at(&self, now: Instant) -> Duration {
|
||||
let mut elapsed = self.elapsed_running;
|
||||
if !self.is_paused {
|
||||
elapsed += now.saturating_duration_since(self.last_resume_at);
|
||||
}
|
||||
elapsed
|
||||
}
|
||||
|
||||
fn elapsed_seconds_at(&self, now: Instant) -> u64 {
|
||||
self.elapsed_duration_at(now).as_secs()
|
||||
}
|
||||
|
||||
pub fn elapsed_seconds(&self) -> u64 {
|
||||
self.elapsed_seconds_at(Instant::now())
|
||||
pub(crate) fn with_timer<'a>(&'a self, timer: &'a StatusTimer) -> impl Renderable + 'a {
|
||||
StatusIndicator { row: self, timer }
|
||||
}
|
||||
|
||||
/// Wrap the details text into a fixed width and return the lines, truncating if necessary.
|
||||
@@ -230,9 +189,14 @@ impl StatusIndicatorWidget {
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for StatusIndicatorWidget {
|
||||
struct StatusIndicator<'a> {
|
||||
row: &'a StatusIndicatorWidget,
|
||||
timer: &'a StatusTimer,
|
||||
}
|
||||
|
||||
impl Renderable for StatusIndicator<'_> {
|
||||
fn desired_height(&self, width: u16) -> u16 {
|
||||
1 + u16::try_from(self.wrapped_details_lines(width).len()).unwrap_or(0)
|
||||
1 + u16::try_from(self.row.wrapped_details_lines(width).len()).unwrap_or(0)
|
||||
}
|
||||
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
@@ -240,31 +204,32 @@ impl Renderable for StatusIndicatorWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.animations_enabled {
|
||||
let row = self.row;
|
||||
if row.animations_enabled {
|
||||
// Schedule next animation frame.
|
||||
self.frame_requester
|
||||
row.frame_requester
|
||||
.schedule_frame_in(Duration::from_millis(32));
|
||||
}
|
||||
let now = Instant::now();
|
||||
let elapsed_duration = self.elapsed_duration_at(now);
|
||||
let elapsed_duration = self.timer.elapsed_at(now);
|
||||
let pretty_elapsed = fmt_elapsed_compact(elapsed_duration.as_secs());
|
||||
let motion_mode = MotionMode::from_animations_enabled(self.animations_enabled);
|
||||
let motion_mode = MotionMode::from_animations_enabled(row.animations_enabled);
|
||||
|
||||
let mut spans = Vec::with_capacity(5);
|
||||
if let Some(indicator) = activity_indicator(
|
||||
Some(self.last_resume_at),
|
||||
Some(self.timer.last_resume_at),
|
||||
motion_mode,
|
||||
ReducedMotionIndicator::Hidden,
|
||||
) {
|
||||
spans.push(indicator);
|
||||
spans.push(" ".into());
|
||||
}
|
||||
spans.extend(shimmer_text(&self.header, motion_mode));
|
||||
spans.extend(shimmer_text(&row.header, motion_mode));
|
||||
if !spans.is_empty() {
|
||||
spans.push(" ".into());
|
||||
}
|
||||
if self.show_interrupt_hint
|
||||
&& let Some(interrupt_binding) = self.interrupt_binding
|
||||
if row.show_interrupt_hint
|
||||
&& let Some(interrupt_binding) = row.interrupt_binding
|
||||
{
|
||||
spans.extend(vec![
|
||||
format!("({pretty_elapsed} • ").dim(),
|
||||
@@ -274,7 +239,7 @@ impl Renderable for StatusIndicatorWidget {
|
||||
} else {
|
||||
spans.push(format!("({pretty_elapsed})").dim());
|
||||
}
|
||||
if let Some(message) = &self.inline_message {
|
||||
if let Some(message) = &row.inline_message {
|
||||
// Keep optional context after elapsed/interrupt text so that core
|
||||
// interrupt affordances stay in a fixed visual location.
|
||||
spans.push(" · ".dim());
|
||||
@@ -288,7 +253,7 @@ impl Renderable for StatusIndicatorWidget {
|
||||
));
|
||||
if area.height > 1 {
|
||||
// If there is enough space, add the details lines below the header.
|
||||
let details = self.wrapped_details_lines(area.width);
|
||||
let details = row.wrapped_details_lines(area.width);
|
||||
let max_details = usize::from(area.height.saturating_sub(1));
|
||||
lines.extend(details.into_iter().take(max_details));
|
||||
}
|
||||
@@ -304,8 +269,6 @@ mod tests {
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::TestBackend;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -328,6 +291,7 @@ mod tests {
|
||||
fn renders_with_working_header() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let timer = StatusTimer::default();
|
||||
let w = StatusIndicatorWidget::new(
|
||||
tx,
|
||||
crate::tui::FrameRequester::test_dummy(),
|
||||
@@ -337,7 +301,7 @@ mod tests {
|
||||
// Render into a fixed-size test terminal and snapshot the backend.
|
||||
let mut terminal = Terminal::new(TestBackend::new(80, 2)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| w.render(f.area(), f.buffer_mut()))
|
||||
.draw(|f| w.with_timer(&timer).render(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
@@ -346,6 +310,7 @@ mod tests {
|
||||
fn renders_truncated() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let timer = StatusTimer::default();
|
||||
let w = StatusIndicatorWidget::new(
|
||||
tx,
|
||||
crate::tui::FrameRequester::test_dummy(),
|
||||
@@ -355,7 +320,7 @@ mod tests {
|
||||
// Render into a fixed-size test terminal and snapshot the backend.
|
||||
let mut terminal = Terminal::new(TestBackend::new(20, 2)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| w.render(f.area(), f.buffer_mut()))
|
||||
.draw(|f| w.with_timer(&timer).render(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
@@ -377,14 +342,14 @@ mod tests {
|
||||
w.set_interrupt_hint_visible(/*visible*/ false);
|
||||
|
||||
// Freeze time-dependent rendering (elapsed + spinner) to keep the snapshot stable.
|
||||
w.is_paused = true;
|
||||
w.elapsed_running = Duration::ZERO;
|
||||
let mut timer = StatusTimer::default();
|
||||
timer.pause_at(timer.last_resume_at);
|
||||
|
||||
// Prefix is 4 columns, so a width of 30 yields a content width of 26: one column
|
||||
// short of fitting the whole phrase (27 cols), forcing exactly one wrap without ellipsis.
|
||||
let mut terminal = Terminal::new(TestBackend::new(30, 3)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| w.render(f.area(), f.buffer_mut()))
|
||||
.draw(|f| w.with_timer(&timer).render(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
@@ -393,17 +358,17 @@ mod tests {
|
||||
fn renders_without_spinner_when_animations_disabled() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut w = StatusIndicatorWidget::new(
|
||||
let w = StatusIndicatorWidget::new(
|
||||
tx,
|
||||
crate::tui::FrameRequester::test_dummy(),
|
||||
/*animations_enabled*/ false,
|
||||
);
|
||||
w.is_paused = true;
|
||||
w.elapsed_running = Duration::ZERO;
|
||||
let mut timer = StatusTimer::default();
|
||||
timer.pause_at(timer.last_resume_at);
|
||||
|
||||
let mut terminal = Terminal::new(TestBackend::new(80, 1)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| w.render(f.area(), f.buffer_mut()))
|
||||
.draw(|f| w.with_timer(&timer).render(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
let line = terminal.backend().buffer().content()[..80]
|
||||
.iter()
|
||||
@@ -423,41 +388,16 @@ mod tests {
|
||||
/*animations_enabled*/ false,
|
||||
);
|
||||
w.set_interrupt_binding(Some(key_hint::plain(KeyCode::F(12)).into()));
|
||||
w.is_paused = true;
|
||||
w.elapsed_running = Duration::ZERO;
|
||||
let mut timer = StatusTimer::default();
|
||||
timer.pause_at(timer.last_resume_at);
|
||||
|
||||
let mut terminal = Terminal::new(TestBackend::new(80, 1)).expect("terminal");
|
||||
terminal
|
||||
.draw(|f| w.render(f.area(), f.buffer_mut()))
|
||||
.draw(|f| w.with_timer(&timer).render(f.area(), f.buffer_mut()))
|
||||
.expect("draw");
|
||||
insta::assert_snapshot!(terminal.backend());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timer_pauses_when_requested() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut widget = StatusIndicatorWidget::new(
|
||||
tx,
|
||||
crate::tui::FrameRequester::test_dummy(),
|
||||
/*animations_enabled*/ true,
|
||||
);
|
||||
|
||||
let baseline = Instant::now();
|
||||
widget.last_resume_at = baseline;
|
||||
|
||||
let before_pause = widget.elapsed_seconds_at(baseline + Duration::from_secs(5));
|
||||
assert_eq!(before_pause, 5);
|
||||
|
||||
widget.pause_timer_at(baseline + Duration::from_secs(5));
|
||||
let paused_elapsed = widget.elapsed_seconds_at(baseline + Duration::from_secs(10));
|
||||
assert_eq!(paused_elapsed, before_pause);
|
||||
|
||||
widget.resume_timer_at(baseline + Duration::from_secs(10));
|
||||
let after_resume = widget.elapsed_seconds_at(baseline + Duration::from_secs(13));
|
||||
assert_eq!(after_resume, before_pause + 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn details_overflow_adds_ellipsis() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
|
||||
Reference in new issue
Block a user