From 930abf46e8349e56ae35a036f4edf17bfe2a4f2f Mon Sep 17 00:00:00 2001 From: easong-openai Date: Mon, 25 Aug 2025 20:01:31 -0700 Subject: [PATCH] fmt --- codex-rs/tui/src/bottom_pane/chat_composer.rs | 108 +++++++++--------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 7a498a5fa7..61b4a23873 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -145,7 +145,11 @@ impl ChatComposer { self.textarea.desired_height(width - 1) + match &self.active_popup { ActivePopup::None => { - if self.token_usage_info.is_some() && width < 90 { 2 } else { 1 } + if self.token_usage_info.is_some() && width < 90 { + 2 + } else { + 1 + } } ActivePopup::Command(c) => c.calculate_required_height(), ActivePopup::File(c) => c.calculate_required_height(), @@ -156,7 +160,13 @@ impl ChatComposer { let popup_height = match &self.active_popup { ActivePopup::Command(popup) => popup.calculate_required_height(), ActivePopup::File(popup) => popup.calculate_required_height(), - ActivePopup::None => if self.token_usage_info.is_some() && area.width < 90 { 2 } else { 1 }, + ActivePopup::None => { + if self.token_usage_info.is_some() && area.width < 90 { + 2 + } else { + 1 + } + } }; let [textarea_rect, _] = Layout::vertical([Constraint::Min(1), Constraint::Max(popup_height)]).areas(area); @@ -1201,66 +1211,62 @@ impl WidgetRef for ChatComposer { hint.push(Span::from(" edit prev")); } - if !needs_tokens_line - && let Some(token_usage_info) = &self.token_usage_info { - let token_usage = &token_usage_info.total_token_usage; + if !needs_tokens_line && let Some(token_usage_info) = &self.token_usage_info { + let token_usage = &token_usage_info.total_token_usage; + hint.push(Span::from(" ")); + hint.push( + Span::from(format!("{} tokens used", token_usage.blended_total())) + .style(Style::default().add_modifier(Modifier::DIM)), + ); + let last_token_usage = &token_usage_info.last_token_usage; + if let Some(context_window) = token_usage_info.model_context_window { + let percent_remaining: u8 = if context_window > 0 { + last_token_usage.percent_of_context_window_remaining( + context_window, + token_usage_info.initial_prompt_tokens, + ) + } else { + 100 + }; hint.push(Span::from(" ")); hint.push( - Span::from(format!("{} tokens used", token_usage.blended_total())) + Span::from(format!("{percent_remaining}% context left")) .style(Style::default().add_modifier(Modifier::DIM)), ); - let last_token_usage = &token_usage_info.last_token_usage; - if let Some(context_window) = token_usage_info.model_context_window { - let percent_remaining: u8 = if context_window > 0 { - last_token_usage.percent_of_context_window_remaining( - context_window, - token_usage_info.initial_prompt_tokens, - ) - } else { - 100 - }; - hint.push(Span::from(" ")); - hint.push( - Span::from(format!("{percent_remaining}% context left")) - .style(Style::default().add_modifier(Modifier::DIM)), - ); - } } + } Line::from(hint) .style(Style::default().dim()) .render_ref(bottom_line_rect, buf); - if needs_tokens_line - && let Some(token_usage_info) = &self.token_usage_info { - let token_usage = &token_usage_info.total_token_usage; - let mut text = String::from(" "); - text.push_str(&format!("{} tokens used", token_usage.blended_total())); - if let Some(context_window) = token_usage_info.model_context_window { - let last_token_usage = &token_usage_info.last_token_usage; - let percent_remaining: u8 = if context_window > 0 { - last_token_usage.percent_of_context_window_remaining( - context_window, - token_usage_info.initial_prompt_tokens, - ) - } else { - 100 - }; - text.push_str(" "); - text.push_str(&format!("{percent_remaining}% context left")); - } - Line::from(text) - .style(Style::default().dim()) - .render_ref( - Rect::new( - bottom_line_rect.x, - bottom_line_rect.y + 1, - bottom_line_rect.width, - 1, - ), - buf, - ); + if needs_tokens_line && let Some(token_usage_info) = &self.token_usage_info { + let token_usage = &token_usage_info.total_token_usage; + let mut text = String::from(" "); + text.push_str(&format!("{} tokens used", token_usage.blended_total())); + if let Some(context_window) = token_usage_info.model_context_window { + let last_token_usage = &token_usage_info.last_token_usage; + let percent_remaining: u8 = if context_window > 0 { + last_token_usage.percent_of_context_window_remaining( + context_window, + token_usage_info.initial_prompt_tokens, + ) + } else { + 100 + }; + text.push_str(" "); + text.push_str(&format!("{percent_remaining}% context left")); } + Line::from(text).style(Style::default().dim()).render_ref( + Rect::new( + bottom_line_rect.x, + bottom_line_rect.y + 1, + bottom_line_rect.width, + 1, + ), + buf, + ); + } } } let border_style = if self.has_focus {