Lightweight coding agent that runs in your terminal
Rust
Update and centralize TUI subscription labels (#49079)
Eric Trautfe50d010e203
diff --git a/codex-rs/tui/src/analytics/render.rs b/codex-rs/tui/src/analytics/render.rsindex 8f1263799b..7ed4b0ee90 100644--- a/codex-rs/tui/src/analytics/render.rs+++ b/codex-rs/tui/src/analytics/render.rs@@ -102,27 +102,10 @@ impl AnalyticsView {]).areas(inner);let account = self.live.as_ref().and_then(|live| live.account_label());- let plan = self.account.ready().map(|plan| {- use codex_protocol::account::PlanType;- match plan {- PlanType::Free => "Free",- PlanType::Go => "Go",- PlanType::Plus => "Plus",- PlanType::Pro => "Pro Extra",- PlanType::ProLite => "Pro Standard",- PlanType::ProMax => "Pro Max",- PlanType::Team- | PlanType::Business- | PlanType::SelfServeBusinessProLite- | PlanType::SelfServeBusinessUsageBased => "Business",- PlanType::Enterprise- | PlanType::Ent26- | PlanType::EnterpriseCbpAutomation- | PlanType::EnterpriseCbpUsageBased => "Enterprise",- PlanType::Edu | PlanType::EduPlus | PlanType::EduPro => "Education",- PlanType::Unknown => "Account",- }- });+ let plan = self+ .account+ .ready()+ .map(|plan| crate::subscription::SubscriptionDisplay::Analytics.label(*plan));let heading = Line::from(vec![plan.map(|plan| format!("Usage · {plan}")).unwrap_or_else(|| "Usage".into())diff --git a/codex-rs/tui/src/analytics/summary_panel.rs b/codex-rs/tui/src/analytics/summary_panel.rsindex 9ad2d4b8e5..2303b4a4c3 100644--- a/codex-rs/tui/src/analytics/summary_panel.rs+++ b/codex-rs/tui/src/analytics/summary_panel.rs@@ -56,27 +56,10 @@ impl AnalyticsView {));}}- let plan = self.account.ready().map(|plan| {- use codex_protocol::account::PlanType;- match plan {- PlanType::Free => "Free",- PlanType::Go => "Go",- PlanType::Plus => "Plus",- PlanType::Pro => "Pro Extra",- PlanType::ProLite => "Pro Standard",- PlanType::ProMax => "Pro Max",- PlanType::Team- | PlanType::Business- | PlanType::SelfServeBusinessProLite- | PlanType::SelfServeBusinessUsageBased => "Business",- PlanType::Ent26- | PlanType::EnterpriseCbpAutomation- | PlanType::EnterpriseCbpUsageBased- | PlanType::Enterprise => "Enterprise",- PlanType::Edu | PlanType::EduPlus | PlanType::EduPro => "Education",- PlanType::Unknown => "Account",- }- });+ let plan = self+ .account+ .ready()+ .map(|plan| crate::subscription::SubscriptionDisplay::Analytics.label(*plan));if let Some(plan) = plan {lines.push(center(plan.set_style(secondary_style()).into(),diff --git a/codex-rs/tui/src/lib.rs b/codex-rs/tui/src/lib.rsindex 1e04ab8575..8da049ef4f 100644--- a/codex-rs/tui/src/lib.rs+++ b/codex-rs/tui/src/lib.rs@@ -209,6 +209,7 @@ mod status;mod status_indicator_widget;mod streaming;mod style;+mod subscription;mod system_motion;mod task_mentions;mod temporary_structured_request;diff --git a/codex-rs/tui/src/status/helpers.rs b/codex-rs/tui/src/status/helpers.rsindex 8c45dfa984..2608273f57 100644--- a/codex-rs/tui/src/status/helpers.rs+++ b/codex-rs/tui/src/status/helpers.rs@@ -98,27 +98,9 @@ pub(crate) fn compose_account_display(}pub(crate) fn plan_type_display_name(plan_type: PlanType) -> String {- if plan_type == PlanType::EnterpriseCbpAutomation {- "Enterprise (Automation)".to_string()- } else if plan_type == PlanType::SelfServeBusinessProLite {- "Business Premium".to_string()- } else if plan_type.is_team_like() {- "Business".to_string()- } else if plan_type.is_business_like() {- "Enterprise".to_string()- } else if plan_type == PlanType::Pro {- "Pro Extra".to_string()- } else if plan_type == PlanType::ProMax {- "Pro Max".to_string()- } else if plan_type == PlanType::ProLite {- "Pro Standard".to_string()- } else if plan_type == PlanType::EduPlus {- "Edu Plus".to_string()- } else if plan_type == PlanType::EduPro {- "Edu Pro".to_string()- } else {- title_case(format!("{plan_type:?}").as_str())- }+ crate::subscription::SubscriptionDisplay::Status+ .label(plan_type)+ .to_string()}pub(crate) fn format_tokens_compact(value: i64) -> String {@@ -198,18 +180,6 @@ pub(crate) fn format_reset_timestamp(}}-fn title_case(s: &str) -> String {- if s.is_empty() {- return String::new();- }- let mut chars = s.chars();- let Some(first) = chars.next() else {- return String::new();- };- let rest = chars.as_str().to_ascii_lowercase();- first.to_uppercase().collect::<String>() + &rest-}-#[cfg(test)]mod tests {use super::*;@@ -233,9 +203,9 @@ mod tests {(PlanType::Free, "Free"),(PlanType::Go, "Go"),(PlanType::Plus, "Plus"),- (PlanType::Pro, "Pro Extra"),- (PlanType::ProLite, "Pro Standard"),- (PlanType::ProMax, "Pro Max"),+ (PlanType::Pro, "Pro 200"),+ (PlanType::ProLite, "Pro 100"),+ (PlanType::ProMax, "Pro 500"),(PlanType::Team, "Business"),(PlanType::SelfServeBusinessUsageBased, "Business"),(PlanType::Business, "Enterprise"),diff --git a/codex-rs/tui/src/subscription.rs b/codex-rs/tui/src/subscription.rsnew file mode 100644index 0000000000..ac288fe446--- /dev/null+++ b/codex-rs/tui/src/subscription.rs@@ -0,0 +1,38 @@+//! Subscription labels for TUI surfaces, preserving status-specific plan detail.++use codex_protocol::account::PlanType;++pub(crate) enum SubscriptionDisplay {+ Status,+ Analytics,+}++impl SubscriptionDisplay {+ pub(crate) fn label(&self, plan: PlanType) -> &'static str {+ match (plan, self) {+ (PlanType::Free, _) => "Free",+ (PlanType::Go, _) => "Go",+ (PlanType::Plus, _) => "Plus",+ (PlanType::Pro, _) => "Pro 200",+ (PlanType::ProLite, _) => "Pro 100",+ (PlanType::ProMax, _) => "Pro 500",+ (PlanType::Team | PlanType::SelfServeBusinessUsageBased, _) => "Business",+ (PlanType::Business, Self::Status) => "Enterprise",+ (PlanType::SelfServeBusinessProLite, Self::Status) => "Business Premium",+ (PlanType::Business | PlanType::SelfServeBusinessProLite, Self::Analytics) => {+ "Business"+ }+ (PlanType::EnterpriseCbpAutomation, Self::Status) => "Enterprise (Automation)",+ (PlanType::EnterpriseCbpAutomation, Self::Analytics)+ | (PlanType::Enterprise | PlanType::Ent26 | PlanType::EnterpriseCbpUsageBased, _) => {+ "Enterprise"+ }+ (PlanType::Edu, Self::Status) => "Edu",+ (PlanType::EduPlus, Self::Status) => "Edu Plus",+ (PlanType::EduPro, Self::Status) => "Edu Pro",+ (PlanType::Edu | PlanType::EduPlus | PlanType::EduPro, Self::Analytics) => "Education",+ (PlanType::Unknown, Self::Status) => "Unknown",+ (PlanType::Unknown, Self::Analytics) => "Account",+ }+ }+}