Files
codex/codex-rs/tui/src/backend_banners/render.rs
T
Eric Traut 13a966fc65 Honor the system clock preference across more TUI timestamps (#47321)
## Why

Several TUI views hard-code 24-hour timestamps even when the detected system preference is 12-hour time.

## What changed

Use the existing `ClockFormat` preference for rate-limit and spend-control reset times, usage notices, backend banners, reset-credit expiration times, analytics timestamps, and expanded session details in the resume picker. Capture the preference when constructing views and preserve existing timezone handling, including analytics' UTC labels.

## Testing

Add coverage for midnight, noon, and next-day reset labels in both clock formats, plus 12-hour analytics rendering with UTC labels. Update snapshots for status, banners, usage notices, reset-credit details, and expanded sessions, including narrow-width layouts. Pin test fixtures to explicit clock formats for deterministic output.

GitOrigin-RevId: 73c36d603ddc4eb7800614650a14c6f2961f8b70
2026-09-22 16:23:59 +00:00

80 lines
2.9 KiB
Rust

//! Render backend-owned copy and ordered CTA labels with the shared inline banner UI.
use super::BackendBanner;
use super::BannerPresentation;
use super::actions::BannerAction;
use crate::app_event::AppEvent;
use crate::bottom_pane::ActionableBanner;
use crate::bottom_pane::BannerDismissal;
use crate::bottom_pane::SelectionItem;
use crate::clock_format::ClockFormat;
use chrono::DateTime;
use chrono::Local;
impl BackendBanner {
pub(crate) fn actionable_banner(&self, clock_format: ClockFormat) -> ActionableBanner {
let reset_time = self
.reset_at
.and_then(|timestamp| DateTime::from_timestamp(timestamp, /*nsecs*/ 0))
.map(|time| {
crate::status::format_reset_timestamp(
time.with_timezone(&Local),
Local::now(),
clock_format,
)
});
let copy = |text: &str| {
let text: String = text
.chars()
.filter(|c| !c.is_control() || *c == '\n')
.collect();
match reset_time.as_deref() {
Some(reset_time) => text.replace("{time}", reset_time),
None => text,
}
};
let actions = self
.ctas
.iter()
.filter_map(|cta| {
if cta.label.trim().is_empty()
|| cta.label.len() > 256
|| cta.label.chars().any(char::is_control)
{
return None;
}
let action = self.resolve_action(&cta.action)?;
Some(SelectionItem {
name: cta.label.clone(),
actions: vec![Box::new(move |tx| {
tx.send(match &action {
BannerAction::OpenUrl(url) => {
AppEvent::OpenUrlInBrowser { url: url.clone() }
}
BannerAction::NotifyOwner(credit_type) => {
AppEvent::SendAddCreditsNudgeEmail {
credit_type: *credit_type,
}
}
BannerAction::ResetUsage => AppEvent::OpenRateLimitResetCredits,
})
})],
dismiss_on_select: false,
..Default::default()
})
})
.collect::<Vec<_>>();
ActionableBanner {
title: copy(&self.title),
description: copy(&self.description),
actions,
dismissal: if self.presentation == BannerPresentation::Dismissible {
BannerDismissal::Dismissible
} else {
BannerDismissal::Persistent
},
..Default::default()
}
}
}