返回 CodeWhale
pin.rs
根目录 / crates / tui / src / commands / groups / core / pin.rs
1 //! `/pin` command: toggle the host terminal window into the always-on-top
2 //! mini window (Windows). Keyboard-friendly twin of the right-click menu
3 //! entry, for mouse-less users.
4
5 use codewhale_command_contract::handler::{CommandCapabilities, CommandHandler};
6 use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand};
7 use codewhale_command_contract::outcome::CommandResult;
8
9 const COMMAND_INFO: CommandInfo = CommandInfo {
10 name: "pin",
11 aliases: &["mini", "window-pin"],
12 usage: "/pin",
13 description_key: "cmd_pin_description",
14 };
15
16 pub(super) struct PinCmd;
17
18 impl<A> RegisterCommand<CommandResult<A>> for PinCmd {
19 fn info() -> &'static CommandInfo {
20 &COMMAND_INFO
21 }
22
23 fn handler() -> CommandHandler<CommandResult<A>> {
24 CommandHandler::Contextual {
25 capabilities: CommandCapabilities::NAVIGATION,
26 handler: |contexts, arg| {
27 match arg.map(str::trim).filter(|value| !value.is_empty()) {
28 Some("help" | "?" | "--help" | "-h") => {
29 return CommandResult::message(format!("Usage: {}", COMMAND_INFO.usage));
30 }
31 Some(_) => {
32 return CommandResult::error(format!("Usage: {}", COMMAND_INFO.usage));
33 }
34 None => {}
35 }
36 let Some(navigation) = contexts.into_parts().navigation else {
37 return CommandResult::error("Command capability unavailable: navigation");
38 };
39 navigation.toggle_window_pin();
40 CommandResult::ok()
41 },
42 }
43 }
44 }
45
45 lines RUST