Skip to main content

Crate boxen

Crate boxen 

Source
Expand description

§Boxen

A Rust implementation of the boxen library for drawing styled boxes around text in terminals.

Boxen provides a simple and flexible API for creating beautiful terminal boxes with support for:

  • Multiple border styles (single, double, round, bold, etc.)
  • Text alignment (left, center, right)
  • Padding and margins with fine-grained control
  • Colors for borders and backgrounds
  • Titles with customizable positioning
  • Unicode and ANSI escape sequence support
  • Fullscreen mode and responsive layouts

§Quick Start

use ::boxen::{boxen, builder, BorderStyle, TextAlignment};

// 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);

§Examples

§Basic Usage

use ::boxen::boxen;

let result = boxen("Simple box", None).unwrap();
// ┌──────────┐
// │Simple box│
// └──────────┘

§Builder Pattern

use ::boxen::{builder, BorderStyle, TextAlignment, Color};

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();

§Convenience Functions

use ::boxen::{simple_box, double_box, round_box};

println!("{}", simple_box("Default style"));
println!("{}", double_box("Double border"));
println!("{}", round_box("Round corners"));

§Performance

Boxen is optimized for performance with:

  • Minimal memory allocations in hot paths
  • Efficient Unicode width calculation
  • Smart ANSI escape sequence handling
  • Pre-allocated string buffers for large content

§Error Handling

All fallible operations return Result<T, BoxenError> with descriptive error messages and helpful recommendations for fixing common issues.

Re-exports§

pub use error::BoxenError;
pub use error::BoxenResult;
pub use error::ErrorRecommendation;
pub use options::BorderChars;
pub use options::BorderStyle;
pub use options::BoxenBuilder;
pub use options::BoxenOptions;
pub use options::Color;
pub use options::DimensionConstraints;
pub use options::Float;
pub use options::FullscreenMode;
pub use options::LayoutDimensions;
pub use options::Spacing;
pub use options::TextAlignment;
pub use options::TitleAlignment;
pub use render::boxen;
pub use validation::MinimumDimensions;
pub use validation::ValidationResult;
pub use validation::auto_adjust_options;
pub use validation::calculate_minimum_dimensions;
pub use validation::suggest_optimal_dimensions;
pub use validation::validate_configuration;
pub use terminal::get_terminal_height;
pub use terminal::get_terminal_size;
pub use terminal::get_terminal_width;

Modules§

borders
Border System
color
Color System
error
Error Handling System
memory
Memory management utilities for performance optimization.
options
Configuration System
render
Core Boxen Rendering Engine
terminal
Terminal Integration System
text
Text Processing Engine
validation
Configuration Validation and Auto-Recovery System

Functions§

builder
Create a new BoxenBuilder for fluent configuration.
double_box
Create a box with double border style.
round_box
Create a box with round border style.
simple_box
Create a simple box with default single border style.