reovim_module_commands/
session.rs1use {
9 reovim_driver_command::{
10 Command, CommandContext, CommandHandler, CommandResult, RuntimeSignal,
11 },
12 reovim_driver_session::SessionRuntime,
13 reovim_kernel::api::v1::{CommandId, ModuleId},
14};
15
16const COMMANDS_MODULE: ModuleId = ModuleId::new("commands");
17
18pub struct DetachCommand;
30
31impl Command for DetachCommand {
32 fn id(&self) -> CommandId {
33 CommandId::new(COMMANDS_MODULE, "detach")
34 }
35
36 fn description(&self) -> &'static str {
37 "Detach from the server (server continues running)"
38 }
39
40 fn names(&self) -> &[&'static str] {
41 &["detach"]
42 }
43}
44
45impl CommandHandler for DetachCommand {
46 fn execute(&self, runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
47 runtime.signal(RuntimeSignal::Quit);
48 CommandResult::Success
49 }
50}
51
52pub struct ServersCommand;
60
61impl Command for ServersCommand {
62 fn id(&self) -> CommandId {
63 CommandId::new(COMMANDS_MODULE, "servers")
64 }
65
66 fn description(&self) -> &'static str {
67 "List running server instances"
68 }
69
70 fn names(&self) -> &[&'static str] {
71 &["servers"]
72 }
73}
74
75impl CommandHandler for ServersCommand {
76 fn execute(&self, _runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
77 CommandResult::Success
79 }
80}
81
82pub struct KillServerCommand;
93
94impl Command for KillServerCommand {
95 fn id(&self) -> CommandId {
96 CommandId::new(COMMANDS_MODULE, "kill-server")
97 }
98
99 fn description(&self) -> &'static str {
100 "Kill the current server (terminates all sessions)"
101 }
102
103 fn names(&self) -> &[&'static str] {
104 &["kill-server", "killserver"]
105 }
106}
107
108impl CommandHandler for KillServerCommand {
109 fn execute(&self, runtime: &mut SessionRuntime<'_>, _ctx: &CommandContext) -> CommandResult {
110 runtime.signal(RuntimeSignal::Quit);
111 CommandResult::Success
112 }
113}
114
115#[must_use]
121pub fn command_handlers() -> Vec<Box<dyn CommandHandler>> {
122 vec![
123 Box::new(DetachCommand),
124 Box::new(ServersCommand),
125 Box::new(KillServerCommand),
126 ]
127}
128
129#[cfg(test)]
134#[path = "session_tests.rs"]
135mod tests;