Show actionable rate-limit banners in the TUI (#41742)

## What changed

- Carry optional backend-owned banner and account identity data through
  `account/rateLimits/read`, filtering banners that do not match the authenticated
  account and user.
- Render supported rate-limit notices above the composer with actions for usage,
  credits, resets, owner notifications, and plan management while preserving the
  existing fallback UI for absent or unsupported banners.
- Refresh usage after limit errors, reject stale responses, and keep queued input
  paused until recovery completes. When instructed by the banner, switch to the
  first available fallback model without changing unrelated thread settings.

## Testing

- Add protocol, banner parsing and rendering, CTA, identity filtering, refresh
  ordering, fallback-model, account-change, and queued-input recovery coverage.

GitOrigin-RevId: e03d75a82e425deb87f4b120a71cf2286c0ef6cc
This commit is contained in:
stefanstokic-oai authored and copyberry committed 2026-08-31 00:20:06 +00:00
1 parent 94cbbddafc
commit 79b04f1ab5
69 files changed
+3454 -69

No files matched your search

@@ -0,0 +1,259 @@
//! Shared title, description, and CTA content for banners in the TUI bottom pane.
//!
//! Workspace notices and backend banners share the existing selection list for CTA dispatch.
//! The inline wrapper owns presentation and dismissal while preserving normal composer input.
use super::BottomPane;
use super::BottomPaneView;
use super::SelectionItem;
use super::SelectionViewParams;
use super::list_selection_view::ListSelectionView;
use crate::render::Insets;
use crate::render::RectExt;
use crate::render::renderable::Renderable;
use crate::wrapping::word_wrap_lines;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyEventKind;
use crossterm::event::KeyModifiers;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Stylize;
use ratatui::text::Line;
use ratatui::widgets::Paragraph;
use ratatui::widgets::Widget;
use std::cell::Cell;
#[derive(Default)]
pub(crate) struct ActionableBanner {
pub(crate) title: String,
pub(crate) description: String,
pub(crate) actions: Vec<SelectionItem>,
pub(crate) initial_selected_idx: Option<usize>,
pub(crate) dismissal: BannerDismissal,
pub(crate) view_id: Option<&'static str>,
}
#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum BannerDismissal {
#[default]
Dismissible,
Persistent,
}
pub(super) struct InlineBanner {
content: InlineBannerContent,
dismissal: BannerDismissal,
shown: Cell<bool>,
// Current visibility is separate from whether this banner has ever been shown.
pub(super) visible: Cell<bool>,
dismissed: bool,
visible_action_count: Cell<usize>,
}
enum InlineBannerContent {
Actions(Box<ListSelectionView>),
Information {
header: Box<dyn Renderable>,
hint: Line<'static>,
},
}
impl Renderable for InlineBanner {
fn render(&self, area: Rect, buf: &mut Buffer) {
self.visible_action_count.set(0);
self.visible.set(!self.dismissed && !area.is_empty());
if !self.visible.get() {
return;
}
self.shown.set(true);
match &self.content {
InlineBannerContent::Actions(view) => {
view.render(area, buf);
self.visible_action_count.set(view.rendered_item_count());
}
InlineBannerContent::Information { header, hint } => {
let content = area.inset(Insets::tlbr(
/*top*/ 1, /*left*/ 2, /*bottom*/ 1, /*right*/ 2,
));
header.render(content, buf);
let y = content
.y
.saturating_add(header.desired_height(content.width) + 1);
if y < area.bottom() {
Renderable::render(
hint,
Rect::new(content.x, y, content.width, /*height*/ 1),
buf,
);
}
}
}
}
fn desired_height(&self, width: u16) -> u16 {
if self.dismissed {
return 0;
}
match &self.content {
InlineBannerContent::Actions(view) => view.desired_height(width),
InlineBannerContent::Information { header, hint } => {
header.desired_height(width.saturating_sub(4))
+ if hint.width() == 0 { 2 } else { 4 }
}
}
}
}
/// Multiline banner copy uses the same word wrapping for measurement and rendering.
struct BannerContent(Vec<Line<'static>>);
impl BannerContent {
fn wrapped_lines(&self, width: u16) -> Vec<Line<'static>> {
let mut lines = word_wrap_lines(&self.0, width as usize);
if lines.len() > 8 {
lines.truncate(7);
lines.push("…".dim().into());
}
lines
}
}
impl Renderable for BannerContent {
fn render(&self, area: Rect, buf: &mut Buffer) {
let lines = self.wrapped_lines(area.width);
Widget::render(Paragraph::new(lines), area, buf);
}
fn desired_height(&self, width: u16) -> u16 {
self.wrapped_lines(width).len() as u16
}
}
impl From<ActionableBanner> for SelectionViewParams {
fn from(banner: ActionableBanner) -> Self {
let lines = banner
.title
.lines()
.map(|line| Line::from(line.to_owned().bold()))
.chain(
banner
.description
.lines()
.map(|line| Line::from(line.to_owned().dim())),
)
.collect();
Self {
view_id: banner.view_id,
header: Box::new(BannerContent(lines)),
items: banner.actions,
initial_selected_idx: banner.initial_selected_idx,
..Default::default()
}
}
}
impl BottomPane {
pub(crate) fn show_actionable_banner(&mut self, banner: ActionableBanner) {
self.show_selection_view(banner.into());
}
/// Display a banner above the composer without interrupting active dialogs or losing a draft.
pub(crate) fn set_inline_banner(&mut self, banner: Option<ActionableBanner>) {
self.inline_banner = banner.map(|banner| {
let dismissal = banner.dismissal;
let has_actions = !banner.actions.is_empty();
let mut params: SelectionViewParams = banner.into();
params.allow_cancel = dismissal == BannerDismissal::Dismissible;
for item in &mut params.items {
item.dismiss_on_select = false;
}
let hint = match (dismissal, has_actions) {
(BannerDismissal::Persistent, true) => "Press a number to choose",
(BannerDismissal::Persistent, false) => "",
(BannerDismissal::Dismissible, true) => {
"Press a number to choose · esc to dismiss · type to continue"
}
(BannerDismissal::Dismissible, false) => "esc to dismiss · type to continue",
};
let hint: Line<'static> = hint.dim().into();
params.footer_hint = Some(hint.clone());
InlineBanner {
content: if has_actions {
InlineBannerContent::Actions(Box::new(ListSelectionView::new(
params,
self.app_event_tx.clone(),
self.keymap.list.clone(),
)))
} else {
InlineBannerContent::Information {
header: params.header,
hint,
}
},
dismissal,
shown: Cell::new(false),
visible: Cell::new(false),
dismissed: false,
visible_action_count: Cell::new(0),
}
});
self.request_redraw();
}
/// Observation for the owning controller; model hiding is not a dismissal.
pub(crate) fn inline_banner_lifecycle(&self) -> (bool, bool) {
self.inline_banner
.as_ref()
.map_or((false, false), |banner| {
(banner.shown.get(), banner.dismissed)
})
}
pub(super) fn inline_banner_accepts_dismissal(&self) -> bool {
self.inline_banner.as_ref().is_some_and(|banner| {
banner.visible.get()
&& !banner.dismissed
&& banner.dismissal == BannerDismissal::Dismissible
})
}
pub(super) fn handle_inline_banner_key(&mut self, key: KeyEvent) -> bool {
// Draft input, completion menus, and paste bursts retain all of their normal keys.
if !self.composer_is_empty()
|| self.composer.popup_active()
|| self.composer.is_in_paste_burst()
|| self.composer_should_handle_vim_insert_escape(key)
|| self.is_task_running
|| key.kind != KeyEventKind::Press
|| key.modifiers != KeyModifiers::NONE
{
return false;
}
let Some(banner) = self.inline_banner.as_mut() else {
return false;
};
if !banner.visible.get() || banner.dismissed {
return false;
}
match key.code {
KeyCode::Esc if banner.dismissal == BannerDismissal::Persistent => return false,
KeyCode::Esc => {
banner.dismissed = true;
}
KeyCode::Char(digit @ '1'..='9') => {
if digit as usize - '1' as usize >= banner.visible_action_count.get() {
return false;
}
let InlineBannerContent::Actions(view) = &mut banner.content else {
return false;
};
view.handle_key_event(key);
let _ = view.take_last_selected_index();
}
_ => return false,
}
self.request_redraw();
true
}
}
@@ -273,6 +273,7 @@ pub(crate) struct ListSelectionView {
name_column_width: Option<usize>,
filtered_indices: Vec<usize>,
last_selected_actual_idx: Option<usize>,
rendered_item_count: std::cell::Cell<usize>,
header: Box<dyn Renderable>,
initial_selected_idx: Option<usize>,
side_content: Box<dyn Renderable>,
@@ -408,6 +409,7 @@ impl ListSelectionView {
name_column_width: params.name_column_width,
filtered_indices: Vec::new(),
last_selected_actual_idx: None,
rendered_item_count: std::cell::Cell::new(0),
header,
initial_selected_idx: params.initial_selected_idx,
side_content: params.side_content,
@@ -1197,6 +1199,7 @@ impl Renderable for ListSelectionView {
}
fn render(&self, area: Rect, buf: &mut Buffer) {
self.rendered_item_count.set(0);
if area.height == 0 || area.width == 0 {
return;
}
@@ -1316,7 +1319,7 @@ impl Renderable for ListSelectionView {
width: effective_rows_width.max(1),
height: list_area.height,
};
match self.row_display {
let rendered_rows = match self.row_display {
SelectionRowDisplay::Wrapped => render_rows_with_col_width_mode(
render_area,
buf,
@@ -1336,6 +1339,7 @@ impl Renderable for ListSelectionView {
column_width,
),
};
self.rendered_item_count.set(rendered_rows.items);
}
// -- Side content (preview panel) --
@@ -1432,6 +1436,12 @@ impl Renderable for ListSelectionView {
}
}
impl ListSelectionView {
pub(crate) fn rendered_item_count(&self) -> usize {
self.rendered_item_count.get()
}
}
#[cfg(test)]
mod tests {
use super::*;
+116 -1
View File
@@ -13,6 +13,8 @@
//!
//! Some UI is time-based rather than input-based, such as the transient "press again to quit"
//! 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.
use std::collections::VecDeque;
use std::path::PathBuf;
@@ -55,6 +57,7 @@ use std::time::Duration;
use std::time::Instant;
mod action_required_title;
mod actionable_banner;
mod app_link_view;
mod apply_patch_header;
mod approval_overlay;
@@ -67,6 +70,8 @@ mod status_surface_preview;
mod title_setup;
pub(crate) use action_required_title::ACTION_REQUIRED_PREVIEW_PREFIX;
pub(crate) use action_required_title::build_action_required_title_text;
pub(crate) use actionable_banner::ActionableBanner;
pub(crate) use actionable_banner::BannerDismissal;
pub(crate) use app_link_view::AppLinkElicitationTarget;
pub(crate) use app_link_view::AppLinkSuggestionType;
pub(crate) use app_link_view::AppLinkView;
@@ -243,6 +248,7 @@ pub(crate) struct BottomPane {
/// Inline status indicator shown above the composer while a task is running.
status: Option<StatusIndicatorWidget>,
inline_banner: Option<actionable_banner::InlineBanner>,
/// Unified exec session summary source.
///
/// When a status row exists, this summary is mirrored inline in that row;
@@ -313,6 +319,7 @@ impl BottomPane {
disable_paste_burst,
is_task_running: false,
status: None,
inline_banner: None,
unified_exec_footer: UnifiedExecFooter::new(),
pending_input_preview: PendingInputPreview::new(),
pending_thread_approvals: PendingThreadApprovals::new(),
@@ -691,6 +698,9 @@ impl BottomPane {
self.request_redraw();
InputResult::None
} else {
if self.handle_inline_banner_key(key_event) {
return InputResult::None;
}
// If a task is running and a status line is visible, allow the
// configured action to interrupt even while the composer has focus.
// When a popup is active, prefer dismissing it over interrupting the task.
@@ -1461,7 +1471,10 @@ impl BottomPane {
/// overlays or popups and not running a task. This is the safe context to
/// use Esc-Esc for backtracking from the main view.
pub(crate) fn is_normal_backtrack_mode(&self) -> bool {
!self.is_task_running && self.view_stack.is_empty() && !self.composer.popup_active()
!self.is_task_running
&& self.view_stack.is_empty()
&& !self.composer.popup_active()
&& !self.inline_banner_accepts_dismissal()
}
/// Return true when no popups or modal views are active, regardless of task state.
@@ -1815,10 +1828,22 @@ impl BottomPane {
&'_ self,
composer_right_reserve: u16,
) -> RenderableItem<'_> {
if (self.is_task_running || !self.view_stack.is_empty())
&& let Some(banner) = &self.inline_banner
{
banner.visible.set(false);
}
if let Some(view) = self.active_view() {
RenderableItem::Borrowed(view)
} else {
let mut flex = FlexRenderable::new();
if let Some(banner) = self
.inline_banner
.as_ref()
.filter(|_| !self.is_task_running)
{
flex.push(/*flex*/ 0, RenderableItem::Borrowed(banner));
}
if let Some(status) = &self.status {
flex.push(/*flex*/ 0, RenderableItem::Borrowed(status));
}
@@ -1952,6 +1977,9 @@ impl Renderable for BottomPane {
#[cfg(test)]
mod tests {
#[path = "actionable_banner_tests.rs"]
mod actionable_banner_tests;
use super::*;
use crate::app::app_server_requests::ResolvedAppServerRequest;
use crate::app_command::AppCommand as Op;
@@ -2030,6 +2058,93 @@ mod tests {
})
}
#[test]
fn inline_banner_snapshot() {
let (tx, _rx) = unbounded_channel();
let mut pane = test_pane(AppEventSender::new(tx));
pane.set_inline_banner(Some(ActionableBanner {
title: "Choose how to continue working".to_string(),
description: "A long description wraps to fit the available terminal width.\n"
.repeat(/*n*/ 8),
actions: vec![
SelectionItem {
name: "Open usage settings".to_string(),
..Default::default()
},
SelectionItem {
name: "Notify owner".to_string(),
..Default::default()
},
],
..Default::default()
}));
let width = 44;
let area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.desired_height(width),
);
assert_snapshot!(
"inline_banner_wrapped_and_truncated",
render_snapshot(&pane, area)
);
assert!(!pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
assert!(pane.is_normal_backtrack_mode());
}
#[test]
fn backend_banner_snapshots_and_numbered_actions() {
for (kind, action, label) in [
("personal_limit", "view_usage", "View usage"),
("workspace_member_credits", "notify_owner", "Notify owner"),
] {
let banner = crate::backend_banners::BackendBanner::parse(&serde_json::json!({
"banner_type": kind,
"presentation": "dismissible",
"title": "Usage limit\u{7} reached",
"description": "Your included usage is depleted.\nChoose an action to continue.",
"ctas": [
{"action": "unsupported", "label": "Hidden action"},
{"action": "view_usage", "label": "Open usage settings"},
{"action": action, "label": label},
{"action": "view_usage", "label": "Extra action"}
]
}))
.expect("valid optional banner");
let (tx, mut rx) = unbounded_channel();
let mut pane = test_pane(AppEventSender::new(tx));
pane.set_inline_banner(Some(banner.actionable_banner()));
let width = 44;
let area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.desired_height(width),
);
assert_snapshot!(
format!("backend_banner_{kind}"),
render_snapshot(&pane, area)
);
pane.handle_key_event(KeyEvent::new(KeyCode::Char('2'), KeyModifiers::NONE));
let selected = match rx.try_recv().expect("numbered CTA dispatch") {
AppEvent::OpenUrlInBrowser { url } => url,
AppEvent::SendAddCreditsNudgeEmail { credit_type } => format!("{credit_type:?}"),
other => panic!("unexpected banner action: {other:?}"),
};
assert_eq!(
selected,
if action == "view_usage" {
"https://chatgpt.com/codex/settings/usage"
} else {
"Credits"
}
);
assert!(pane.inline_banner.is_some());
}
}
#[derive(Default)]
struct DismissibleView {
id: Option<&'static str>,
@@ -452,6 +452,12 @@ fn adjust_start_for_wrapped_selection_visibility(
/// and behavior for selection popups.
/// Returns the number of terminal lines actually rendered (including the
/// single-line empty placeholder when shown).
#[derive(Clone, Copy, Default)]
pub(crate) struct RenderedRows {
pub(crate) lines: u16,
pub(crate) items: usize,
}
fn render_rows_inner(
area: Rect,
buf: &mut Buffer,
@@ -460,18 +466,21 @@ fn render_rows_inner(
max_results: usize,
empty_message: &str,
column_width: ColumnWidthConfig,
) -> u16 {
) -> RenderedRows {
if rows_all.is_empty() {
if area.height > 0 {
Line::from(empty_message.dim().italic()).render(area, buf);
}
// Count the placeholder line only when there is vertical space to draw it.
return u16::from(area.height > 0);
return RenderedRows {
lines: u16::from(area.height > 0),
items: 0,
};
}
let max_items = max_results.min(rows_all.len());
if max_items == 0 {
return 0;
return RenderedRows::default();
}
let desc_measure_items = max_items.min(area.height.max(1) as usize);
@@ -499,6 +508,7 @@ fn render_rows_inner(
// shared description column. Stop when we run out of vertical space.
let mut cur_y = area.y;
let mut rendered_lines: u16 = 0;
let mut rendered_items = 0;
for (i, row) in rows_all.iter().enumerate().skip(start_idx).take(max_items) {
if cur_y >= area.y + area.height {
break;
@@ -513,6 +523,7 @@ fn render_rows_inner(
);
// Render the wrapped lines.
let mut rendered_item = false;
for line in wrapped {
if cur_y >= area.y + area.height {
break;
@@ -528,10 +539,17 @@ fn render_rows_inner(
);
cur_y = cur_y.saturating_add(1);
rendered_lines = rendered_lines.saturating_add(1);
rendered_item = true;
}
if rendered_item {
rendered_items += 1;
}
}
rendered_lines
RenderedRows {
lines: rendered_lines,
items: rendered_items,
}
}
/// Render a list of rows using the provided ScrollState, with shared styling
@@ -559,6 +577,7 @@ pub(crate) fn render_rows(
empty_message,
ColumnWidthConfig::default(),
)
.lines
}
/// Render a list of rows using the provided ScrollState and explicit
@@ -566,7 +585,7 @@ pub(crate) fn render_rows(
///
/// This is the low-level entry point for callers that need to thread a mode
/// through higher-level configuration.
/// Returns the number of terminal lines actually rendered.
/// Returns the terminal lines and selectable items actually rendered.
pub(crate) fn render_rows_with_col_width_mode(
area: Rect,
buf: &mut Buffer,
@@ -575,7 +594,7 @@ pub(crate) fn render_rows_with_col_width_mode(
max_results: usize,
empty_message: &str,
column_width: ColumnWidthConfig,
) -> u16 {
) -> RenderedRows {
render_rows_inner(
area,
buf,
@@ -609,10 +628,12 @@ pub(crate) fn render_rows_single_line(
empty_message,
ColumnWidthConfig::default(),
)
.lines
}
/// Render a list of rows as a single line each (no wrapping), truncating overflow with an
/// ellipsis while honoring the configured column width behavior.
/// Returns the terminal lines and selectable items actually rendered.
pub(crate) fn render_rows_single_line_with_col_width_mode(
area: Rect,
buf: &mut Buffer,
@@ -621,13 +642,16 @@ pub(crate) fn render_rows_single_line_with_col_width_mode(
max_results: usize,
empty_message: &str,
column_width: ColumnWidthConfig,
) -> u16 {
) -> RenderedRows {
if rows_all.is_empty() {
if area.height > 0 {
Line::from(empty_message.dim().italic()).render(area, buf);
}
// Count the placeholder line only when there is vertical space to draw it.
return u16::from(area.height > 0);
return RenderedRows {
lines: u16::from(area.height > 0),
items: 0,
};
}
let visible_items = max_results
@@ -686,7 +710,10 @@ pub(crate) fn render_rows_single_line_with_col_width_mode(
rendered_lines = rendered_lines.saturating_add(1);
}
rendered_lines
RenderedRows {
lines: rendered_lines,
items: rendered_lines as usize,
}
}
/// Compute the number of terminal rows required to render up to `max_results`
@@ -0,0 +1,18 @@
---
source: tui/src/bottom_pane/mod.rs
expression: "render_snapshot(&pane, area)"
---
Usage limit reached
Your included usage is depleted.
Choose an action to continue.
› 1. Open usage settings
2. View usage
3. Extra action
Press a number to choose · esc to dismiss
› Ask Codex to do anything
? for shortcuts 100% context left
@@ -0,0 +1,18 @@
---
source: tui/src/bottom_pane/mod.rs
expression: "render_snapshot(&pane, area)"
---
Usage limit reached
Your included usage is depleted.
Choose an action to continue.
› 1. Open usage settings
2. Notify owner
3. Extra action
Press a number to choose · esc to dismiss
› Ask Codex to do anything
? for shortcuts 100% context left
@@ -0,0 +1,22 @@
---
source: tui/src/bottom_pane/mod.rs
expression: "render_snapshot(&pane, area)"
---
Choose how to continue working
A long description wraps to fit the
available terminal width.
A long description wraps to fit the
available terminal width.
A long description wraps to fit the
available terminal width.
…
› 1. Open usage settings
2. Notify owner
Press a number to choose · esc to dismiss
› Ask Codex to do anything
? for shortcuts 100% context left
@@ -0,0 +1,170 @@
use super::super::actionable_banner::BannerDismissal;
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn hidden_banner_preserves_input_before_render_and_after_resize() {
let (tx, mut rx) = unbounded_channel();
let mut pane = test_pane_with_disable_paste_burst(
AppEventSender::new(tx),
/*disable_paste_burst*/ true,
);
pane.set_inline_banner(Some(ActionableBanner {
title: "Usage limit reached".into(),
actions: vec![SelectionItem {
name: "View usage".into(),
actions: vec![Box::new(|tx| {
tx.send(AppEvent::OpenUrlInBrowser {
url: "https://example.com/usage".into(),
});
})],
..Default::default()
}],
..Default::default()
}));
let width = 70;
let hidden_area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.composer.desired_height(width),
);
let visible_area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.desired_height(width),
);
// Keys remain composer input before the first frame and after resizing a
// previously visible banner out of view.
for render_hidden in [false, true] {
if render_hidden {
let rendered = render_snapshot(&pane, hidden_area);
assert!(!rendered.contains("View usage"));
}
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
assert_eq!(pane.composer_text(), "1");
assert!(rx.try_recv().is_err());
pane.set_composer_text(String::new(), Vec::new(), Vec::new());
assert!(pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
let rendered = render_snapshot(&pane, visible_area);
assert!(rendered.contains("View usage"));
assert!(!pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
assert_eq!(pane.composer_text(), "");
assert!(
matches!(rx.try_recv(), Ok(AppEvent::OpenUrlInBrowser { url })
if url == "https://example.com/usage")
);
}
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
assert!(pane.is_normal_backtrack_mode());
assert!(!render_snapshot(&pane, visible_area).contains("View usage"));
}
#[test]
fn partially_clipped_banner_preserves_hidden_action_shortcuts() {
let (tx, mut rx) = unbounded_channel();
let mut pane = test_pane_with_disable_paste_burst(
AppEventSender::new(tx),
/*disable_paste_burst*/ true,
);
pane.set_inline_banner(Some(ActionableBanner {
title: "Usage limit reached".into(),
actions: vec![SelectionItem {
name: "View usage".into(),
actions: vec![Box::new(|tx| {
tx.send(AppEvent::OpenUrlInBrowser {
url: "https://example.com/usage".into(),
});
})],
..Default::default()
}],
..Default::default()
}));
let width = 70;
let footer_only_area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.composer.desired_height(width) + 1,
);
let rendered = render_snapshot(&pane, footer_only_area);
assert!(!rendered.contains("View usage"));
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
assert_eq!(pane.composer_text(), "1");
assert!(rx.try_recv().is_err());
}
#[test]
fn banner_hidden_during_task_waits_for_redraw_before_accepting_dismissal() {
let (tx, _rx) = unbounded_channel();
let mut pane = test_pane(AppEventSender::new(tx));
pane.set_inline_banner(Some(ActionableBanner {
title: "Usage limit reached".into(),
..Default::default()
}));
let width = 70;
let area = Rect::new(
/*x*/ 0,
/*y*/ 0,
width,
pane.desired_height(width),
);
assert!(render_snapshot(&pane, area).contains("Usage limit reached"));
pane.set_task_running(/*running*/ true);
assert!(!render_snapshot(&pane, area).contains("Usage limit reached"));
pane.set_task_running(/*running*/ false);
assert!(pane.is_normal_backtrack_mode());
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
assert!(render_snapshot(&pane, area).contains("Usage limit reached"));
assert!(!pane.is_normal_backtrack_mode());
}
#[test]
fn information_banner_preserves_input_and_honors_dismissal() {
for dismissal in [BannerDismissal::Persistent, BannerDismissal::Dismissible] {
let (tx, _rx) = unbounded_channel();
let mut pane = test_pane_with_disable_paste_burst(
AppEventSender::new(tx),
/*disable_paste_burst*/ true,
);
pane.set_inline_banner(Some(ActionableBanner {
title: "Usage limit reached".into(),
description: "You can change models or request more usage.".into(),
dismissal,
..Default::default()
}));
let area = Rect::new(
/*x*/ 0,
/*y*/ 0,
/*width*/ 70,
pane.desired_height(/*width*/ 70),
);
let rendered = render_snapshot(&pane, area);
assert!(!rendered.contains("no matches"));
assert!(!rendered.contains("Press a number"));
assert_eq!(
rendered.contains("esc to dismiss"),
dismissal == BannerDismissal::Dismissible
);
if dismissal == BannerDismissal::Persistent {
assert_snapshot!("information_banner_persistent", rendered);
} else {
assert_snapshot!("information_banner_dismissible", rendered);
}
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
assert_eq!(
render_snapshot(&pane, area).contains("Usage limit reached"),
dismissal == BannerDismissal::Persistent
);
pane.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
assert_eq!(pane.composer_text(), "1");
}
}
@@ -0,0 +1,15 @@
---
source: tui/src/bottom_pane/tests/actionable_banner_tests.rs
assertion_line: 34
expression: rendered
---
Usage limit reached
You can change models or request more usage.
esc to dismiss · type to continue
› Ask Codex to do anything
? for shortcuts 100% context left
@@ -0,0 +1,13 @@
---
source: tui/src/bottom_pane/tests/actionable_banner_tests.rs
assertion_line: 32
expression: rendered
---
Usage limit reached
You can change models or request more usage.
› Ask Codex to do anything
? for shortcuts 100% context left