Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Keep TUI hints immediately above the composer (#47096)

Felipe Courye8cd975a55a1
diff --git a/codex-rs/tui/src/app/composer_hints_tests.rs b/codex-rs/tui/src/app/composer_hints_tests.rs
index 2ffdbfe692..bbbccf2674 100644
--- a/codex-rs/tui/src/app/composer_hints_tests.rs
+++ b/codex-rs/tui/src/app/composer_hints_tests.rs
@@ -26,16 +26,29 @@ fn quota(used_percent: i32) -> RateLimitSnapshot {
#[tokio::test]
async fn usage_notice_preserves_composer_geometry_and_restores_tip_on_recovery() -> Result<()> {
let mut snapshots = Vec::new();
- for (width, running, used_percent) in [(80, false, 92), (32, true, 101), (18, true, 95)] {
+ for (width, height, running, queued, used_percent) in [
+ (80, 10, false, false, 92),
+ (80, 12, true, false, 98),
+ (32, 10, true, false, 101),
+ (18, 10, true, false, 95),
+ (80, 18, true, true, 98),
+ (80, 11, true, true, 98),
+ (80, 6, true, false, 98),
+ ] {
let (mut app, mut events, _ops) = crate::app::tests::make_test_app_with_channels().await;
app.local_settings.tui.show_tooltips = !running;
app.local_settings.tui.animations = false;
app.transcript_cells
- .push(Arc::new(crate::history_cell::PlainHistoryCell::new(vec![
- "Conversation".into(),
- ])));
+ .push(Arc::new(crate::history_cell::PlainHistoryCell::new(
+ if running {
+ (0..20)
+ .map(|row| format!("Conversation row {row}").into())
+ .collect()
+ } else {
+ vec!["Conversation".into()]
+ },
+ )));
if running {
- app.chat_widget.apply_external_edit("draft stays".into());
app.chat_widget.handle_server_notification(
ServerNotification::TurnStarted(TurnStartedNotification {
thread_id: ThreadId::new().to_string(),
@@ -53,10 +66,28 @@ async fn usage_notice_preserves_composer_geometry_and_restores_tip_on_recovery()
/*replay_kind*/ None,
);
assert!(app.chat_widget.is_user_turn_pending_or_running());
+ if queued {
+ app.keymap.chat.edit_queued_message = vec![crate::key_hint::shift(KeyCode::Left)];
+ app.chat_widget
+ .apply_keymap_update(Default::default(), &app.keymap);
+ app.chat_widget
+ .apply_external_edit("queued follow-up".into());
+ app.chat_widget
+ .handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE));
+ assert_eq!(
+ app.chat_widget.queued_user_message_texts(),
+ vec!["queued follow-up"],
+ );
+ }
+ app.chat_widget.apply_external_edit(if queued {
+ "draft stays\nsecond line".into()
+ } else {
+ "draft stays".into()
+ });
}
let mut tui = crate::tui::test_support::make_test_tui()?;
tui.set_owned_screen(/*owned*/ true)?;
- let size = Size::new(width, /*height*/ 10);
+ let size = Size::new(width, height);
tui.terminal.resize(size)?;
let before = app.render_owned_transcript(&mut tui, size)?;
let cursor = tui.terminal.last_known_cursor_pos;
@@ -83,7 +114,9 @@ async fn usage_notice_preserves_composer_geometry_and_restores_tip_on_recovery()
})
.collect::<Vec<_>>()
.join("\n");
- snapshots.push(format!("{width} columns, running={running}\n{screen}"));
+ snapshots.push(format!(
+ "{width} columns, {height} rows, running={running}, queued={queued}\n{screen}"
+ ));
app.chat_widget
.on_rate_limit_snapshot(Some(quota(/*used_percent*/ 10)));
assert_eq!(app.composer_hint(width), tip);
@@ -388,7 +421,7 @@ async fn hints_render_clickable_links_and_release_them_when_disabled() -> Result
tui.screen_size_for_event(&TuiEvent::Resize(size))?;
let bottom = app.render_owned_transcript(&mut tui, size)?;
let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal);
- let row = bottom.y - 1;
+ let row = bottom.y;
let rendered = (0..size.width)
.map(|column| strip_osc8(buffer[(column, row)].symbol()))
.collect::<String>();
diff --git a/codex-rs/tui/src/app/owned_transcript.rs b/codex-rs/tui/src/app/owned_transcript.rs
index 9d6c83f02d..e9ede1a999 100644
--- a/codex-rs/tui/src/app/owned_transcript.rs
+++ b/codex-rs/tui/src/app/owned_transcript.rs
@@ -1,6 +1,7 @@
//! Compose the owned transcript above the composer and route their selection gestures.
-//! Reserve a cleared row between transcript content and the composer. Slash suggestions overlay
-//! already-painted rows so opening or closing them leaves transcript geometry unchanged.
+//! Reserve a cleared row below activity and previews, immediately above the composer.
+//! Slash suggestions overlay already-painted rows so opening or closing them leaves transcript
+//! geometry unchanged.
//! Plain Enter returns an empty composer to latest after transcript interactions and prompt editing.
use super::*;
@@ -82,6 +83,9 @@ impl App {
self.sync_owned_transcript(screen_size.width);
let transcript_width = self.chat_widget.history_wrap_width(screen_size.width);
let composer_hint = self.composer_hint(transcript_width);
+ let composer_gap = (!self.chat_widget.has_active_view()
+ && !self.chat_widget.is_external_writer_view())
+ .then(crate::bottom_pane::ComposerGap::default);
let mut prompt_footer =
self.prompt_navigation_footer(screen_size.width.saturating_sub(/*rhs*/ 2));
let chat_widget = &self.chat_widget;
@@ -106,6 +110,7 @@ impl App {
} else {
crate::bottom_pane::CommandPopupPlacement::Overlay
},
+ composer_gap.as_ref(),
);
let dashboard_visible = chat_widget
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
@@ -138,22 +143,11 @@ impl App {
/*x*/ 0,
/*y*/ 0,
transcript_width,
- available.saturating_sub(/*rhs*/ 1),
+ available.saturating_sub(u16::from(composer_gap.is_none())),
),
frame.buffer,
&self.transcript_cells,
);
- let follow_area =
- (available > 0 && chat_widget.no_modal_or_popup_active()).then(|| {
- Rect::new(
- /*x*/ 0,
- available - 1,
- transcript_width,
- /*height*/ 1,
- )
- });
- feedback_tick =
- view.render_composer_gap(follow_area, composer_hint.as_ref(), frame.buffer);
// Rendering resolves whether new activity is still hidden. Paint that result in
// this frame so a revision change cannot flash a stale activity hint.
let mut footer =
@@ -176,6 +170,7 @@ impl App {
} else {
crate::bottom_pane::CommandPopupPlacement::Overlay
},
+ composer_gap.as_ref(),
);
footer_height_changed = !dashboard_visible
&& bottom
@@ -183,6 +178,24 @@ impl App {
.min(screen_size.height)
!= bottom_height;
bottom.render(bottom_area, frame.buffer);
+ let follow_area = if let Some(gap) = composer_gap.as_ref() {
+ Some(Rect {
+ width: transcript_width,
+ ..gap.area.get()
+ })
+ } else {
+ (available > 0).then(|| {
+ Rect::new(
+ /*x*/ 0,
+ available - 1,
+ transcript_width,
+ /*height*/ 1,
+ )
+ })
+ }
+ .filter(|_| chat_widget.no_modal_or_popup_active());
+ feedback_tick =
+ view.render_composer_gap(follow_area, composer_hint.as_ref(), frame.buffer);
chat_widget.note_rendered_width(screen_size.width);
rendered_cursor = bottom.cursor_pos(bottom_area);
if let Some(position) = rendered_cursor {
diff --git a/codex-rs/tui/src/app/owned_transcript_follow_tests.rs b/codex-rs/tui/src/app/owned_transcript_follow_tests.rs
index b83af5ab36..e4a364a9bd 100644
--- a/codex-rs/tui/src/app/owned_transcript_follow_tests.rs
+++ b/codex-rs/tui/src/app/owned_transcript_follow_tests.rs
@@ -10,6 +10,7 @@ use pretty_assertions::assert_eq;
#[tokio::test]
async fn follow_control_click_preserves_draft_caret_and_composer_geometry() -> Result<()> {
let mut app = crate::app::test_support::make_test_app().await;
+ app.local_settings.tui.animations = false;
let mut server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
tui.set_owned_screen(/*owned*/ true)?;
@@ -20,7 +21,27 @@ async fn follow_control_click_preserves_draft_caret_and_composer_geometry() -> R
.map(|row| format!("transcript row {row}").into())
.collect(),
))];
- for width in [80, 40] {
+ for (width, running) in [(80, false), (40, false), (80, true)] {
+ if running {
+ app.chat_widget.handle_server_notification(
+ codex_app_server_protocol::ServerNotification::TurnStarted(
+ codex_app_server_protocol::TurnStartedNotification {
+ thread_id: ThreadId::new().to_string(),
+ turn: codex_app_server_protocol::Turn {
+ id: "turn".into(),
+ items_view: codex_app_server_protocol::TurnItemsView::Full,
+ items: Vec::new(),
+ status: codex_app_server_protocol::TurnStatus::InProgress,
+ error: None,
+ started_at: None,
+ completed_at: None,
+ duration_ms: None,
+ },
+ },
+ ),
+ /*replay_kind*/ None,
+ );
+ }
let size = Size::new(width, /*height*/ 12);
tui.screen_size_for_event(&TuiEvent::Resize(size))?;
app.transcript_view.jump_to_latest();
@@ -51,9 +72,19 @@ async fn follow_control_click_preserves_draft_caret_and_composer_geometry() -> R
);
}
let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal);
- let row = bottom.y - 1;
- let column = (0..width)
- .find(|column| buffer[(*column, row)].symbol() == "↓")
+ if running {
+ insta::assert_snapshot!(
+ "running_follow_control",
+ crate::chatwidget::tests::helpers::normalize_snapshot_paths(
+ super::tests::buffer_text(buffer)
+ ),
+ );
+ }
+ let (column, row) = buffer
+ .content()
+ .iter()
+ .position(|cell| cell.symbol() == "↓")
+ .map(|index| buffer.pos_of(index))
.expect("return control");
for interrupted in [true, false] {
for kind in [
diff --git a/codex-rs/tui/src/app/owned_transcript_tests.rs b/codex-rs/tui/src/app/owned_transcript_tests.rs
index 057885cac3..26b304e377 100644
--- a/codex-rs/tui/src/app/owned_transcript_tests.rs
+++ b/codex-rs/tui/src/app/owned_transcript_tests.rs
@@ -58,7 +58,7 @@ fn attach_thread(app: &mut App, thread_id: ThreadId) {
});
}
-fn buffer_text(buffer: &Buffer) -> String {
+pub(super) fn buffer_text(buffer: &Buffer) -> String {
buffer
.content()
.chunks(usize::from(buffer.area.width))
@@ -235,7 +235,7 @@ async fn owned_transcript_reserves_a_row_above_the_composer() -> Result<()> {
));
continue;
}
- let gap = Rect::new(/*x*/ 0, bottom.y - 1, width, /*height*/ 1);
+ let gap = Rect::new(/*x*/ 0, bottom.y, width, /*height*/ 1);
let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal);
let start = buffer.index_of(gap.x, gap.y);
// Both scenarios show the current tail, including the paused detailed view.
@@ -375,6 +375,7 @@ async fn owned_details_keep_the_composer_cursor_and_screen() -> Result<()> {
.bottom_pane_renderable(
/*footer*/ None,
crate::bottom_pane::CommandPopupPlacement::Overlay,
+ Some(&crate::bottom_pane::ComposerGap::default()),
)
.cursor_pos(bottom_area)
.expect("composer cursor");
@@ -1009,6 +1010,8 @@ async fn slash_picker_overlays_history_without_moving_the_transcript_or_composer
let before =
crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal).clone();
+ // Suggestions may cover the gap, but not the single-line composer's top padding.
+ let composer_y = cursor.y.saturating_sub(/*rhs*/ 1);
// Changing the token reopens the menu dismissed above.
app.chat_widget.apply_external_edit("/mo".to_string());
app.chat_widget.apply_external_edit("/m".to_string());
@@ -1017,7 +1020,7 @@ async fn slash_picker_overlays_history_without_moving_the_transcript_or_composer
let open =
crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal).clone();
let open_text = buffer_text(&open);
- if bottom.y > 0 {
+ if composer_y > 0 {
let menu_y = open_text
.lines()
.position(|line| line.contains("› /model"))
@@ -1029,7 +1032,7 @@ async fn slash_picker_overlays_history_without_moving_the_transcript_or_composer
);
assert_ne!(open, before);
}
- let composer_start = open.index_of(bottom.x, bottom.y);
+ let composer_start = open.index_of(bottom.x, composer_y);
assert_eq!(
&open.content()[composer_start..],
&before.content()[composer_start..]
@@ -1046,9 +1049,9 @@ async fn slash_picker_overlays_history_without_moving_the_transcript_or_composer
assert_eq!(
filtered
.lines()
- .take(usize::from(bottom.y))
+ .take(usize::from(composer_y))
.any(|line| line.contains("› /model")),
- bottom.y > 0,
+ composer_y > 0,
"a single command remains visible when the menu has room",
);
app.chat_widget.apply_external_edit("/m".to_string());
diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__composer_hints__tests__composer_usage_notice.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__composer_hints__tests__composer_usage_notice.snap
index 85f93b7813..deba777663 100644
--- a/codex-rs/tui/src/app/snapshots/codex_tui__app__composer_hints__tests__composer_usage_notice.snap
+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__composer_hints__tests__composer_usage_notice.snap
@@ -1,9 +1,8 @@
---
source: tui/src/app/composer_hints_tests.rs
-assertion_line: 87
expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(snapshots.join(\"\\n\\n\"))"
---
-80 columns, running=false
+80 columns, 10 rows, running=false, queued=false
Conversation
⚠ Heads up, you have less than 10% of your 5h limit left. Run /status for a
@@ -15,26 +14,81 @@ Conversation
GPT-5.6-Sol default · /tmp/project
? for shortcuts ⚠ 1 warning · f2 to view
-32 columns, running=true
- 5% of your 5h limit left.
+80 columns, 12 rows, running=true, queued=false
+
+⚠ Heads up, you have less than 5% of your 5h limit left. Run /status for a
+ breakdown.
+
+• Working (0s • esc to interrupt)
+
+ ⚠ 5h limit: only 2% left · /status
+
+› draft stays
+
+ GPT-5.6-Sol default · /tmp/project
+ tab to queue message
+
+32 columns, 10 rows, running=true, queued=false
Run /status for a breakdown.
- ⚠ 5h limit: only <1% left
+
• Working (0s • esc to interrup…
+ ⚠ 5h <1% left
› draft stays
GPT-5.6-Sol default · /tmp/pr…
tab to queue message
-18 columns, running=true
- Run /status for
+18 columns, 10 rows, running=true, queued=false
a breakdown.
- ⚠ 5h 5% left
+
• Working (0s • e…
+ ⚠ 5h 5% left
› draft stays
GPT-5.6-Sol def…
tab to queue mes
+
+80 columns, 18 rows, running=true, queued=true
+Conversation row 18
+Conversation row 19
+
+⚠ Heads up, you have less than 5% of your 5h limit left. Run /status for a
+ breakdown.
+
+• Working (0s • esc to interrupt)
+
+• Queued follow-up inputs
+ ↳ queued follow-up
+ shift+← edit last queued message
+ ⚠ 5h limit: only 2% left · /status
+
+› draft stays
+ second line
+
+ GPT-5.6-Sol default · /tmp/project
+ tab to queue message
+
+80 columns, 11 rows, running=true, queued=true
+• Working (0s • esc to interrupt)
+
+• Queued follow-up inputs
+ ↳ queued follow-up
+ shift+← edit last queued message
+
+› draft stays
+ second line
+
+ GPT-5.6-Sol default · /tmp/project
+ tab to queue message
+
+80 columns, 6 rows, running=true, queued=false
+• Working (0s • esc to interrupt)
+
+› draft stays
+
+ GPT-5.6-Sol default · /tmp/project
+ tab to queue message
diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__follow_tests__running_follow_control.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__follow_tests__running_follow_control.snap
new file mode 100644
index 0000000000..76db613360
--- /dev/null
+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__follow_tests__running_follow_control.snap
@@ -0,0 +1,16 @@
+---
+source: tui/src/app/owned_transcript_follow_tests.rs
+expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(super::tests::buffer_text(buffer))"
+---
+transcript row 27
+transcript row 28
+transcript row 29
+
+• Working (0s • esc to interrupt)
+
+ ↓ Back to bottom · esc
+
+› draft stays here
+
+ GPT-5.6-Sol default · /tmp/project
+ tab to queue message
diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs
index 9c884f2ed3..769afb0a1b 100644
--- a/codex-rs/tui/src/app/tests.rs
+++ b/codex-rs/tui/src/app/tests.rs
@@ -8366,7 +8366,7 @@ async fn prompt_edit_reverts_earlier_and_first_visible_prompts_in_place() -> Res
let transcript = buffer
.content()
.chunks(usize::from(size.width))
- .take(usize::from(bottom.y.saturating_sub(/*rhs*/ 1)))
+ .take(usize::from(bottom.y))
.map(|row| {
row.iter()
.map(ratatui::buffer::Cell::symbol)
diff --git a/codex-rs/tui/src/app/tests/pagination_completion_tests.rs b/codex-rs/tui/src/app/tests/pagination_completion_tests.rs
index a6a30a13e8..424a1a01d8 100644
--- a/codex-rs/tui/src/app/tests/pagination_completion_tests.rs
+++ b/codex-rs/tui/src/app/tests/pagination_completion_tests.rs
@@ -225,12 +225,7 @@ async fn beginning_navigation_holds_the_view_until_the_last_page_arrives() -> Re
let render = |app: &mut App, tui: &mut tui::Tui| -> Result<Buffer> {
tui.screen_size_for_event(&TuiEvent::Resize(size))?;
let bottom = app.render_owned_transcript(tui, size)?;
- let area = Rect::new(
- /*x*/ 0,
- /*y*/ 0,
- size.width,
- bottom.y.saturating_sub(/*rhs*/ 1),
- );
+ let area = Rect::new(/*x*/ 0, /*y*/ 0, size.width, bottom.y);
let mut buffer = Buffer::empty(area);
app.transcript_view
.render(area, &mut buffer, &app.transcript_cells);
diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
index 18580a30b1..492f0f299e 100644
--- a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
+++ b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
@@ -62,6 +62,8 @@ pub(crate) enum CommandPopupPlacement {
/// A borrowed presentation shared by measurement, painting, and cursor placement.
#[derive(Clone, Copy, Default)]
pub(crate) struct ComposerRenderOptions<'a> {
+ /// Reserve a shared hint row independently of whether it currently contains a notice.
+ pub(crate) composer_gap: Option<&'a crate::bottom_pane::ComposerGap>,
pub(crate) warning_count: usize,
pub(crate) textarea_right_reserve: u16,
/// Keep configured status below the composer while hints occupy the final row.
diff --git a/codex-rs/tui/src/bottom_pane/composer_gap.rs b/codex-rs/tui/src/bottom_pane/composer_gap.rs
new file mode 100644
index 0000000000..1e1e962b1c
--- /dev/null
+++ b/codex-rs/tui/src/bottom_pane/composer_gap.rs
@@ -0,0 +1,25 @@
+//! Reserve the owned transcript's hint row immediately above the composer.
+//! The app paints its shared hints and reading controls into the per-frame layout rectangle.
+
+use std::cell::Cell;
+
+use ratatui::buffer::Buffer;
+use ratatui::layout::Rect;
+
+use crate::render::renderable::Renderable;
+
+#[derive(Default)]
+pub(crate) struct ComposerGap {
+ /// Filled during rendering; a fresh instance prevents reusing a hidden or clipped row.
+ pub(crate) area: Cell<Rect>,
+}
+
+impl Renderable for ComposerGap {
+ fn render(&self, area: Rect, _buf: &mut Buffer) {
+ self.area.set(area);
+ }
+
+ fn desired_height(&self, _width: u16) -> u16 {
+ 1
+ }
+}
diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs
index 8e9680a581..817fbace0b 100644
--- a/codex-rs/tui/src/bottom_pane/mod.rs
+++ b/codex-rs/tui/src/bottom_pane/mod.rs
@@ -15,9 +15,12 @@
//! hint. The pane schedules redraws so those hints can expire even when the UI is otherwise idle.
//! Inline banners sit above the composer. Number shortcuts apply only to an empty, idle composer;
//! drafts, paste bursts, and active dialogs keep their normal input routing.
+//! Owned transcripts separate activity from the transcript and reserve their shared hint row
+//! below activity and previews, above the composer.
pub(crate) use chat_composer::CommandPopupPlacement;
pub(crate) use chat_composer::ComposerRenderOptions;
pub(crate) use chat_composer::TranscriptFooter;
+pub(crate) use composer_gap::ComposerGap;
pub(crate) use footer::footer_hint_items_line;
pub(crate) use footer::inset_footer_hint_area;
use std::collections::VecDeque;
@@ -112,6 +115,7 @@ pub(crate) use status_line_style::status_line_from_segments;
pub(crate) use voice_strip::VoiceStripPhase;
pub(crate) use voice_strip::VoiceStripState;
mod bottom_pane_view;
+mod composer_gap;
mod effort_ignition;
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -2212,7 +2216,19 @@ impl BottomPane {
);
}
let mut flex2 = FlexRenderable::new();
- flex2.push(/*flex*/ 1, RenderableItem::Owned(flex.into()));
+ // Clip spacing and hints before activity and previews when the composer is tall.
+ let above_composer = if let Some(gap) = options.composer_gap {
+ let mut column = FlexRenderable::new();
+ if has_status_or_footer {
+ column.push(/*flex*/ 1, RenderableItem::Owned("".into()));
+ }
+ column.push(/*flex*/ 0, RenderableItem::Owned(flex.into()));
+ column.push(/*flex*/ 1, RenderableItem::Borrowed(gap));
+ column.into()
+ } else {
+ flex.into()
+ };
+ flex2.push(/*flex*/ 1, RenderableItem::Owned(above_composer));
let composer: RenderableItem<'_> = if let Some(questions) = question_editor {
RenderableItem::Borrowed(questions.as_ref())
} else if options.textarea_right_reserve == 0
@@ -2374,7 +2390,7 @@ mod tests {
lines.join("\n")
}
- fn render_snapshot(pane: &BottomPane, area: Rect) -> String {
+ fn render_snapshot(pane: &impl Renderable, area: Rect) -> String {
let mut buf = Buffer::empty(area);
pane.render(area, &mut buf);
snapshot_buffer(&buf)
diff --git a/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs b/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
index 855220962c..83ed170687 100644
--- a/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
+++ b/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
@@ -98,9 +98,17 @@ fn hidden_banner_preserves_input_before_render_and_after_resize() {
// Keys remain composer input before the first frame and after resizing a
// previously visible banner out of view.
- for render_hidden in [false, true] {
+ for (render_hidden, composer_gap) in [
+ (false, None),
+ (true, None),
+ (true, Some(super::super::ComposerGap::default())),
+ ] {
if render_hidden {
- let rendered = render_snapshot(&pane, hidden_area);
+ let renderable = pane.as_renderable_with_options(ComposerRenderOptions {
+ composer_gap: composer_gap.as_ref(),
+ ..Default::default()
+ });
+ let rendered = render_snapshot(&renderable, hidden_area);
assert!(!rendered.contains("View usage"));
}
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
@@ -110,7 +118,22 @@ fn hidden_banner_preserves_input_before_render_and_after_resize() {
assert!(pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
- let rendered = render_snapshot(&pane, visible_area);
+ let rendered = {
+ let renderable = pane.as_renderable_with_options(ComposerRenderOptions {
+ composer_gap: composer_gap.as_ref(),
+ ..Default::default()
+ });
+ render_snapshot(
+ &renderable,
+ Rect {
+ height: renderable.desired_height(width),
+ ..visible_area
+ },
+ )
+ };
+ if composer_gap.is_some() {
+ assert_snapshot!("actionable_banner_with_composer_gap", rendered);
+ }
assert!(rendered.contains("View usage"));
assert!(!pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
diff --git a/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__actionable_banner_with_composer_gap.snap b/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__actionable_banner_with_composer_gap.snap
new file mode 100644
index 0000000000..1ec65f6303
--- /dev/null
+++ b/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__actionable_banner_with_composer_gap.snap
@@ -0,0 +1,15 @@
+---
+source: tui/src/bottom_pane/tests/actionable_banner_tests.rs
+expression: rendered
+---
+
+ Usage limit reached
+
+› 1. View usage
+
+ Press a number to choose · esc to dismiss · type to continue
+
+
+› Ask Codex to do anything
+
+ esc esc to edit previous message
diff --git a/codex-rs/tui/src/chatwidget/rendering.rs b/codex-rs/tui/src/chatwidget/rendering.rs
index 3529fbe473..0017c65d76 100644
--- a/codex-rs/tui/src/chatwidget/rendering.rs
+++ b/codex-rs/tui/src/chatwidget/rendering.rs
@@ -125,6 +125,7 @@ impl ChatWidget {
return self.bottom_pane_renderable(
/*footer*/ None,
crate::bottom_pane::CommandPopupPlacement::AboveComposer,
+ /*composer_gap*/ None,
);
}
@@ -189,6 +190,7 @@ impl ChatWidget {
self.bottom_pane_renderable(
/*footer*/ None,
crate::bottom_pane::CommandPopupPlacement::AboveComposer,
+ /*composer_gap*/ None,
)
.inset(Insets::tlbr(
/*top*/ 1, /*left*/ 0, /*bottom*/ 0, /*right*/ 0,
@@ -200,11 +202,12 @@ impl ChatWidget {
/// Returns the composer, footer, and active modal without the live transcript above it.
///
/// Both transcript surfaces use this composition so read-only notices and cursor placement
- /// remain consistent. The caller owns any spacing between the transcript and this surface.
+ /// remain consistent. Owned transcripts reserve their shared hint row above the composer.
pub(crate) fn bottom_pane_renderable<'a>(
&'a self,
footer: Option<&'a crate::bottom_pane::TranscriptFooter>,
command_popup_placement: crate::bottom_pane::CommandPopupPlacement,
+ composer_gap: Option<&'a crate::bottom_pane::ComposerGap>,
) -> RenderableItem<'a> {
if self.external_writer_view && !self.bottom_pane.has_active_view() {
RenderableItem::Owned(Box::new(ExternalWriterNotice {
@@ -223,6 +226,7 @@ impl ChatWidget {
};
self.bottom_pane
.as_renderable_with_options(crate::bottom_pane::ComposerRenderOptions {
+ composer_gap,
warning_count: self.warning_display_state.count,
textarea_right_reserve: right_reserve,
separate_status_line: command_popup_placement
diff --git a/codex-rs/tui/src/chatwidget/rendering_tests.rs b/codex-rs/tui/src/chatwidget/rendering_tests.rs
index 59a28b577b..6271b1ecb1 100644
--- a/codex-rs/tui/src/chatwidget/rendering_tests.rs
+++ b/codex-rs/tui/src/chatwidget/rendering_tests.rs
@@ -86,6 +86,7 @@ async fn owned_bottom_pane_preserves_draft_cursor_and_read_only_notice() {
let bottom = widget.bottom_pane_renderable(
/*footer*/ None,
crate::bottom_pane::CommandPopupPlacement::Overlay,
+ /*composer_gap*/ None,
);
let mut buffer = Buffer::empty(area);
bottom.render(area, &mut buffer);
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__usage_notice_widths.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__usage_notice_widths.snap
index 6a57fea30b..9a408c543a 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__usage_notice_widths.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__usage_notice_widths.snap
@@ -1,11 +1,13 @@
---
source: tui/src/chatwidget/usage_notice_tests.rs
-assertion_line: 35
expression: "lines.join(\"\\n\")"
---
-47 columns: ⚠ 5h limit: 8% left · resets at 13:00 · /status
-46 columns: ⚠ 5h limit: 8% left · /status
-28 columns: ⚠ 5h limit: 8% left
-18 columns: ⚠ 5h 8% left
+94 columns: ⚠ 5h limit: 8% left · resets at 13:00 · /status
+93 columns: ⚠ 5h limit: 8% left · /status
+58 columns: ⚠ 5h limit: 8% left · /status
+57 columns: ⚠ 5h limit: 8% left
+38 columns: ⚠ 5h limit: 8% left
+37 columns: ⚠ 5h 8% left
12 columns: ⚠ 5h 8% left
11 columns:
+0 columns:
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__weekly_usage_notice_widths.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__weekly_usage_notice_widths.snap
new file mode 100644
index 0000000000..318dcd49b8
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__usage_notice__tests__weekly_usage_notice_widths.snap
@@ -0,0 +1,12 @@
+---
+source: tui/src/chatwidget/usage_notice_tests.rs
+expression: "lines.join(\"\\n\")"
+---
+132 columns: ⚠ weekly limit: only 2% left · resets at 12:00 on 21 Sep · /status
+131 columns: ⚠ weekly limit: only 2% left · /status
+76 columns: ⚠ weekly limit: only 2% left · /status
+75 columns: ⚠ weekly limit: only 2% left
+56 columns: ⚠ weekly limit: only 2% left
+55 columns: ⚠ weekly 2% left
+16 columns: ⚠ weekly 2% left
+15 columns:
diff --git a/codex-rs/tui/src/chatwidget/usage_notice.rs b/codex-rs/tui/src/chatwidget/usage_notice.rs
index 16785f7d17..6aff045fd4 100644
--- a/codex-rs/tui/src/chatwidget/usage_notice.rs
+++ b/codex-rs/tui/src/chatwidget/usage_notice.rs
@@ -1,6 +1,6 @@
//! Account quota state and composer notice, independent of one-time warning history.
//! Rolling updates retain metadata; fresh account reads replace windows and confirm recovery.
-//! Optional details yield to the quota summary when the composer gap is narrow.
+//! Details target half the composer gap; the shortest notice may use its full width.
use super::ChatWidget;
use super::rate_limits::RateLimitSnapshotSource;
@@ -57,15 +57,19 @@ impl UsageNoticeState {
if window.used_percent >= 90 {
style = style.bold();
}
+ let compact = Line::from(format!("⚠ {label} {remaining} left"));
+ // Prefer half the row, but keep a complete warning on narrow terminals.
+ let notice_width = (usize::from(width) / 2)
+ .max(compact.width())
+ .min(usize::from(width)) as u16;
let line = first_fitting_line(
[
- format!("{summary}{reset} · /status"),
- format!("{summary} · /status"),
- summary,
- format!("⚠ {label} {remaining} left"),
- ]
- .map(Line::from),
- width,
+ Line::from(format!("{summary}{reset} · /status")),
+ Line::from(format!("{summary} · /status")),
+ Line::from(summary),
+ compact,
+ ],
+ notice_width,
);
(!line.spans.is_empty()).then_some(line.style(style))
}
diff --git a/codex-rs/tui/src/chatwidget/usage_notice_tests.rs b/codex-rs/tui/src/chatwidget/usage_notice_tests.rs
index 187d317776..6351d28524 100644
--- a/codex-rs/tui/src/chatwidget/usage_notice_tests.rs
+++ b/codex-rs/tui/src/chatwidget/usage_notice_tests.rs
@@ -29,22 +29,45 @@ fn notice_time() -> DateTime<Local> {
#[test]
fn notice_details_fit_without_truncating_the_warning() {
let now = notice_time();
- let mut state = UsageNoticeState {
- primary: snapshot(/*used_percent*/ 92).primary,
- ..Default::default()
- };
- state.primary.as_mut().unwrap().resets_at =
- Some((now + chrono::Duration::hours(/*hours*/ 1)).timestamp());
- let mut lines = Vec::new();
- for width in [47, 46, 28, 18, 12, 11] {
- let line = state.line(width, now);
- assert!(
- line.as_ref()
- .is_none_or(|line| line.width() <= usize::from(width))
- );
- lines.push(format!("{width} columns: {}", line.unwrap_or_default()));
+ let mut primary = snapshot(/*used_percent*/ 92).primary.unwrap();
+ primary.resets_at = Some((now + chrono::Duration::hours(/*hours*/ 1)).timestamp());
+ for (name, state, widths) in [
+ (
+ "usage_notice_widths",
+ UsageNoticeState {
+ primary: Some(primary),
+ ..Default::default()
+ },
+ &[94, 93, 58, 57, 38, 37, 12, 11, 0][..],
+ ),
+ (
+ "weekly_usage_notice_widths",
+ UsageNoticeState {
+ secondary: Some(RateLimitWindow {
+ used_percent: 98,
+ window_duration_mins: Some(10080),
+ resets_at: Some((now + chrono::Duration::days(/*days*/ 1)).timestamp()),
+ }),
+ ..Default::default()
+ },
+ &[132, 131, 76, 75, 56, 55, 16, 15][..],
+ ),
+ ] {
+ let mut lines = Vec::new();
+ for &width in widths {
+ let line = state.line(width, now);
+ assert!(
+ line.as_ref()
+ .is_none_or(|line| line.width() <= usize::from(width))
+ );
+ lines.push(
+ format!("{width} columns: {}", line.unwrap_or_default())
+ .trim_end()
+ .to_owned(),
+ );
+ }
+ insta::assert_snapshot!(name, lines.join("\n"));
}
- insta::assert_snapshot!("usage_notice_widths", lines.join("\n"));
}
#[test]
@@ -66,7 +89,7 @@ fn notice_shows_only_valid_future_reset_times() {
] {
state.primary.as_mut().unwrap().resets_at = reset;
assert_eq!(
- state.line(/*width*/ 80, now),
+ state.line(/*width*/ 160, now),
Some(
Line::from(format!("⚠ 5h limit: 8% left{expected} · /status"))
.style(crate::style::warning_notice_style().bold())