Files
zesdex/src/app/runtime/commands.rs
T
asepharyana a00aa9bec8 Refactor view modules for improved readability and consistency
- Updated markdown rendering logic to use more concise methods for obtaining vector lengths.
- Changed review status display to use the correct flag from settings.
- Cleaned up sidebar rendering code for better formatting and readability.
- Enhanced status bar rendering with improved string formatting and consistent style application.
- Refined workflow panel rendering, ensuring consistent style usage and improved readability.
- Added architecture overview and detailed documentation for backend, data, dependencies, and frontend structures.
2026-07-16 07:56:11 +07:00

78 lines
2.6 KiB
Rust

//! Maps parsed `/` slash commands into one or more `Action` variants
//! that `apply_action` can process.
use crate::app::runtime::actions::Action;
use crate::app::state::types::Overlay;
use crate::controller::command::Command;
/// Convert a parsed `Command` into the corresponding sequence of `Action`s.
///
/// Flow: match each `Command` variant to its handler — most produce a
/// single `Action` (open an overlay, dispatch an OAuth flow, open the
/// editor, etc.); some produce an `Action::SystemNote` for errors or
/// informational responses.
///
/// Return: a `Vec<Action>` (always non-empty) to be applied sequentially
/// by `apply_action`.
pub fn apply_command(command: Command) -> Vec<Action> {
match command {
Command::Help => {
vec![Action::OpenOverlay(Overlay::Help)]
}
Command::Quit => {
vec![Action::QuitConfirm]
}
Command::McpOpen => {
vec![Action::OpenOverlay(Overlay::Mcp)]
}
Command::ClearConfirm => {
vec![Action::OpenOverlay(Overlay::ClearConfirm)]
}
Command::Clear => {
vec![Action::SystemNote {
kind: "clear".to_string(),
message: "transcript cleared".to_string(),
}]
}
Command::Login { provider } if provider.is_empty() => {
vec![Action::SystemNote {
kind: "error".to_string(),
message: "Usage: /login <provider>".to_string(),
}]
}
Command::Login { provider } => {
vec![Action::StartOAuth { provider }]
}
Command::Edit(path) if path == "." || path.is_empty() => {
vec![Action::SystemNote {
kind: "info".to_string(),
message: "Usage: /edit <path>\nOpens a file for inline editing.\nExample: /edit src/main.rs".to_string(),
}]
}
Command::Edit(path) => {
vec![Action::OpenEditor { path }]
}
Command::McpAdd { name, command } => {
vec![Action::McpAdd { name, command }]
}
Command::ModelList => {
vec![Action::ModelList]
}
Command::Compact => {
vec![Action::Compact]
}
Command::TodoOpen => {
vec![Action::OpenOverlay(Overlay::Todo)]
}
Command::UsageOpen => {
vec![Action::OpenOverlay(Overlay::Usage)]
}
Command::Unknown(cmd) => {
vec![Action::SystemNote {
kind: "error".to_string(),
message: format!("unknown command: {cmd}"),
}]
}
}
}