From c9b80cd4568111024dd7cce6625fa47a6847bb5f Mon Sep 17 00:00:00 2001 From: pap Date: Fri, 1 Aug 2025 19:45:32 +0100 Subject: [PATCH] re-use command name instead of slashcommand as we removed at_command --- codex-rs/tui/src/app.rs | 14 ++++++------- codex-rs/tui/src/app_event.rs | 4 ++-- codex-rs/tui/src/bottom_pane/chat_composer.rs | 6 +++--- codex-rs/tui/src/bottom_pane/command_popup.rs | 10 +++++----- codex-rs/tui/src/slash_command.rs | 20 +++++++++---------- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index d4e66a2ace..9eacc6052f 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -5,7 +5,7 @@ use crate::file_search::FileSearchManager; use crate::get_git_diff::get_git_diff; use crate::git_warning_screen::GitWarningOutcome; use crate::git_warning_screen::GitWarningScreen; -use crate::slash_command::SlashCommand; +use crate::slash_command::Command; use crate::tui; use codex_core::config::Config; use codex_core::protocol::Event; @@ -339,8 +339,8 @@ impl App<'_> { AppState::Chat { widget } => widget.update_latest_log(line), AppState::GitWarning { .. } => {} }, - AppEvent::DispatchSlashCommand(command) => match command { - SlashCommand::New => { + AppEvent::DispatchCommand(command) => match command { + Command::New => { let new_widget = Box::new(ChatWidget::new( self.config.clone(), self.app_event_tx.clone(), @@ -351,16 +351,16 @@ impl App<'_> { self.app_state = AppState::Chat { widget: new_widget }; self.app_event_tx.send(AppEvent::RequestRedraw); } - SlashCommand::Compact => { + Command::Compact => { if let AppState::Chat { widget } = &mut self.app_state { widget.clear_token_usage(); self.app_event_tx.send(AppEvent::CodexOp(Op::Compact)); } } - SlashCommand::Quit => { + Command::Quit => { break; } - SlashCommand::Diff => { + Command::Diff => { let (is_git_repo, diff_text) = match get_git_diff() { Ok(v) => v, Err(e) => { @@ -382,7 +382,7 @@ impl App<'_> { } } #[cfg(debug_assertions)] - SlashCommand::TestApproval => { + Command::TestApproval => { use std::collections::HashMap; use codex_core::protocol::ApplyPatchApprovalRequestEvent; diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rs index 77ad986e65..45c4b9137d 100644 --- a/codex-rs/tui/src/app_event.rs +++ b/codex-rs/tui/src/app_event.rs @@ -3,7 +3,7 @@ use codex_file_search::FileMatch; use crossterm::event::KeyEvent; use ratatui::text::Line; -use crate::slash_command::SlashCommand; +use crate::slash_command::Command; #[derive(Debug)] #[allow(clippy::large_enum_variant)] @@ -33,7 +33,7 @@ pub(crate) enum AppEvent { /// Dispatch a recognized slash command from the UI (composer) to the app /// layer so it can be handled centrally. - DispatchSlashCommand(SlashCommand), + DispatchCommand(Command), /// Kick off an asynchronous file search for the given query (text after /// the `@`). Previous searches may be cancelled by the app layer so there diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 5b293bad1b..1f50d9cdce 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -19,7 +19,7 @@ use tui_textarea::TextArea; use super::chat_composer_history::ChatComposerHistory; use super::command_popup::CommandPopup; use super::file_search_popup::FileSearchPopup; -use crate::slash_command::SlashCommand; +use crate::slash_command::Command; use crate::app_event::AppEvent; use crate::app_event_sender::AppEventSender; @@ -56,7 +56,7 @@ pub(crate) struct ChatComposer<'a> { /// Popup state – at most one can be visible at any time. enum ActivePopup { None, - Slash(CommandPopup), + Slash(CommandPopup), File(FileSearchPopup), } @@ -271,7 +271,7 @@ impl ChatComposer<'_> { } => { if let Some(cmd) = popup.selected_command() { // Send command to the app layer. - self.app_event_tx.send(AppEvent::DispatchSlashCommand(*cmd)); + self.app_event_tx.send(AppEvent::DispatchCommand(*cmd)); // Clear textarea so no residual text remains. self.textarea.select_all(); diff --git a/codex-rs/tui/src/bottom_pane/command_popup.rs b/codex-rs/tui/src/bottom_pane/command_popup.rs index aa99f95317..7442d45299 100644 --- a/codex-rs/tui/src/bottom_pane/command_popup.rs +++ b/codex-rs/tui/src/bottom_pane/command_popup.rs @@ -12,7 +12,7 @@ use ratatui::widgets::Table; use ratatui::widgets::Widget; use ratatui::widgets::WidgetRef; -use crate::slash_command::SlashCommand; +use crate::slash_command::Command; use crate::slash_command::built_in_slash_commands; pub trait CommandInfo: Copy { @@ -20,12 +20,12 @@ pub trait CommandInfo: Copy { fn description(&self) -> &'static str; } -impl CommandInfo for SlashCommand { +impl CommandInfo for Command { fn command(&self) -> &'static str { - SlashCommand::command(*self) + Command::command(*self) } fn description(&self) -> &'static str { - SlashCommand::description(*self) + Command::description(*self) } } @@ -144,7 +144,7 @@ impl CommandPopup { } } -impl CommandPopup { +impl CommandPopup { pub(crate) fn slash() -> Self { CommandPopup::new('/', built_in_slash_commands()) } diff --git a/codex-rs/tui/src/slash_command.rs b/codex-rs/tui/src/slash_command.rs index d82a16608f..9b2cc6d681 100644 --- a/codex-rs/tui/src/slash_command.rs +++ b/codex-rs/tui/src/slash_command.rs @@ -9,7 +9,7 @@ use strum_macros::IntoStaticStr; Debug, Clone, Copy, PartialEq, Eq, Hash, EnumString, EnumIter, AsRefStr, IntoStaticStr, )] #[strum(serialize_all = "kebab-case")] -pub enum SlashCommand { +pub enum Command { // DO NOT ALPHA-SORT! Enum order is presentation order in the popup, so // more frequently used commands should be listed first. New, @@ -20,18 +20,16 @@ pub enum SlashCommand { TestApproval, } -impl SlashCommand { +impl Command { /// User-visible description shown in the popup. pub fn description(self) -> &'static str { match self { - SlashCommand::New => "Start a new chat.", - SlashCommand::Compact => "Compact the chat history.", - SlashCommand::Quit => "Exit the application.", - SlashCommand::Diff => { - "Show git diff of the working directory (including untracked files)" - } + Command::New => "Start a new chat.", + Command::Compact => "Compact the chat history.", + Command::Quit => "Exit the application.", + Command::Diff => "Show git diff of the working directory (including untracked files)", #[cfg(debug_assertions)] - SlashCommand::TestApproval => "Test approval request", + Command::TestApproval => "Test approval request", } } @@ -43,6 +41,6 @@ impl SlashCommand { } /// Return all built-in commands in a Vec paired with their command string. -pub fn built_in_slash_commands() -> Vec<(&'static str, SlashCommand)> { - SlashCommand::iter().map(|c| (c.command(), c)).collect() +pub fn built_in_slash_commands() -> Vec<(&'static str, Command)> { + Command::iter().map(|c| (c.command(), c)).collect() }