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, exit::exit::ExitCommand, history::HistoryCommand,
106 lang::LanguageCommand, log_level::LogLevelCommand, performance::PerformanceCommand,
107 restart::RestartCommand, theme::ThemeCommand, version::VersionCommand,
108 };
109
110 let mut registry = CommandRegistry::new();
111
112 registry.register(HistoryCommand);
113 registry.register(ExitCommand);
114 registry.register(LogLevelCommand);
115 registry.register(LanguageCommand::new()); registry.register(ClearCommand);
117 registry.register(RestartCommand);
118 registry.register(VersionCommand);
119 registry.register(PerformanceCommand);
120 registry.register(ThemeCommand::new()); registry.initialize();
123 registry
124}
125
126pub async fn run() -> Result<()> {
128 let config = Config::load().await?;
129 let mut screen = ui::screen::ScreenManager::new(&config).await?;
130 screen.run().await
131}
132
133pub use ui::screen::ScreenManager;
135
136pub async fn run_with_config(config: Config) -> Result<()> {
138 let mut screen = ScreenManager::new(&config).await?;
139 screen.run().await
140}
141
142pub fn create_handler() -> CommandHandler {
143 CommandHandler::new()
144}
145
146pub async fn load_config() -> Result<Config> {
147 Config::load().await
148}