| Crates.io | boxen |
| lib.rs | boxen |
| version | 0.3.1 |
| created_at | 2025-09-09 19:38:14.417076+00 |
| updated_at | 2026-01-25 21:27:17.324303+00 |
| description | A Rust library for creating styled terminal boxes around text with performance optimizations |
| homepage | |
| repository | https://github.com/sabry-awad97/boxen |
| max_upload_size | |
| id | 1831435 |
| size | 670,903 |
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
๐จ Styling
|
๐ Layout
|
โก Performance
|
๐ก๏ธ Quality
|
Add boxen to your Cargo.toml:
[dependencies]
boxen = "0.3"
For maximum performance, enable caching features:
[dependencies]
boxen = { version = "0.3", features = ["width-cache", "terminal-cache"] }
use ::boxen::{boxen, builder, BorderStyle, TextAlignment};
fn main() {
// Simple box with default settings
let simple = boxen("Hello, World!", None).unwrap();
println!("{}", simple);
// โโโโโโโโโโโโโโโ
// โHello, World!โ
// โโโโโโโโโโโโโโโ
// Styled box with builder pattern
let fancy = builder()
.border_style(BorderStyle::Double)
.padding(2)
.text_alignment(TextAlignment::Center)
.title("Greeting")
.border_color("blue")
.render("Hello, World!")
.unwrap();
println!("{}", fancy);
}
|
Code:
|
Output:
|
|
Code:
|
Output:
|
use ::boxen::{simple_box, double_box, round_box};
println!("{}", simple_box("Default style"));
println!("{}", double_box("Double border"));
println!("{}", round_box("Round corners"));
use ::boxen::{builder, BorderStyle, TextAlignment, TitleAlignment, Float};
let result = builder()
.border_style(BorderStyle::Bold)
.padding((2, 4, 2, 4)) // top, right, bottom, left
.margin(1)
.text_alignment(TextAlignment::Center)
.title_alignment(TitleAlignment::Center)
.float(Float::Center)
.width(40)
.title("๐ Celebration")
.border_color("#ff6b6b")
.background_color("#ffe66d")
.render("Congratulations!\nYou've mastered boxen!")
.unwrap();
Boxen supports various border styles:
| Style | Preview | Description |
|---|---|---|
Single |
โโโ โ โ โโโ |
Clean single-line borders |
Double |
โโโ โ โ โโโ |
Bold double-line borders |
Round |
โญโโฎ โ โ โฐโโฏ |
Smooth rounded corners |
Bold |
โโโ โ โ โโโ |
Heavy bold borders |
SingleDouble |
โโโ โ โ โโโ |
Single horizontal, double vertical |
DoubleSingle |
โโโ โ โ โโโ |
Double horizontal, single vertical |
Classic |
+--+ | | +--+ |
ASCII-compatible classic style |
Boxen supports multiple color formats:
use ::boxen::builder;
// Named colors (16 standard terminal colors)
builder()
.border_color("red")
.background_color("blue");
// Hex colors
builder()
.border_color("#ff0000")
.background_color("#0000ff");
// RGB colors
builder()
.border_color((255, 0, 0))
.background_color((0, 0, 255));
// Dim borders for subtle styling
builder()
.border_color("cyan")
.dim_border(true);
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
Boxen is highly optimized for speed and memory efficiency:
| 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 โก |
โ
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
Enable caching for even better performance:
[dependencies]
boxen = { version = "0.3", features = ["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
๐ See Performance Guide for detailed information.
CLI Tools
|
Status Displays
|
Notifications
|
Run the included examples to see boxen in action:
# Basic usage patterns
cargo run --example main_api_demo
# Color demonstrations
cargo run --example color_demo
# Comprehensive feature showcase
cargo run --example comprehensive_demo
# Performance testing
cargo run --example performance_demo
# Caching features demo
cargo run --example caching_demo --features width-cache,terminal-cache
# Memory profiling
cargo run --example memory_profiling --features dhat-heap
# Error handling patterns
cargo run --example error_handling_demo
# Fullscreen mode
cargo run --example fullscreen_demo
# Interactive clock with spinner
cargo run --example clock_spinner
Contributions are welcome! Here's how you can help:
Please read our Contributing Guide for details.
This project is licensed under either of:
at your option.
Made with ๐ฆ Rust โข Report Bug โข Request Feature