boxy-cli
A Crate to create boxes in command-line interfaces with Rust
Dual-licensed under Apache 2.0 or MIT.
About
boxy-cli is a Rust crate that makes it easy to create stylish text boxes in terminal applications. With a simple, intuitive API, you can quickly add visually appealing elements to your CLI applications.
Features
- Multiple Border Styles: Choose from single, double, bold, rounded, and other border styles
- Color Support: Customize border and text colors using hex color codes
- Flexible Layouts: Create multi-segment boxes with horizontal dividers
- Text Alignment: Align text left, center, or right within each segment
- Custom Padding: Control spacing both inside and outside the box
- Terminal-Aware: Automatically adjusts to terminal width or use fixed dimensions
- Builder Pattern: Fluent API for easy box creation
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or use cargo add:
How to use:
Using the Builder Pattern
The builder pattern provides a fluent, chainable API for creating and configuring text boxes:
use *;
Next, you can create the BoxyBuilder struct
let mut my_box = builder
.box_type // Set border style
.color // Set border color
.padding
.align // Center the box in the terminal
.add_segment
.add_line
.add_segment
.width // Set fixed width
.build;
and now, display it:
my_box.display;
You can also build and display in one go:
builder
.box_type
.color
.padding
.align
.add_segment
.add_line
.add_segment
.width
.build
.display;
further, you can use the same methods as displayed above to modify the textbox before building.
But you can also modify the textbox after building it (before displaying) using the methods shown in the following section.
Using the Struct and methods.
First, import the crate into the current scope, using:
use *;
Next you create a new boxy struct with either the new method:
let mut box1 = new;
or the macro:
let mut box2 = boxy!;
for more info on the macro, view the macro documentation
Next, we just add in text sections:
box1.add_text_sgmt;
Add some more text to the same segment (or the latest segment):
box1.add_text_line;
or to a segment with a particular index:
box1.add_text_line_indx;
Once you are done, display the TextBox:
box1.display;
Examples:
Example 1
use *;
Example 2 (with the macro)
use *;
Example 3 (with the BoxyBuilder implementation)
use *;