SlashCommand

Trait SlashCommand 

Source
pub trait SlashCommand: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn execute(&self, args: &str, ctx: &mut CommandContext<'_>) -> CommandResult;
}
Expand description

Trait for slash commands.

Implement this for full control over command behavior, or use CustomCommand for simple closure-based commands.

§Example

use agent_core::tui::commands::{SlashCommand, CommandContext, CommandResult};

struct CounterCommand {
    count: std::sync::atomic::AtomicUsize,
}

impl SlashCommand for CounterCommand {
    fn name(&self) -> &str { "count" }
    fn description(&self) -> &str { "Increment and show counter" }

    fn execute(&self, _args: &str, _ctx: &mut CommandContext) -> CommandResult {
        let n = self.count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
        CommandResult::Message(format!("Count: {}", n + 1))
    }
}

Required Methods§

Source

fn name(&self) -> &str

Command name without the leading slash (e.g., “clear”).

Source

fn description(&self) -> &str

Short description shown in the slash popup.

Source

fn execute(&self, args: &str, ctx: &mut CommandContext<'_>) -> CommandResult

Execute the command.

§Arguments
  • args - Everything after the command name, trimmed
  • ctx - Context providing access to app functionality
§Returns

A CommandResult indicating what happened

Trait Implementations§

Source§

impl SlashCommandDisplay for &dyn SlashCommand

Source§

fn name(&self) -> &str

The command name (without the leading /)
Source§

fn description(&self) -> &str

A short description of what the command does

Implementors§