1#[macro_export]
7macro_rules! impl_default {
8 ($type:ty, $body:expr) => {
9 impl Default for $type {
10 fn default() -> Self {
11 $body
12 }
13 }
14 };
15}
16
17#[macro_export]
18macro_rules! matches_exact {
19 ($cmd:expr, $($pattern:literal)|+) => {
20 matches!($cmd.trim().to_lowercase().as_str(), $($pattern)|+)
21 };
22}
23
24#[macro_export]
26macro_rules! register_command {
27 ($registry:expr, $command:expr) => {
28 $registry.register($command);
29 };
30}
31
32#[macro_export]
33macro_rules! register_commands {
34 ($registry:expr, $($command:expr),+ $(,)?) => {
35 $(
36 $crate::register_command!($registry, $command);
37 )+
38 };
39}
40
41#[macro_export]
43macro_rules! create_full_registry {
44 () => {{
45 use $crate::commands::{
46 clear::ClearCommand,
47 exit::exit::ExitCommand,
48 history::HistoryCommand,
49 lang::LanguageCommand,
50 restart::RestartCommand,
51 theme::ThemeCommand, version::VersionCommand,
53 };
54
55 let mut registry = $crate::commands::registry::CommandRegistry::new();
56
57 $crate::register_commands!(
58 registry,
59 HistoryCommand,
60 ExitCommand,
61 LanguageCommand,
62 ClearCommand,
63 RestartCommand,
64 VersionCommand,
65 ThemeCommand );
67
68 registry.initialize();
69 registry
70 }};
71}
72
73#[macro_export]
75macro_rules! create_registry_with_plugins {
76 ($($plugin:expr),+ $(,)?) => {{
77 let mut registry = create_full_registry!();
78 let mut plugin_manager = $crate::commands::PluginManager::new();
79
80 $(
81 plugin_manager.load_plugin($plugin);
82 )+
83
84 plugin_manager.apply_to_registry(&mut registry);
85 (registry, plugin_manager)
86 }};
87}
88
89pub mod commands;
91pub mod core;
92pub mod i18n;
93pub mod input;
94pub mod output;
95pub mod setup;
96pub mod ui;
97
98pub use commands::{Command, CommandHandler, CommandPlugin, CommandRegistry, PluginManager};
100pub use core::config::Config;
101pub use core::error::{AppError, Result};
102
103pub fn create_default_registry() -> CommandRegistry {
104 use commands::{
105 clear::ClearCommand,
106 exit::exit::ExitCommand,
107 history::HistoryCommand,
108 lang::LanguageCommand,
109 log_level::LogLevelCommand,
110 performance::PerformanceCommand,
111 restart::RestartCommand,
112 theme::ThemeCommand,
113 version::VersionCommand, };
115
116 let mut registry = CommandRegistry::new();
117
118 registry.register(HistoryCommand);
119 registry.register(ExitCommand);
120 registry.register(LogLevelCommand);
121 registry.register(LanguageCommand);
122 registry.register(ClearCommand);
123 registry.register(RestartCommand);
124 registry.register(VersionCommand);
125 registry.register(PerformanceCommand);
126 registry.register(ThemeCommand); registry.initialize();
129 registry
130}
131
132pub async fn run() -> Result<()> {
134 let config = Config::load().await?;
135 let mut screen = ui::screen::ScreenManager::new(&config).await?;
136 screen.run().await
137}
138
139pub use ui::screen::ScreenManager;
141
142pub async fn run_with_config(config: Config) -> Result<()> {
144 let mut screen = ScreenManager::new(&config).await?;
145 screen.run().await
146}
147
148pub fn create_handler() -> CommandHandler {
149 CommandHandler::new()
150}
151
152pub async fn load_config() -> Result<Config> {
153 Config::load().await
154}