What is Glyphs?
Glyphs is a Rust library for working with ANSI escape sequences. It lets you:
- Style terminal output with a fluent, type-safe API
- Parse existing sequences into human-readable descriptions
- Strip ANSI codes from strings
- Control cursors and screens with named constants
Think of it as the Rust equivalent of sequin from Charmbracelet.
use ;
// Style text beautifully
let output = style
.fg // Molten Orange
.bold
.to_string;
println!;
// Parse mystery sequences
for segment in parse
Features
🎨 Fluent Styling API
style
.fg
.bg
.bold
.italic
.underline
🔍 Sequence Parsing
parse
// → [Escape(red fg), Text("red"), Escape(reset)]
🌈 Full Color Support
- Standard 16 colors
- 256-color palette
- True color (24-bit RGB)
- Hex color parsing
🧹 String Utilities
strip_ansi // "Hello"
visible_len // 5
Installation
Or add to your Cargo.toml:
[]
= "0.1"
With Molten Brand Colors
[]
= { = "0.1", = ["brand"] }
Quick Start
Basic Styling
use ;
// Simple colors
let red = style.fg.to_string;
let warning = style.fg.bold.to_string;
// RGB colors
let custom = style
.fg
.to_string;
// Hex colors
let hex = style
.fg
.to_string;
// 256-color palette
let palette = style
.fg
.to_string;
Text Modifiers
use ;
let styled = style
.bold // Bold text
.italic // Italic
.underline // Underlined
.strikethrough // Strikethrough
.dim // Dimmed
.reverse // Inverted colors
.blink // Blinking (if supported)
.to_string;
Combining Styles
use ;
let fancy = style
.fg
.bold
.underline
.to_string;
println!;
Parsing
Parse ANSI Sequences
Turn cryptic escape codes into readable descriptions:
use ;
let input = "\x1b[1;38;2;249;115;22mMolten\x1b[0m";
for segment in parse
Strip ANSI Codes
use strip_ansi;
let styled = "\x1b[1;31mBold Red\x1b[0m Normal";
let plain = strip_ansi;
assert_eq!;
Get Visible Length
use visible_len;
let styled = "\x1b[31mHello\x1b[0m";
assert_eq!; // Not 14!
Cursor & Screen Control
Cursor Movement
use cursor;
// Move cursor
print!; // Move up 5 lines
print!; // Move down 3 lines
print!; // Move left 10 columns
print!; // Move right 10 columns
// Position cursor
print!; // Row 10, Column 20
print!; // Start of line
Screen Control
use sequences;
// Clear screen
print!;
print!;
// Cursor visibility
print!;
// ... do stuff ...
print!;
// Alternate screen buffer (for TUIs)
print!;
// ... your TUI ...
print!;
Color Reference
Standard Colors
| Color | Code | Bright Variant |
|---|---|---|
Color::Black |
30 | Color::BrightBlack |
Color::Red |
31 | Color::BrightRed |
Color::Green |
32 | Color::BrightGreen |
Color::Yellow |
33 | Color::BrightYellow |
Color::Blue |
34 | Color::BrightBlue |
Color::Magenta |
35 | Color::BrightMagenta |
Color::Cyan |
36 | Color::BrightCyan |
Color::White |
37 | Color::BrightWhite |
RGB & Hex
rgb // Orange
from_hex // Molten Orange
from_hex // Goblin Purple (# optional)
256-Color Palette
ansi256 // Black
ansi256 // Bright red
ansi256 // Orange
ansi256 // White
Modifier Reference
| Modifier | ANSI Code | Description |
|---|---|---|
.bold() |
1 | Bold text |
.dim() |
2 | Dimmed text |
.italic() |
3 | Italic text |
.underline() |
4 | Underlined |
.blink() |
5 | Blinking text |
.reverse() |
7 | Inverted colors |
.hidden() |
8 | Hidden text |
.strikethrough() |
9 |
Ecosystem
Glyphs is part of the Molten Labs open source ecosystem:
| Crate | Description | Status |
|---|---|---|
| molten_brand | Design tokens & colors | ✅ Published |
| glyphs | ANSI sequences (you are here) | ✅ Published |
| lacquer | Terminal styling (like lipgloss) | ✅ Published |
| cauldron | TUI framework (like bubbletea) | 📋 Planned |
Why "Glyphs"?
A glyph is a symbolic mark or character—like the hidden ANSI codes that transform plain text into beautiful terminal output. In the forge, we inscribe glyphs to add magic to our creations. ✨
Performance
- Zero allocations for static styling
- Compile-time color constants
- Efficient parsing with minimal copies
- Suitable for hot paths and TUI rendering loops
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.