prettychars
Unicode text styling and named glyph lookup with zero runtime overhead.
Features
- 24 Text Styles: Transform text into mathematical bold, circled, fullwidth, and more
- 531 Named Glyphs: Look up Unicode symbols by intuitive names like
arrow.rightorstar.filled - Zero Runtime Cost: Uses compile-time perfect hash functions for O(1) lookups
- VS15 Handling: Automatically applies variation selectors for consistent text rendering
- No Dependencies: Minimal footprint (except PHF for static data generation)
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Text Styling
use ;
// Mathematical styles
let bold = style; // ๐๐๐ฅ๐ฅ๐จ
let italic = style; // ๐๐๐๐๐
let mono = style; // ๐ฒ๐๐๐
// Enclosed styles
let circled = style; // โโโโ
let squared = style; // ๐
๐ฐ๐
๐ฝ
// Typography
let fancy = style; // ๐ฎ๐ธ๐๐พ๐
๐
let gothic = style; // ๐๐ฏ๐๐จ๐ฑ๐ฒ๐ฏ
// Technical
let wide = style; // ๏ผฆ๏ฝ๏ฝ๏ฝ
let small = style; // แดแดแด๊ฑ
Named Glyphs
use glyph;
// Arrows
println!; // โ
println!; // โ
// Box drawing
println!; // โ
println!; // โ
// Symbols
println!; // โ
println!; // โ
println!; // โฅ
// Math
println!; // โ
println!; // โ
// Currency
println!; // โฌ
println!; // โฟ
Discovery
use ;
// Find all arrow glyphs
for name in glyph_names.filter
// List all available styles
for style in style_names
Chaining Operations
Combine multiple prettychars operations for rich terminal interfaces:
use ;
// Progress bars with mixed elements
let progress = format!;
// Status indicators with styled text
let status = format!;
// Complex UI elements
let title = format!;
See examples/chaining.rs for complete patterns.
Available Styles
Mathematical
MathBold- Bold (๐๐๐๐๐๐๐๐๐)Italic- Italic (๐ด๐ต๐ถ๐๐๐)BoldItalic- Bold italic (๐จ๐ฉ๐ช๐๐๐)DoubleStruck- Blackboard bold (๐ธ๐นโ๐๐๐๐๐๐)
Enclosed
Circled- Circled letters (โถโทโธโถโทโธ)CircledNegative- Negative circled (๐ ๐ ๐ )Squared- Squared letters (๐ฐ๐ฑ๐ฒ)SquaredNegative- Negative squared (๐ ฐ๐ ฑ๐ ฒ)Parenthesized- Parenthesized (โโโ)
Typography
Fraktur- Gothic/Blackletter (๐๐ ๐๐๐๐ )FrakturBold- Bold Fraktur (๐ฌ๐ญ๐ฎ๐๐๐)Script- Calligraphic (๐โฌ๐๐ถ๐ท๐ธ)ScriptBold- Bold script (๐๐๐๐ช๐ซ๐ฌ)SmallCaps- Small capitals (แดสแด)
Technical
Monospace- Fixed-width (๐ฐ๐ฑ๐ฒ๐๐๐๐ถ๐ท๐ธ)Fullwidth- East Asian fullwidth (๏ผก๏ผข๏ผฃ๏ฝ๏ฝ๏ฝ๏ผ๏ผ๏ผ)SansSerif- Sans-serif (๐ ๐ก๐ข๐บ๐ป๐ผ๐ข๐ฃ๐ค)SansSerifBold- Bold sans-serif (๐๐๐๐ฎ๐ฏ๐ฐ๐ฌ๐ญ๐ฎ)SansSerifItalic- Italic sans-serif (๐๐๐๐ข๐ฃ๐ค)SansSerifBoldItalic- Bold italic sans-serif (๐ผ๐ฝ๐พ๐๐๐)
Effects
Superscript- Raised (แดฌแดฎแถโฐยนยฒ)Subscript- Lowered (โโโโโโ)Strikethrough- Struck through (AฬถBฬถCฬถ)Inverted- Upside down (ษqษ)
Glyph Categories
The 531 named glyphs are organized into categories:
- Arrows: Directional arrows, double arrows, dashed arrows
- Box Drawing: Light, heavy, double, and rounded box components
- Blocks: Full, partial, and shaded blocks for graphics
- Shapes: Circles, squares, triangles, diamonds (filled and empty)
- Check Marks: Checkboxes, check marks, X marks
- Numbers: Circled, parenthesized, period-suffixed, roman numerals
- Stars: Various star styles and sizes
- Card Suits: Spades, hearts, diamonds, clubs
- Dice: Six-sided die faces
- Music: Notes, sharps, flats, naturals
- Math: Operators, relations, set theory, logic symbols
- Greek: Complete lowercase and uppercase Greek alphabet
- Superscripts/Subscripts: Numbers and operators
- Fractions: Common fractions like ยฝ, โ , ยผ
- Currency: Dollar, euro, pound, bitcoin, and more
- Miscellaneous: Symbols, emoji, weather, hazards, tools
- Keyboard: Mac modifier keys (โ, โฅ, โ, โง)
- Chess: White and black pieces
Design Principles
Zero Runtime Cost
All glyph lookups use PHF (Perfect Hash Function) to generate compile-time hash maps. This means:
- O(1) lookup time for all 531 glyphs
- No runtime hash computation
- No memory allocation
- Minimal binary size impact
VS15 Transparency
All glyphs have VS15 (U+FE0E, Variation Selector-15) applied automatically. VS15 requests text-style rendering rather than emoji-style rendering, ensuring consistent appearance across platforms. This is completely transparent to callers.
Stable Name Registry
The glyph name registry is append-only. Names are never removed or changed once published, ensuring your code won't break with updates. New glyphs may be added in minor version releases.
Use Cases
- Terminal UIs: Rich text formatting, progress bars, box drawing
- Logging: Styled log levels, status indicators, symbols
- Documentation: Mathematical notation, special symbols
- CLI Tools: Fancy output, Unicode art, tables
- Text Processing: Transform text for social media, messaging
Performance
Benchmarking on a modern CPU shows:
- Glyph lookup: ~2ns per lookup (faster than a HashMap)
- Text styling: ~15ns per character
- Zero allocations for lookups (except result String for styling)
The entire compiled PHF map for 531 glyphs adds approximately 8KB to your binary.
Compatibility
- Rust Version: Requires Rust 1.70 or newer
- Edition: 2021
- no_std: Not currently supported (uses
std::fmtfor errors)
Examples
Progress Bar
use glyph;
draw_progress; // [โโโโโโโโโโโโโโโโโโโโ] 65%
Styled CLI Output
use ;
Unicode Table
use glyph;
Terminal Examples
Run these examples to see prettychars in action:
Chess Board (cargo run --example chessboard)
- Renders a complete 8x8 chess board with pieces in starting position
- Uses double-line box drawing (โโโโโ) for the grid structure
- Shows checkerboard pattern with Unicode shade characters
- Displays all 12 chess pieces: โโโโโโ (white) and โโโโโโ (black)
- Includes algebraic notation (a-h columns, 1-8 rows)
System Dashboard (cargo run --example dashboard)
- Creates a monitoring interface with multiple sections
- Progress bars using 8-level gradient blocks (โโโโโ โโโ)
- Service status indicators with checkmarks (โ) and crosses (โ)
- Sparkline charts for network traffic visualization
- Warning alerts with appropriate symbols (โ )
- Professional layout using heavy box drawing characters
Both examples demonstrate:
- Zero runtime overhead through PHF lookups
- Rich terminal UIs using only Unicode characters
- Proper alignment and spacing in terminal environments
Note: GitHub's markdown renderer cannot properly display Unicode box-drawing alignment. The examples render perfectly in actual terminals. See TERMINAL_COMPATIBILITY.md for terminal-specific guidance.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- 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.
When suggesting new glyphs, please ensure they:
- Have a clear, intuitive name following the existing naming scheme
- Are widely supported across platforms
- Fill a genuine use case
Acknowledgments
Extracted from the mdfx project by Blackwell Systems, this crate provides the Unicode styling and glyph functionality as a standalone library.