shortcuts_tui/lib.rs
1//! Shortcuts TUI Library
2//!
3//! A comprehensive library for creating terminal user interfaces that display and manage
4//! tools and shortcuts from configuration files.
5//!
6//! # Features
7//!
8//! - **Multiple Configuration Formats**: Support for both TOML and JSON configuration files
9//! - **Rich TUI Interface**: Built with ratatui for a modern terminal experience
10//! - **Flexible Organization**: Tools can be organized by categories and tagged for easy searching
11//! - **Command Execution**: Execute tool commands directly from the interface
12//! - **Search Functionality**: Powerful search across tool names, descriptions, and metadata
13//! - **Validation**: Built-in configuration validation and error reporting
14//! - **Extensible**: Modular design allows for easy extension and customization
15//!
16//! # Quick Start
17//!
18//! ```rust,no_run
19//! use shortcuts_tui::{
20//! config::{Config, Tool, loader::ConfigLoader},
21//! ui::TuiApp,
22//! };
23//!
24//! # fn main() -> shortcuts_tui::error::Result<()> {
25//! // Load configuration from file
26//! let loader = ConfigLoader::new();
27//! let config = loader.load_file("shortcuts.toml")?;
28//!
29//! // Create and run the TUI application
30//! let app = TuiApp::new(config)?;
31//! app.run()?;
32//! # Ok(())
33//! # }
34//! ```
35//!
36//! # Configuration Example
37//!
38//! ## TOML Format
39//!
40//! ```toml
41//! [metadata]
42//! title = "My Development Tools"
43//! description = "A collection of useful development tools"
44//! version = "1.0"
45//! author = "Developer"
46//!
47//! [[categories]]
48//! id = "dev"
49//! name = "Development"
50//! description = "Software development tools"
51//! icon = "💻"
52//! color = "blue"
53//!
54//! [[tools]]
55//! id = "git_status"
56//! name = "Git Status"
57//! description = "Check git repository status"
58//! command = "git status"
59//! shortcut = "Ctrl+G S"
60//! category = "dev"
61//! tags = ["git", "vcs"]
62//! priority = 10
63//! enabled = true
64//!
65//! [tools.metadata]
66//! documentation = "https://git-scm.com/docs/git-status"
67//! ```
68//!
69//! ## JSON Format
70//!
71//! ```json
72//! {
73//! "metadata": {
74//! "title": "My Development Tools",
75//! "description": "A collection of useful development tools",
76//! "version": "1.0",
77//! "author": "Developer"
78//! },
79//! "categories": [
80//! {
81//! "id": "dev",
82//! "name": "Development",
83//! "description": "Software development tools",
84//! "icon": "💻",
85//! "color": "blue"
86//! }
87//! ],
88//! "tools": [
89//! {
90//! "id": "git_status",
91//! "name": "Git Status",
92//! "description": "Check git repository status",
93//! "command": "git status",
94//! "shortcut": "Ctrl+G S",
95//! "category": "dev",
96//! "tags": ["git", "vcs"],
97//! "priority": 10,
98//! "enabled": true,
99//! "metadata": {
100//! "documentation": "https://git-scm.com/docs/git-status"
101//! }
102//! }
103//! ]
104//! }
105//! ```
106//!
107//! # Architecture
108//!
109//! The library is organized into several key modules:
110//!
111//! - [`config`]: Configuration loading, parsing, and validation
112//! - [`ui`]: Terminal user interface components and application logic
113//! - [`error`]: Comprehensive error handling and reporting
114//!
115//! ## Configuration System
116//!
117//! The configuration system supports:
118//! - Multiple file formats (TOML, JSON)
119//! - Automatic format detection
120//! - Schema validation
121//! - Default value handling
122//! - Search path resolution
123//!
124//! ## User Interface
125//!
126//! The TUI provides:
127//! - Multiple view modes (tools, categories, search, help)
128//! - Keyboard navigation and shortcuts
129//! - Real-time search and filtering
130//! - Tool execution capabilities
131//! - Responsive layout design
132//!
133//! ## Error Handling
134//!
135//! Comprehensive error handling with:
136//! - Structured error types
137//! - Context preservation
138//! - User-friendly error messages
139//! - Graceful degradation
140
141pub mod config;
142pub mod error;
143pub mod ui;
144
145// Re-export commonly used types for convenience
146pub use config::{Config, Tool, Category, ConfigFormat};
147pub use error::{Result, ShortcutsError, ConfigError, UiError};
148
149/// Library version information
150pub const VERSION: &str = env!("CARGO_PKG_VERSION");
151
152/// Library name
153pub const NAME: &str = env!("CARGO_PKG_NAME");
154
155/// Library description
156pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
157
158/// Get library version information
159pub fn version() -> &'static str {
160 VERSION
161}
162
163/// Get library name
164pub fn name() -> &'static str {
165 NAME
166}
167
168/// Get library description
169pub fn description() -> &'static str {
170 DESCRIPTION
171}
172
173/// Create a sample configuration for demonstration purposes
174///
175/// # Returns
176///
177/// A [`Config`] instance populated with sample tools and categories
178/// that demonstrate the various features of the configuration system.
179///
180/// # Example
181///
182/// ```rust
183/// use shortcuts_tui::sample_config;
184///
185/// let config = sample_config();
186/// assert!(!config.tools.is_empty());
187/// assert!(!config.categories.is_empty());
188/// ```
189pub fn sample_config() -> Config {
190 config::loader::create_sample_config()
191}
192
193#[cfg(test)]
194mod tests {
195 use super::*;
196
197 #[test]
198 fn test_version_info() {
199 assert!(!version().is_empty());
200 assert!(!name().is_empty());
201 assert!(!description().is_empty());
202 }
203
204 #[test]
205 fn test_sample_config() {
206 let config = sample_config();
207 assert!(!config.tools.is_empty());
208 assert!(!config.categories.is_empty());
209
210 // Validate the sample config
211 assert!(config.validate().is_ok());
212 }
213
214 #[test]
215 fn test_constants() {
216 assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
217 assert_eq!(NAME, env!("CARGO_PKG_NAME"));
218 assert_eq!(DESCRIPTION, env!("CARGO_PKG_DESCRIPTION"));
219 }
220}