Add commands.rs
This commit is contained in:
39
src/ui/commands.rs
Normal file
39
src/ui/commands.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//! IPC 命令處理
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum UiCommand {
|
||||||
|
OpenFile(String),
|
||||||
|
ExecuteCommand(String),
|
||||||
|
ToggleFullscreen,
|
||||||
|
ZoomIn,
|
||||||
|
ZoomOut,
|
||||||
|
ResetZoom,
|
||||||
|
Pan(i32, i32),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UiCommand {
|
||||||
|
pub fn parse(input: &str) -> Result<Self> {
|
||||||
|
let parts: Vec<&str> = input.trim().split_whitespace().collect();
|
||||||
|
|
||||||
|
match parts.first().copied().unwrap_or("") {
|
||||||
|
"open" if parts.len() > 1 => {
|
||||||
|
Ok(UiCommand::OpenFile(parts[1..].join(" ")))
|
||||||
|
}
|
||||||
|
"cmd" | "command" if parts.len() > 1 => {
|
||||||
|
Ok(UiCommand::ExecuteCommand(parts[1..].join(" ")))
|
||||||
|
}
|
||||||
|
"fullscreen" => Ok(UiCommand::ToggleFullscreen),
|
||||||
|
"zoom_in" | "+" => Ok(UiCommand::ZoomIn),
|
||||||
|
"zoom_out" | "-" => Ok(UiCommand::ZoomOut),
|
||||||
|
"reset" => Ok(UiCommand::ResetZoom),
|
||||||
|
"pan" if parts.len() >= 3 => {
|
||||||
|
let x = parts[1].parse().unwrap_or(0);
|
||||||
|
let y = parts[2].parse().unwrap_or(0);
|
||||||
|
Ok(UiCommand::Pan(x, y))
|
||||||
|
}
|
||||||
|
_ => anyhow::bail!("Unknown command: {}", input),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user