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§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Short description shown in the slash popup.
Sourcefn execute(&self, args: &str, ctx: &mut CommandContext<'_>) -> CommandResult
fn execute(&self, args: &str, ctx: &mut CommandContext<'_>) -> CommandResult
Execute the command.
§Arguments
args- Everything after the command name, trimmedctx- Context providing access to app functionality
§Returns
A CommandResult indicating what happened