pub trait TerminalCommand: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn run<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 str,
context: &'life2 CommandContext,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
A slash command the terminal runs for its embedder: /name args in the message box runs
it, and what it returns is shown in a pane (spec 3.3 §5.2).
adk-rust adds the harness REPL’s commands this way (/todos, /rules, /memory,
/hooks, …), so the full screen runs the same code as the REPL, in process or on a
kernel. The terminal’s own commands (/help, /today, /permissions, /mode,
/session, /stop, /resume, /quit, /exit) take precedence over an added command of
the same name; an added mode or session answers the bare /mode and /session, which
show the mode and the session. What a command returns is shown as plain text, every
control character escaped (S-I9).
§Example
use adk_surface::tui::{CommandContext, TerminalCommand};
use async_trait::async_trait;
struct Uptime;
#[async_trait]
impl TerminalCommand for Uptime {
fn name(&self) -> &str {
"uptime"
}
fn description(&self) -> &str {
"How long the kernel has run"
}
async fn run(&self, _args: &str, context: &CommandContext) -> adk_core::Result<String> {
Ok(format!("Up 3 hours; this thread is {}", context.session_id))
}
}Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
One line shown next to the name while completing and in /help.
Sourcefn run<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 str,
context: &'life2 CommandContext,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn run<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 str,
context: &'life2 CommandContext,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Runs the command with the text after its name, trimmed, in the session the terminal shows, and returns what to show.
§Errors
An error is shown in the pane in place of the output, and the terminal carries on.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".