unicode-rs
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.
Features
- 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
Quick Start
Add this to your Cargo.toml
:
[]
= "0.1.0"
Usage
Basic Usage
use *;
// Use symbols with different themes
let check_minimal = Check.get_char; // 'v'
let check_rich = Check.get_char; // '✓'
let check_fancy = Check.get_char; // '✅'
// Use arrows
let right_arrow = Right.get_char; // '→'
let up_arrow = Up.get_char; // '↑'
// Git symbols
let modified = Modified.get_char; // '●'
let added = Added.get_char; // '+'
Global Configuration
use *;
// Set global theme
set_global_config;
// Now all symbols will use the minimal theme by default
let check = get_char; // 'v'
let arrow = get_char; // '>'
Custom Overrides
use *;
// Create config with custom overrides
let config = with_theme
.with_override
.with_fallback; // Enable ASCII fallback for unsupported terminals
set_global_config;
Unicode Security
use *;
// Analyze text for security issues
let analysis = analyze_text; // Contains zero-width space
if analysis.risk_level >= High
// Sanitize dangerous text
let safe_text = sanitize_text;
assert_eq!;
Available Symbol Categories
Symbols
- Check marks, X marks, exclamation, question marks
- Copyright, trademark, registered symbols
Arrows
- Directional arrows (up, down, left, right)
- Navigation symbols (home, end, page up/down)
Blocks
- Box drawing characters
- Block elements for progress bars and layouts
Shapes
- Geometric shapes (circles, squares, triangles)
- Filled and outlined variants
Git
- Status indicators (modified, added, deleted, etc.)
- Diff symbols (plus, minus, delta)
- Branch and action symbols
File Types
- Language-specific file type indicators
- Generic file and folder symbols
UI Elements
- Borders and separators
- Control symbols
- Status indicators
Editor
- Cursor and selection indicators
- Text editing symbols
Themes
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
Examples
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
License
This project is licensed under MIT
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.