返回 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 crate::commands::traits::{CommandInfo, RegisterCommand};
6 use crate::tui::app::App;
7 use codewhale_localization::MessageId;
8
9 use super::CommandResult;
10
11 pub(in crate::commands) const COMMAND_INFO: CommandInfo = CommandInfo {
12 name: "pin",
13 aliases: &["mini", "window-pin"],
14 usage: "/pin",
15 description_id: MessageId::CmdPinDescription,
16 };
17
18 pub(in crate::commands) struct PinCmd;
19
20 impl RegisterCommand for PinCmd {
21 fn info() -> &'static CommandInfo {
22 &COMMAND_INFO
23 }
24
25 fn execute(app: &mut App, arg: Option<&str>) -> CommandResult {
26 match arg.map(str::trim).filter(|value| !value.is_empty()) {
27 Some("help" | "?" | "--help" | "-h") => {
28 return CommandResult::message(format!("Usage: {}", COMMAND_INFO.usage));
29 }
30 Some(_) => return CommandResult::error(format!("Usage: {}", COMMAND_INFO.usage)),
31 None => {}
32 }
33 crate::tui::window_control::toggle_pin(app);
34 CommandResult::ok()
35 }
36 }
37
37 lines RUST