use {
reovim_driver_command::{
Command, CommandContext, CommandHandler, CommandResult, RuntimeSignal,
},
reovim_driver_session::SessionRuntime,
reovim_kernel::api::v1::{CommandId, ModuleId},
};
const COMMANDS_MODULE: ModuleId = ModuleId::new("commands");
pub struct DetachCommand;
impl Command for DetachCommand {
fn id(&self) -> CommandId {
CommandId::new(COMMANDS_MODULE, "detach")
}
fn description(&self) -> &'static str {
"Detach from the server (server continues running)"
}
fn names(&self) -> &[&'static str] {
&["detach"]
}
}
impl CommandHandler for DetachCommand {
fn execute(&self, runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
runtime.signal(RuntimeSignal::Quit);
CommandResult::Success
}
}
pub struct ServersCommand;
impl Command for ServersCommand {
fn id(&self) -> CommandId {
CommandId::new(COMMANDS_MODULE, "servers")
}
fn description(&self) -> &'static str {
"List running server instances"
}
fn names(&self) -> &[&'static str] {
&["servers"]
}
}
impl CommandHandler for ServersCommand {
fn execute(&self, _runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
CommandResult::Success
}
}
pub struct KillServerCommand;
impl Command for KillServerCommand {
fn id(&self) -> CommandId {
CommandId::new(COMMANDS_MODULE, "kill-server")
}
fn description(&self) -> &'static str {
"Kill the current server (terminates all sessions)"
}
fn names(&self) -> &[&'static str] {
&["kill-server", "killserver"]
}
}
impl CommandHandler for KillServerCommand {
fn execute(&self, runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
runtime.signal(RuntimeSignal::Quit);
CommandResult::Success
}
}
#[must_use]
pub fn command_handlers() -> Vec<Box<dyn CommandHandler>> {
vec![
Box::new(DetachCommand),
Box::new(ServersCommand),
Box::new(KillServerCommand),
]
}
#[cfg(test)]
#[path = "session_tests.rs"]
mod tests;