re-use command name instead of slashcommand as we removed at_command

This commit is contained in:
pap
2025-08-01 19:45:32 +01:00
parent 5ebbecb968
commit c9b80cd456
5 changed files with 26 additions and 28 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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<SlashCommand>),
Slash(CommandPopup<Command>),
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();

View File

@@ -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<C: CommandInfo> CommandPopup<C> {
}
}
impl CommandPopup<SlashCommand> {
impl CommandPopup<Command> {
pub(crate) fn slash() -> Self {
CommandPopup::new('/', built_in_slash_commands())
}

View File

@@ -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()
}