| Crates.io | boxen |
| lib.rs | boxen |
| version | 0.1.3 |
| created_at | 2025-09-09 19:38:14.417076+00 |
| updated_at | 2025-09-09 22:58:17.867719+00 |
| description | A Rust library for creating styled terminal boxes around text |
| homepage | |
| repository | https://github.com/sabry-awad97/boxen |
| max_upload_size | |
| id | 1831435 |
| size | 583,380 |
A Rust implementation of the popular boxen library for creating styled terminal boxes around text.
Add this to your Cargo.toml:
[dependencies]
boxen = "0.1.3"
use ::boxen::{boxen, builder, BorderStyle, TextAlignment};
fn main() {
// Simple box with default settings
let simple = boxen("Hello, World!", None).unwrap();
println!("{}", simple);
// Using the builder pattern for more control
let fancy = builder()
.border_style(BorderStyle::Double)
.padding(2)
.margin(1)
.text_alignment(TextAlignment::Center)
.title("Greeting")
.border_color("blue")
.render("Hello, World!")
.unwrap();
println!("{}", fancy);
}
use ::boxen::boxen;
let result = boxen("Simple box", None).unwrap();
println!("{}", result);
Output:
โโโโโโโโโโโโ
โSimple boxโ
โโโโโโโโโโโโ
use ::boxen::{builder, BorderStyle, TextAlignment};
let result = builder()
.border_style(BorderStyle::Round)
.padding(1)
.text_alignment(TextAlignment::Center)
.width(20)
.title("Status")
.border_color("green")
.render("All systems operational")
.unwrap();
println!("{}", result);
Output:
โญโโโ Status โโโโโฎ
โ โ
โ All systems โ
โ operational โ
โ โ
โฐโโโโโโโโโโโโโโโโฏ
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, 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)
.height(8)
.title("๐ Celebration")
.border_color("#ff6b6b")
.background_color("#ffe66d")
.render("Congratulations!\nYou've mastered boxen!")
.unwrap();
println!("{}", result);
use ::boxen::{builder, BoxenError};
match builder()
.width(5) // Too narrow
.padding(10) // Too much padding
.render("This won't fit") {
Ok(result) => println!("{}", result),
Err(BoxenError::ConfigurationError(msg)) => {
eprintln!("Configuration error: {}", msg);
}
Err(e) => eprintln!("Error: {}", e),
}
Boxen supports various border styles:
| Style | Preview |
| -------------- | ----------- | --- | --- | --- | ----- |
| Single | โโโโ โโโโ |
| Double | โโโโ โโโโ |
| Round | โญโโฎโ โโฐโโฏ |
| Bold | โโโโ โโโโ |
| SingleDouble | โโโโ โโโโ |
| DoubleSingle | โโโโ โโโโ |
| Classic | +--+ | | | | +--+ |
Boxen supports multiple color formats:
use ::boxen::builder;
// Named colors
builder().border_color("red");
builder().background_color("blue");
// Hex colors
builder().border_color("#ff0000");
builder().background_color("#0000ff");
// RGB colors
builder().border_color((255, 0, 0));
builder().background_color((0, 0, 255));
Boxen is optimized for performance:
Benchmark results on a modern machine:
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
# 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! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under either of
at your option.