๐ฆ Boxen
Create beautiful boxes in the terminal with Rust
A Rust implementation of the popular boxen library for creating styled terminal boxes around text.
Features โข Installation โข Quick Start โข Examples โข Documentation
โจ Features
๐จ Styling
- Multiple border styles (single, double, round, bold, custom)
- Rich color support (named, hex, RGB)
- Title support with positioning
- Dim borders and backgrounds
๐ Layout
- Flexible text alignment (left, center, right)
- Precise padding and margins
- Width and height constraints
- Fullscreen mode
โก Performance
- 30x faster than baseline
- Thread-local string pooling
- Optional Unicode width caching
- Optional terminal size caching
๐ก๏ธ Quality
- Type-safe API with builder pattern
- Comprehensive error handling
- Unicode and ANSI aware
- 100% backward compatible
๐ฆ Installation
Add boxen to your Cargo.toml:
[]
= "0.3"
For maximum performance, enable caching features:
[]
= { = "0.3", = ["width-cache", "terminal-cache"] }
๐ Quick Start
use ;
๐ Examples
Basic Usage
Code:
use boxen;
let result = boxen
.unwrap;
println!;
Output:
โโโโโโโโโโโโ
โSimple boxโ
โโโโโโโโโโโโ
Styled Box
Code:
use ;
let result = builder
.border_style
.padding
.title
.border_color
.render
.unwrap;
Output:
โญโโโ Status โโโโโฎ
โ โ
โ All systems โ
โ operational โ
โ โ
โฐโโโโโโโโโโโโโโโโฏ
Convenience Functions
use ;
println!;
println!;
println!;
Advanced Styling
use ;
let result = builder
.border_style
.padding // top, right, bottom, left
.margin
.text_alignment
.title_alignment
.float
.width
.title
.border_color
.background_color
.render
.unwrap;
๐จ Border Styles
Boxen supports various border styles:
๐ Color Support
Boxen supports multiple color formats:
use builder;
// Named colors (16 standard terminal colors)
builder
.border_color
.background_color;
// Hex colors
builder
.border_color
.background_color;
// RGB colors
builder
.border_color
.background_color;
// Dim borders for subtle styling
builder
.border_color
.dim_border;
Available named colors:
black, red, green, yellow, blue, magenta, cyan, white,
bright-black, bright-red, bright-green, bright-yellow, bright-blue, bright-magenta, bright-cyan, bright-white
โก Performance
Boxen is highly optimized for speed and memory efficiency:
Benchmark Results
| Operation | Time | vs Baseline |
|---|---|---|
| Simple box | 1.57ฮผs | 30x faster โก |
| Unicode content | 2.93ฮผs | 40x faster โก |
| Complex styled box | 12.2ฮผs | - |
| Large text (1000 chars) | 102.75ฮผs | 8x faster โก |
| Batch (100 boxes) | 150ms | 30x faster โก |
Core Optimizations
โ
Thread-local string pooling - Reduces allocations by 24-87%
โ
Smart buffer management - Pre-allocated buffers with capacity hints
โ
Efficient ANSI handling - Proper escape sequence processing
โ
Unicode optimization - Fast width calculations
Optional Performance Features
Enable caching for even better performance:
[]
= { = "0.3", = ["width-cache", "terminal-cache"] }
| Feature | Benefit | Use Case |
|---|---|---|
width-cache |
2-3x faster Unicode | Apps with CJK text, emoji |
terminal-cache |
10-20% faster batch | Rendering multiple boxes |
dhat-heap |
Memory profiling | Development & optimization |
Performance gains:
-
90% cache hit rates for typical workloads
- Lock-free thread-local caching
- Automatic cache invalidation on terminal resize (Unix)
- Configurable cache sizes and TTL
๐ See Performance Guide for detailed information.
๐ฏ Use Cases
CLI Tools
// Success messages
println!;
// Error messages
println!;
Status Displays
// System status
println!;
Notifications
// User notifications
println!;
๐ Documentation
Guides
- ๐ API Documentation - Complete API reference
- ๐ Usage Guide - Detailed usage examples
- ๐ Customization Guide - Advanced styling techniques
- ๐ Performance Guide - Optimization strategies
- ๐ Migration Guide - Upgrading from v0.1.x
Examples
Run the included examples to see boxen in action:
# Basic usage patterns
# Color demonstrations
# Comprehensive feature showcase
# Performance testing
# Caching features demo
# Memory profiling
# Error handling patterns
# Fullscreen mode
# Interactive clock with spinner
๐ค Contributing
Contributions are welcome! Here's how you can help:
- ๐ Report bugs - Open an issue with details
- ๐ก Suggest features - Share your ideas
- ๐ Improve docs - Help others learn
- ๐ง Submit PRs - Fix bugs or add features
Please read our Contributing Guide for details.
๐ License
This project is 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.
๐ Acknowledgments
- Inspired by the original boxen TypeScript library by Sindre Sorhus
- Built with โค๏ธ for the Rust community
- Thanks to all contributors
Made with ๐ฆ Rust โข Report Bug โข Request Feature