# prettychars
[](https://crates.io/crates/prettychars)
[](https://docs.rs/prettychars)
[](LICENSE)
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.right` or `star.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`:
```toml
[dependencies]
prettychars = "0.1"
```
### Text Styling
```rust
use prettychars::{style, Style};
// Mathematical styles
let bold = style("Hello", Style::MathBold); // ๐๐๐ฅ๐ฅ๐จ
let italic = style("World", Style::Italic); // ๐๐๐๐๐
let mono = style("Code", Style::Monospace); // ๐ฒ๐๐๐
// Enclosed styles
let circled = style("RUST", Style::Circled); // โโโโ
let squared = style("WARN", Style::Squared); // ๐
๐ฐ๐
๐ฝ
// Typography
let fancy = style("Script", Style::Script); // ๐ฎ๐ธ๐๐พ๐
๐
let gothic = style("Fraktur", Style::Fraktur); // ๐๐ฏ๐๐จ๐ฑ๐ฒ๐ฏ
// Technical
let wide = style("Full", Style::Fullwidth); // ๏ผฆ๏ฝ๏ฝ๏ฝ
let small = style("CAPS", Style::SmallCaps); // แดแดแด๊ฑ
```
### Named Glyphs
```rust
use prettychars::glyph;
// Arrows
println!("{}", glyph("arrow.right").unwrap()); // โ
println!("{}", glyph("arrow.double-left").unwrap()); // โ
// Box drawing
println!("{}", glyph("box.light.tl").unwrap()); // โ
println!("{}", glyph("box.heavy.cross").unwrap()); // โ
// Symbols
println!("{}", glyph("check.mark").unwrap()); // โ
println!("{}", glyph("star.filled").unwrap()); // โ
println!("{}", glyph("heart").unwrap()); // โฅ
// Math
println!("{}", glyph("math.infinity").unwrap()); // โ
println!("{}", glyph("math.sum").unwrap()); // โ
// Currency
println!("{}", glyph("currency.euro").unwrap()); // โฌ
println!("{}", glyph("currency.bitcoin").unwrap()); // โฟ
```
### Discovery
```rust
use prettychars::{glyph_names, style_names};
// Find all arrow glyphs
for name in glyph_names().filter(|n| n.starts_with("arrow.")) {
println!("{}: {}", name, glyph(name).unwrap());
}
// List all available styles
for style in style_names() {
println!("{:?}", style);
}
```
### Chaining Operations
Combine multiple prettychars operations for rich terminal interfaces:
```rust
use prettychars::{glyph, style, Style};
// Progress bars with mixed elements
let progress = format!(
"{} [{}{}] {}% {}",
glyph("arrow.right").unwrap(),
glyph("block.full").unwrap().repeat(7),
glyph("block.left.4").unwrap(),
75,
glyph("check.mark").unwrap()
);
// Status indicators with styled text
let status = format!("{} {}",
glyph("misc.warning").unwrap(),
style("HIGH CPU", Style::MathBold)
);
// Complex UI elements
let title = format!("{} {} {}",
glyph("star").unwrap(),
style("DASHBOARD", Style::SmallCaps),
glyph("star").unwrap()
);
```
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)](https://github.com/rust-phf/rust-phf) 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::fmt` for errors)
## Examples
### Progress Bar
```rust
use prettychars::glyph;
fn draw_progress(percent: u8) {
let filled = glyph("block.full").unwrap();
let empty = glyph("block.empty").unwrap();
let bar_width = 20;
let filled_count = (percent as usize * bar_width) / 100;
print!("[");
for i in 0..bar_width {
print!("{}", if i < filled_count { filled } else { empty });
}
println!("] {}%", percent);
}
draw_progress(65); // [โโโโโโโโโโโโโโโโโโโโ] 65%
```
### Styled CLI Output
```rust
use prettychars::{style, glyph, Style};
fn log_message(level: &str, msg: &str) {
let (symbol, styled_level) = match level {
"error" => (glyph("check.x.heavy").unwrap(),
style("ERROR", Style::MathBold)),
"warn" => (glyph("misc.warning").unwrap(),
style("WARN", Style::Squared)),
"info" => (glyph("check.mark").unwrap(),
style("INFO", Style::Circled)),
_ => ("?", level.to_string()),
};
println!("{} {} {}", symbol, styled_level, msg);
}
```
### Unicode Table
```rust
use prettychars::glyph;
fn draw_table() {
let tl = glyph("box.heavy.tl").unwrap();
let tr = glyph("box.heavy.tr").unwrap();
let bl = glyph("box.heavy.bl").unwrap();
let br = glyph("box.heavy.br").unwrap();
let h = glyph("box.heavy.h").unwrap();
let v = glyph("box.heavy.v").unwrap();
println!("{}{:โ<20}{}", tl, "", tr);
println!("{} {:18} {}", v, "Table Content", v);
println!("{}{:โ<20}{}", bl, "", br);
}
```
### 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](TERMINAL_COMPATIBILITY.md) for terminal-specific guidance.
## License
Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](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](https://github.com/blackwell-systems/utf8fx) project by Blackwell Systems, this crate provides the Unicode styling and glyph functionality as a standalone library.