A comprehensive Unicode character library for Rust applications, particularly useful for terminal applications, editors, and CLI tools that need consistent Unicode symbol support across different environments and themes.
- Multiple themes: Support for Minimal (ASCII), Basic, Rich, and Fancy Unicode themes
- Categorized symbols: Organized into logical groups (arrows, blocks, shapes, git, etc.)
- Fallback support: Graceful degradation to ASCII when Unicode isn't supported
- Global configuration: Set theme and overrides globally for your application
- Type-safe: All symbols are strongly typed enums
- Security utilities: Detect dangerous Unicode characters and potential attacks
- Zero dependencies: Pure Rust implementation with no external dependencies
Add this to your Cargo.toml
:
[dependencies]
unicode-rs = "0.1.0"
use unicode_rs::prelude::*;
// Use symbols with different themes
let check_minimal = Symbol::Check.get_char(UnicodeTheme::Minimal); // 'v'
let check_rich = Symbol::Check.get_char(UnicodeTheme::Rich); // '✓'
let check_fancy = Symbol::Check.get_char(UnicodeTheme::Fancy); // '✅'
// Use arrows
let right_arrow = Arrow::Right.get_char(UnicodeTheme::Rich); // '→'
let up_arrow = Arrow::Up.get_char(UnicodeTheme::Rich); // '↑'
// Git symbols
let modified = GitStatus::Modified.get_char(UnicodeTheme::Rich); // '●'
let added = GitStatus::Added.get_char(UnicodeTheme::Rich); // '+'
use unicode_rs::prelude::*;
// Set global theme
set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
// Now all symbols will use the minimal theme by default
let check = get_char(&Symbol::Check, None); // 'v'
let arrow = get_char(&Arrow::Right, None); // '>'
use unicode_rs::prelude::*;
// Create config with custom overrides
let config = UnicodeConfig::with_theme(UnicodeTheme::Rich)
.with_override("custom_check", '√')
.with_fallback(); // Enable ASCII fallback for unsupported terminals
set_global_config(config);
use unicode_rs::security::*;
// Analyze text for security issues
let analysis = analyze_text("Hello\u{200B}World"); // Contains zero-width space
if analysis.risk_level >= RiskLevel::High {
println!("⚠️ Security risk detected!");
println!("{}", generate_security_report("Hello\u{200B}World"));
}
// Sanitize dangerous text
let safe_text = sanitize_text("Hello\u{200B}World\u{202E}");
assert_eq!(safe_text, "HelloWorld");
- Check marks, X marks, exclamation, question marks
- Copyright, trademark, registered symbols
- Directional arrows (up, down, left, right)
- Navigation symbols (home, end, page up/down)
- Box drawing characters
- Block elements for progress bars and layouts
- Geometric shapes (circles, squares, triangles)
- Filled and outlined variants
- Status indicators (modified, added, deleted, etc.)
- Diff symbols (plus, minus, delta)
- Branch and action symbols
- Language-specific file type indicators
- Generic file and folder symbols
- Borders and separators
- Control symbols
- Status indicators
- Cursor and selection indicators
- Text editing symbols
The library supports four different themes:
- Minimal: ASCII-only characters for maximum compatibility
- Basic: Basic Unicode symbols
- Rich: Full Unicode symbol set (default)
- Fancy: Decorative Unicode with emoji-style characters
Check out the examples/
directory for more comprehensive usage examples:
basic_usage.rs
- Simple symbol usagegit_status.rs
- Git status displayfile_browser.rs
- File browser with type indicatorssecurity_analysis.rs
- Unicode security vulnerability detection
This project is licensed under MIT
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.