2026-07-11 18:23:01 +07:00
|
|
|
use crate::app::mode::ModeKind;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
pub enum Command {
|
|
|
|
|
Help,
|
|
|
|
|
Quit,
|
|
|
|
|
Resume,
|
|
|
|
|
LessonCreate(String),
|
|
|
|
|
LessonExport(String),
|
|
|
|
|
LessonImport(String),
|
|
|
|
|
Mode(ModeKind),
|
|
|
|
|
Clear,
|
|
|
|
|
Save,
|
|
|
|
|
LessonList,
|
|
|
|
|
Unknown(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn parse_command(text: &str) -> Command {
|
|
|
|
|
let text = text.trim();
|
|
|
|
|
if !text.starts_with('/') {
|
|
|
|
|
return Command::Unknown(text.to_string());
|
|
|
|
|
}
|
|
|
|
|
let parts: Vec<&str> = text.splitn(3, ' ').collect();
|
|
|
|
|
let cmd = parts[0];
|
|
|
|
|
let arg1 = parts.get(1).copied().unwrap_or("");
|
|
|
|
|
let arg2 = parts.get(2).copied().unwrap_or("");
|
|
|
|
|
match cmd {
|
|
|
|
|
"/help" => Command::Help,
|
|
|
|
|
"/quit" => Command::Quit,
|
|
|
|
|
"/resume" => Command::Resume,
|
|
|
|
|
"/clear" => Command::Clear,
|
|
|
|
|
"/save" => Command::Save,
|
|
|
|
|
"/mode" => {
|
|
|
|
|
let mode = match arg1 {
|
|
|
|
|
"chat" | "c" => ModeKind::Chat,
|
|
|
|
|
"agents" | "a" => ModeKind::Agents,
|
|
|
|
|
"bash" | "b" => ModeKind::Bash,
|
|
|
|
|
"workflow" | "w" => ModeKind::Workflow,
|
|
|
|
|
"help" | "h" => ModeKind::Help,
|
|
|
|
|
"settings" | "s" => ModeKind::Settings,
|
|
|
|
|
_ => return Command::Unknown(format!("unknown mode: {}", arg1)),
|
|
|
|
|
};
|
|
|
|
|
Command::Mode(mode)
|
|
|
|
|
}
|
|
|
|
|
"/lesson" if arg1 == "export" && !arg2.is_empty() => Command::LessonExport(arg2.to_string()),
|
|
|
|
|
"/lesson" if arg1 == "import" && !arg2.is_empty() => Command::LessonImport(arg2.to_string()),
|
|
|
|
|
"/lesson" if arg1 == "list" || arg1 == "ls" => Command::LessonList,
|
|
|
|
|
"/lesson" if !arg1.is_empty() => Command::LessonCreate(arg1.to_string()),
|
|
|
|
|
"/lesson" => Command::LessonList,
|
|
|
|
|
_ => Command::Unknown(cmd.to_string()),
|
|
|
|
|
}
|
|
|
|
|
}
|