unicode_rs/
lib.rs

1//! # Unicode-rs
2//!
3//! A comprehensive Unicode character library for Rust applications, particularly useful for
4//! terminal applications, editors, and CLI tools that need consistent Unicode symbol support
5//! across different environments and themes.
6//!
7//! ## Features
8//!
9//! - **Multiple themes**: Support for Minimal (ASCII), Basic, Rich, and Fancy Unicode themes
10//! - **Categorized symbols**: Organized into logical groups (arrows, blocks, shapes, git, etc.)
11//! - **Fallback support**: Graceful degradation to ASCII when Unicode isn't supported
12//! - **Global configuration**: Set theme and overrides globally for your application
13//! - **Type-safe**: All symbols are strongly typed enums
14//!
15//! ## Quick Start
16//!
17//! ```rust
18//! use unicode_rs::prelude::*;
19//!
20//! // Use with default theme (Rich)
21//! let check = Symbol::Check.get_char(UnicodeTheme::Rich); // ✓
22//! let arrow = Arrow::Right.get_char(UnicodeTheme::Rich);  // →
23//!
24//! // Configure globally
25//! set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
26//! let check_ascii = get_char(&Symbol::Check, None); // v
27//! ```
28//!
29//! ## Theme Comparison
30//!
31//! | Symbol | Minimal | Basic | Rich | Fancy |
32//! |--------|---------|-------|------|-------|
33//! | Check  | `v`     | `✓`   | `✓`  | `✅`  |
34//! | Arrow Right | `>` | `→`   | `→`  | `⮕`  |
35//! | Git Modified | `M` | `●`   | `●`  | `◐`  |
36//!
37//! ## Advanced Usage
38//!
39//! ### Custom Configuration
40//! ```rust
41//! use unicode_rs::prelude::*;
42//!
43//! // Create a config with fallback and custom overrides
44//! let config = UnicodeConfig::with_theme(UnicodeTheme::Rich)
45//!     .with_fallback()  // Fall back to ASCII if Unicode fails
46//!     .with_override("custom_bullet", '•');
47//!
48//! set_global_config(config);
49//! ```
50//!
51//! ### Terminal Compatibility
52//! ```rust
53//! use unicode_rs::prelude::*;
54//!
55//! // Detect terminal capabilities and choose appropriate theme
56//! let theme = if std::env::var("TERM").unwrap_or_default().contains("xterm") {
57//!     UnicodeTheme::Rich
58//! } else {
59//!     UnicodeTheme::Minimal
60//! };
61//!
62//! set_global_config(UnicodeConfig::with_theme(theme));
63//! ```
64//!
65//! ## Modules
66//!
67//! - [`symbols`] - General symbols (checkmarks, exclamation, etc.)
68//! - [`arrows`] - Directional arrows and navigation symbols
69//! - [`blocks`] - Block drawing characters
70//! - [`shapes`] - Geometric shapes
71//! - [`git`] - Git status and diff symbols
72//! - [`file_types`] - File type indicators
73//! - [`ui`] - UI elements (borders, separators, etc.)
74//! - [`editor`] - Editor-specific symbols (cursor, selection)
75//! - [`status`] - Status indicators
76//! - [`security`] - Unicode security utilities for detecting dangerous characters
77
78pub mod unicode;
79
80// Re-export the main types for convenience
81pub use unicode::*;
82
83/// Prelude module for convenient imports
84pub mod prelude {
85    pub use crate::unicode::{
86        get_char, get_file_type_from_extension, get_file_type_from_filename, get_global_config,
87        get_str, set_global_config, Arrow, Block, Border, Control, Cursor, FileType, GitAction,
88        GitBranch, GitDiff, GitStatus, Indicator, LanguageType, Navigation, Selection, Separator,
89        Shape, Status, Symbol, UnicodeConfig, UnicodeProvider, UnicodeTheme,
90    };
91}
92
93#[cfg(test)]
94mod tests {
95    use super::prelude::*;
96
97    #[test]
98    fn test_symbol_themes() {
99        // Test different themes for the same symbol
100        assert_eq!(Symbol::Check.get_char(UnicodeTheme::Minimal), 'v');
101        assert_eq!(Symbol::Check.get_char(UnicodeTheme::Basic), '✓');
102        assert_eq!(Symbol::Check.get_char(UnicodeTheme::Rich), '✓');
103    }
104
105    #[test]
106    fn test_global_config() {
107        // Test global configuration
108        set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
109        let config = get_global_config();
110        assert_eq!(config.theme, UnicodeTheme::Minimal);
111
112        let check_char = get_char(&Symbol::Check, None);
113        assert_eq!(check_char, 'v');
114    }
115
116    #[test]
117    fn test_config_with_fallback() {
118        let config = UnicodeConfig::with_theme(UnicodeTheme::Rich).with_fallback();
119        assert!(config.use_fallback);
120    }
121
122    #[test]
123    fn test_config_with_override() {
124        let config = UnicodeConfig::default().with_override("custom_check", '√');
125        assert_eq!(config.overrides.get("custom_check"), Some(&'√'));
126    }
127}