-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathmod.rs
More file actions
91 lines (82 loc) · 2.63 KB
/
Copy pathmod.rs
File metadata and controls
91 lines (82 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Slash command system for cortex-tui.
//!
//! This module provides a complete slash command infrastructure including:
//! - Command registry with 45+ built-in commands
//! - Command parser supporting quoted arguments
//! - Fuzzy completion engine
//! - Command execution framework
//!
//! # Overview
//!
//! Commands are entered with a leading `/` character:
//! - `/help` - Show help
//! - `/models claude-sonnet-4-20250514` - Switch model
//! - `/search "hello world"` - Search with quoted argument
//!
//! # Example
//!
//! ```rust,ignore
//! use cortex_tui::commands::{CommandRegistry, CommandParser, CompletionEngine};
//!
//! // Get the default registry with all builtins
//! let registry = CommandRegistry::default();
//!
//! // Parse user input
//! if let Some(cmd) = CommandParser::parse("/help topic") {
//! // Look up the command
//! if let Some(def) = registry.get(&cmd.name) {
//! println!("Command: {} - {}", def.name, def.description);
//! }
//! }
//!
//! // Get completions for partial input
//! let engine = CompletionEngine::new(®istry);
//! let completions = engine.complete("/hel");
//! ```
pub mod completion;
pub mod executor;
pub mod forms;
pub mod parser;
pub mod registry;
pub mod types;
// Re-exports for convenience
pub use completion::{Completion, CompletionEngine};
pub use executor::CommandExecutor;
pub use forms::FormRegistry;
pub use parser::CommandParser;
pub use registry::{CommandRegistry, register_builtin_commands};
pub use types::{CommandCategory, CommandDef, CommandResult, ModalType, ParsedCommand, ViewType};
/// Initialize the command system with all builtins.
///
/// This is a convenience function that creates a `CommandRegistry`
/// with all built-in commands registered.
pub fn init() -> CommandRegistry {
CommandRegistry::default()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init_creates_registry() {
let registry = init();
assert!(!registry.is_empty());
assert!(registry.exists("help"));
}
#[test]
fn test_full_workflow() {
let registry = init();
// Parse a command
let input = "/help topic";
let cmd = CommandParser::parse(input).unwrap();
assert_eq!(cmd.name, "help");
assert_eq!(cmd.args, vec!["topic"]);
// Look up definition
let def = registry.get(&cmd.name).unwrap();
assert_eq!(def.category, CommandCategory::General);
// Get completions
let engine = CompletionEngine::new(®istry);
let completions = engine.complete("/hel");
assert!(!completions.is_empty());
assert!(completions.iter().any(|c| c.command == "help"));
}
}