boxy-cli
A Rust crate for creating styled, multi-segment text boxes in the terminal.
Dual-licensed under Apache 2.0 or MIT.
Features
- 9 border styles — classic ASCII, single, double, bold, rounded, bold-corners, and more
- True-color support — hex color codes (
#rrggbb) for borders and per-line text - Multi-segment boxes — stack sections separated by horizontal dividers
- Columnar layouts — side-by-side columns inside a single box, with configurable width ratios and correct junction characters (
┼/┬/┴) where column boundaries meet across adjacent segments - Automatic word wrapping — wraps to terminal width, respecting internal padding
- Text alignment — left, center, or right per segment
- Terminal-aware sizing — auto-sizes to terminal width, or set a fixed width
- Two APIs — imperative
Boxystruct and fluentBoxyBuilder - Macro support —
boxy!for quick one-liners
Installation
[]
= "2.1.0"
Or:
Quick Start
Builder API
use *;
builder
.box_type
.color
.add_segment
.add_segment
.add_line
.padding
.build
.display;
Imperative API
use *;
let mut b = new;
b.add_text_sgmt;
b.add_text_sgmt;
b.add_text_line;
b.display;
Macro
use *;
let mut b = boxy!;
b.add_text_sgmt;
b.display;
Columnar Layouts
Columnar segments let you place content side-by-side inside one box. Column widths are
controlled by ratio values — vec![1, 2, 1] gives the middle column twice the space of the
others.
Where column boundaries from adjacent segments coincide, boxy-cli renders the correct
junction character automatically:
┌─────────────────┬─────────────────┬─────────────┐
│ Project | Status │ Purpose |
├─────────────────┼─────────────────┴─────────────┤ <- ┼ where both have a boundary
│ Lumio V2 │ Shipped Internship │ ┴ where only the top segment does
└─────────────────┴───────────────────────────────┘
use *;
let mut b = new;
// Plain text header segment
b.add_text_sgmt;
// 3-column segment with equal widths
b.add_col_text_sgmt;
b.add_col_text_line;
b.add_col_text_line;
b.add_col_text_line;
b.add_col_text_line;
b.add_col_text_line;
b.add_col_text_line;
// Optional: customize column width ratios (must match column count)
b.set_segment_ratios;
b.display;
Or using the builder:
use *;
builder
.add_segment
.add_col_segment
.add_col_line
.add_col_line
.add_col_line
.add_col_line
.add_col_line
.add_col_line
.segment_ratios
.build
.display;
Border Styles
BoxType variant |
Appearance |
|---|---|
Single |
┌─┐ / │ / └─┘ |
Double |
╔═╗ / ║ / ╚═╝ |
Bold |
┏━┓ / ┃ / ┗━┛ |
Rounded |
╭─╮ / │ / ╰─╯ |
DoubleHorizontal |
╒═╕ / │ / ╘═╛ |
DoubleVertical |
╓─╖ / ║ / ╙─╜ |
BoldCorners |
┍━┑ / │ / ┕━┙ |
Classic |
+-+ / | / +-+ |
Empty |
invisible borders |
Padding
BoxPad controls spacing between the terminal edge and the box (external), and between the
box border and its text (internal).
use *;
// Uniform padding on all sides
let pad = uniform;
// Separate vertical and horizontal values
let pad = vh; // top/bottom: 1, left/right: 3
// Full control: top, left, down, right
let pad = from_tldr;
let mut b = new;
b.set_ext_padding;
b.set_int_padding;
b.add_text_sgmt;
b.display;
Examples
Multi-segment box
use *;
API Overview
| Method | Description |
|---|---|
Boxy::new(type, color) |
Create a new box |
Boxy::builder() |
Start a builder chain |
add_text_sgmt(text, color, align) |
Add a plain text segment |
add_text_line(text, color) |
Add a line to the last segment |
add_text_line_indx(text, color, idx) |
Add a line to a specific segment |
add_col_text_sgmt(align, count) |
Add a columnar segment |
add_col_text_line(text, color, col) |
Add a line to a column in the last segment |
add_col_text_line_indx(text, color, seg, col) |
Add a line to a specific column in a specific segment |
set_segment_ratios(seg, ratios) |
Set column width ratios for a columnar segment |
set_align(align) |
Set box alignment within the terminal |
set_int_padding(pad) |
Set internal padding |
set_ext_padding(pad) |
Set external padding |
set_width(n) |
Fix the box width |
set_type(type) |
Change border style |
set_color(color) |
Change border color |
display() |
Render and print the box |
For the full API reference see docs.rs/boxy-cli.