From a5eaf21a13556563df14dd8261eb6a0d0e5a4035 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Sun, 25 Jan 2026 21:43:49 -0800 Subject: [PATCH] unify --- codex-rs/tui/src/bottom_pane/chat_composer.rs | 237 +++++++----------- 1 file changed, 88 insertions(+), 149 deletions(-) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 121d365b7f..2d56d2dec0 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -7,7 +7,6 @@ //! - Handling submit vs newline on Enter. //! - Turning raw key streams into explicit paste operations on platforms where terminals //! don't provide reliable bracketed paste (notably Windows). -//! - Supporting textarea-only embedding by disabling popups/footers and rendering the core input. //! //! # Key Event Routing //! @@ -202,7 +201,6 @@ pub(crate) struct ChatComposer { textarea: TextArea, textarea_state: RefCell, active_popup: ActivePopup, - popups_enabled: bool, app_event_tx: AppEventSender, history: ChatComposerHistory, quit_shortcut_expires_at: Option, @@ -226,8 +224,6 @@ pub(crate) struct ChatComposer { // When true, disables paste-burst logic and inserts characters immediately. disable_paste_burst: bool, custom_prompts: Vec, - footer_enabled: bool, - prompt_inset_enabled: bool, footer_mode: FooterMode, footer_hint_override: Option>, footer_flash: Option, @@ -287,7 +283,6 @@ impl ChatComposer { textarea: TextArea::new(), textarea_state: RefCell::new(TextAreaState::default()), active_popup: ActivePopup::None, - popups_enabled: true, app_event_tx, history: ChatComposerHistory::new(), quit_shortcut_expires_at: None, @@ -307,8 +302,6 @@ impl ChatComposer { paste_burst: PasteBurst::default(), disable_paste_burst: false, custom_prompts: Vec::new(), - footer_enabled: true, - prompt_inset_enabled: true, footer_mode: FooterMode::ShortcutSummary, footer_hint_override: None, footer_flash: None, @@ -344,13 +337,9 @@ impl ChatComposer { } pub(crate) fn desired_textarea_height(&self, width: u16) -> u16 { - let cols_with_margin = if self.prompt_inset_enabled { - LIVE_PREFIX_COLS + 3 - } else { - 4 - }; + const COLS_WITH_MARGIN: u16 = LIVE_PREFIX_COLS + 1; self.textarea - .desired_height(width.saturating_sub(cols_with_margin)) + .desired_height(width.saturating_sub(COLS_WITH_MARGIN)) + 2 } @@ -396,29 +385,21 @@ impl ChatComposer { } fn layout_areas(&self, area: Rect) -> [Rect; 3] { - let footer_total_height = if self.footer_enabled { - let footer_props = self.footer_props(); - let footer_hint_height = self - .custom_footer_height() - .unwrap_or_else(|| footer_height(footer_props)); - let footer_spacing = Self::footer_spacing(footer_hint_height); - footer_hint_height + footer_spacing - } else { - 0 - }; - let popup_constraint = if self.popups_enabled { - match &self.active_popup { - ActivePopup::Command(popup) => { - Constraint::Max(popup.calculate_required_height(area.width)) - } - ActivePopup::File(popup) => Constraint::Max(popup.calculate_required_height()), - ActivePopup::Skill(popup) => { - Constraint::Max(popup.calculate_required_height(area.width)) - } - ActivePopup::None => Constraint::Max(footer_total_height), + let footer_props = self.footer_props(); + let footer_hint_height = self + .custom_footer_height() + .unwrap_or_else(|| footer_height(footer_props)); + let footer_spacing = Self::footer_spacing(footer_hint_height); + let footer_total_height = footer_hint_height + footer_spacing; + let popup_constraint = match &self.active_popup { + ActivePopup::Command(popup) => { + Constraint::Max(popup.calculate_required_height(area.width)) } - } else { - Constraint::Max(footer_total_height) + ActivePopup::File(popup) => Constraint::Max(popup.calculate_required_height()), + ActivePopup::Skill(popup) => { + Constraint::Max(popup.calculate_required_height(area.width)) + } + ActivePopup::None => Constraint::Max(footer_total_height), }; let [composer_rect, popup_rect] = Layout::vertical([Constraint::Min(3), popup_constraint]).areas(area); @@ -426,45 +407,8 @@ impl ChatComposer { [composer_rect, textarea_rect, popup_rect] } - fn render_footer(&self, popup_rect: Rect, buf: &mut Buffer) { - let footer_props = self.footer_props(); - let custom_height = self.custom_footer_height(); - let footer_hint_height = custom_height.unwrap_or_else(|| footer_height(footer_props)); - let footer_spacing = Self::footer_spacing(footer_hint_height); - let hint_rect = if footer_spacing > 0 && footer_hint_height > 0 { - let [_, hint_rect] = Layout::vertical([ - Constraint::Length(footer_spacing), - Constraint::Length(footer_hint_height), - ]) - .areas(popup_rect); - hint_rect - } else { - popup_rect - }; - let mut left_content_width = None; - if self.footer_flash_visible() { - if let Some(flash) = self.footer_flash.as_ref() { - flash.line.render(inset_footer_hint_area(hint_rect), buf); - left_content_width = Some(flash.line.width() as u16); - } - } else if let Some(items) = self.footer_hint_override.as_ref() { - render_footer_hint_items(hint_rect, buf, items); - left_content_width = Some(footer_hint_items_width(items)); - } else { - render_footer(hint_rect, buf, footer_props); - left_content_width = Some(footer_line_width(footer_props)); - } - render_mode_indicator( - hint_rect, - buf, - self.collaboration_mode_indicator, - !footer_props.is_task_running, - left_content_width, - ); - } - fn textarea_render_rect(&self, textarea_rect: Rect) -> Rect { - let rect = if self.prompt_inset_enabled && textarea_rect.x < LIVE_PREFIX_COLS { + if textarea_rect.x < LIVE_PREFIX_COLS { Rect { x: textarea_rect.x.saturating_add(LIVE_PREFIX_COLS), width: textarea_rect.width.saturating_sub(LIVE_PREFIX_COLS), @@ -472,15 +416,6 @@ impl ChatComposer { } } else { textarea_rect - }; - if self.prompt_inset_enabled { - rect - } else { - Rect { - x: rect.x.saturating_add(2), - width: rect.width.saturating_sub(2), - ..rect - } } } @@ -489,14 +424,10 @@ impl ChatComposer { if render_rect.is_empty() { return; } - let prompt_x = if self.prompt_inset_enabled { - textarea_rect - .x - .checked_sub(LIVE_PREFIX_COLS) - .unwrap_or(textarea_rect.x) - } else { - textarea_rect.x - }; + let prompt_x = textarea_rect + .x + .checked_sub(LIVE_PREFIX_COLS) + .unwrap_or(textarea_rect.x); let prompt = if self.input_enabled { "›".bold() } else { @@ -1798,9 +1729,7 @@ impl ChatComposer { text = text.trim().to_string(); text_elements = Self::trim_text_elements(&expanded_input, &text, text_elements); - if self.popups_enabled - && let Some((name, _rest, _rest_offset)) = parse_slash_name(&text) - { + if let Some((name, _rest, _rest_offset)) = parse_slash_name(&text) { let treat_as_plain_text = input_starts_with_space || name.contains('/'); if !treat_as_plain_text { let is_builtin = @@ -1886,24 +1815,21 @@ impl ChatComposer { // the '/name' token and our caret-based heuristic hides the popup, // but Enter/Ctrl+Shift+Q should still dispatch the command rather than submit // literal text. - if self.popups_enabled - && let Some(result) = self.try_dispatch_bare_slash_command() - { + if let Some(result) = self.try_dispatch_bare_slash_command() { return (result, true); } // If we're in a paste-like burst capture, treat Enter/Ctrl+Shift+Q as part of the burst // and accumulate it rather than submitting or inserting immediately. // Do not treat as paste inside a slash-command context. - let in_slash_context = self.popups_enabled - && (matches!(self.active_popup, ActivePopup::Command(_)) - || self - .textarea - .text() - .lines() - .next() - .unwrap_or("") - .starts_with('/')); + let in_slash_context = matches!(self.active_popup, ActivePopup::Command(_)) + || self + .textarea + .text() + .lines() + .next() + .unwrap_or("") + .starts_with('/'); if !self.disable_paste_burst && self.paste_burst.is_active() && !in_slash_context @@ -1932,9 +1858,7 @@ impl ChatComposer { .map(|img| img.path.clone()) .collect::>(); let original_pending_pastes = self.pending_pastes.clone(); - if self.popups_enabled - && let Some(result) = self.try_dispatch_slash_command_with_args() - { + if let Some(result) = self.try_dispatch_slash_command_with_args() { return (result, true); } @@ -2353,10 +2277,6 @@ impl ChatComposer { } fn sync_popups(&mut self) { - if !self.popups_enabled { - self.active_popup = ActivePopup::None; - return; - } let file_token = Self::current_at_token(&self.textarea); let browsing_history = self .history @@ -2635,26 +2555,18 @@ impl Renderable for ChatComposer { } fn desired_height(&self, width: u16) -> u16 { - let footer_total_height = if self.footer_enabled { - let footer_props = self.footer_props(); - let footer_hint_height = self - .custom_footer_height() - .unwrap_or_else(|| footer_height(footer_props)); - let footer_spacing = Self::footer_spacing(footer_hint_height); - footer_hint_height + footer_spacing - } else { - 0 - }; + let footer_props = self.footer_props(); + let footer_hint_height = self + .custom_footer_height() + .unwrap_or_else(|| footer_height(footer_props)); + let footer_spacing = Self::footer_spacing(footer_hint_height); + let footer_total_height = footer_hint_height + footer_spacing; const COLS_WITH_MARGIN: u16 = LIVE_PREFIX_COLS + 1; - let popup_height = if self.popups_enabled { - match &self.active_popup { - ActivePopup::None => footer_total_height, - ActivePopup::Command(c) => c.calculate_required_height(width), - ActivePopup::File(c) => c.calculate_required_height(), - ActivePopup::Skill(c) => c.calculate_required_height(width), - } - } else { - footer_total_height + let popup_height = match &self.active_popup { + ActivePopup::None => footer_total_height, + ActivePopup::Command(c) => c.calculate_required_height(width), + ActivePopup::File(c) => c.calculate_required_height(), + ActivePopup::Skill(c) => c.calculate_required_height(width), }; self.textarea .desired_height(width.saturating_sub(COLS_WITH_MARGIN)) @@ -2664,25 +2576,52 @@ impl Renderable for ChatComposer { fn render(&self, area: Rect, buf: &mut Buffer) { let [composer_rect, textarea_rect, popup_rect] = self.layout_areas(area); - if self.popups_enabled { - match &self.active_popup { - ActivePopup::Command(popup) => { - popup.render_ref(popup_rect, buf); - } - ActivePopup::File(popup) => { - popup.render_ref(popup_rect, buf); - } - ActivePopup::Skill(popup) => { - popup.render_ref(popup_rect, buf); - } - ActivePopup::None => { - if self.footer_enabled { - self.render_footer(popup_rect, buf); - } - } + match &self.active_popup { + ActivePopup::Command(popup) => { + popup.render_ref(popup_rect, buf); + } + ActivePopup::File(popup) => { + popup.render_ref(popup_rect, buf); + } + ActivePopup::Skill(popup) => { + popup.render_ref(popup_rect, buf); + } + ActivePopup::None => { + let footer_props = self.footer_props(); + let custom_height = self.custom_footer_height(); + let footer_hint_height = + custom_height.unwrap_or_else(|| footer_height(footer_props)); + let footer_spacing = Self::footer_spacing(footer_hint_height); + let hint_rect = if footer_spacing > 0 && footer_hint_height > 0 { + let [_, hint_rect] = Layout::vertical([ + Constraint::Length(footer_spacing), + Constraint::Length(footer_hint_height), + ]) + .areas(popup_rect); + hint_rect + } else { + popup_rect + }; + let left_content_width = if self.footer_flash_visible() + && let Some(flash) = self.footer_flash.as_ref() + { + flash.line.render(inset_footer_hint_area(hint_rect), buf); + Some(flash.line.width() as u16) + } else if let Some(items) = self.footer_hint_override.as_ref() { + render_footer_hint_items(hint_rect, buf, items); + Some(footer_hint_items_width(items)) + } else { + render_footer(hint_rect, buf, footer_props); + Some(footer_line_width(footer_props)) + }; + render_mode_indicator( + hint_rect, + buf, + self.collaboration_mode_indicator, + !footer_props.is_task_running, + left_content_width, + ); } - } else if self.footer_enabled { - self.render_footer(popup_rect, buf); } let style = user_message_style(); Block::default().style(style).render_ref(composer_rect, buf);