| Crates.io | cli-boxes |
| lib.rs | cli-boxes |
| version | 0.1.1 |
| created_at | 2025-09-08 14:24:28.355645+00 |
| updated_at | 2025-09-08 14:29:31.995889+00 |
| description | Unicode box drawing characters for creating beautiful CLI interfaces |
| homepage | https://github.com/sabry-awad97/cli-boxes |
| repository | https://github.com/sabry-awad97/cli-boxes |
| max_upload_size | |
| id | 1829333 |
| size | 91,091 |
A Rust library providing Unicode box-drawing characters for creating beautiful CLI interfaces.
BoxChars and high-level BorderStyle enumnew() method| Style | Example | Description |
|---|---|---|
NONE |
|
Invisible borders (all spaces) |
SINGLE |
┌─┐│┘─└│ |
Clean single-line borders |
DOUBLE |
╔═╗║╝═╚║ |
Bold double-line borders |
ROUND |
╭─╮│╯─╰│ |
Soft rounded corners |
BOLD |
┏━┓┃┛━┗┃ |
Thick, bold lines |
SINGLE_DOUBLE |
╓─╖║╜─╙║ |
Single horizontal, double vertical |
DOUBLE_SINGLE |
╒═╕│╛═╘│ |
Double horizontal, single vertical |
CLASSIC |
+─+|+─+| |
ASCII-compatible characters |
ARROW |
↘↓↙←↖↑↗→ |
Decorative arrow style |
Add this to your Cargo.toml:
[dependencies]
cli-boxes = "0.1.0"
# Enable serde support (optional)
cli-boxes = { version = "0.1.0", features = ["serde"] }
use cli_boxes::{BorderStyle, BoxChars};
// Use the ergonomic BorderStyle enum
let style = BorderStyle::Single;
let box_chars = style.chars();
// Or convert directly
let box_chars = BoxChars::from(BorderStyle::Double);
// Parse from string (case-insensitive, supports kebab-case)
let style: BorderStyle = "single-double".parse().unwrap();
let box_chars = style.chars();
// Convert to string
println!("Current style: {}", BorderStyle::Round); // Output: "round"
use cli_boxes::BoxChars;
// Create a simple box with single-line characters
let box_chars = BoxChars::SINGLE;
println!("{}{}{}",
box_chars.top_left,
box_chars.top.to_string().repeat(10),
box_chars.top_right
);
println!("{} {}", box_chars.left, box_chars.right);
println!("{}{}{}",
box_chars.bottom_left,
box_chars.bottom.to_string().repeat(10),
box_chars.bottom_right
);
Output:
┌──────────┐
│ │
└──────────┘
use cli_boxes::BorderStyle;
// Iterate through all available styles
for style in BorderStyle::all() {
let chars = style.chars();
println!("{}: {}{}{}", style, chars.top_left, chars.top, chars.top_right);
}
The BorderStyle enum supports parsing from strings with flexible formatting:
use std::str::FromStr;
use cli_boxes::BorderStyle;
// Case-insensitive parsing
let style1 = "SINGLE".parse::<BorderStyle>().unwrap();
let style2 = "double".parse::<BorderStyle>().unwrap();
// Supports both snake_case and kebab-case
let style3 = "single_double".parse::<BorderStyle>().unwrap();
let style4 = "single-double".parse::<BorderStyle>().unwrap();
// Error handling with helpful suggestions
match "invalid_style".parse::<BorderStyle>() {
Ok(style) => println!("Parsed: {}", style),
Err(e) => println!("Error: {}", e),
// Error: Invalid border style: 'invalid_style'. Did you mean one of: none, single, double, round, bold, single_double, double_single, classic, arrow?
}
You can create custom box character sets in several ways:
use cli_boxes::BoxChars;
let custom = BoxChars::new('*', '-', '*', '|', '*', '-', '*', '|');
use cli_boxes::BoxChars;
// Set all corners and sides uniformly
let uniform = BoxChars::builder()
.corners('*')
.horizontal('-')
.vertical('|')
.build();
// Mix and match for asymmetric designs
let asymmetric = BoxChars::builder()
.top_left('╭')
.top_right('╮')
.bottom_left('╰')
.bottom_right('╯')
.horizontal('─')
.vertical('│')
.build();
// Override specific characters
let mixed = BoxChars::builder()
.corners('●')
.horizontal('═')
.vertical('║')
.top_left('╔') // Override just the top-left corner
.build();
use cli_boxes::BoxChars;
let custom = BoxChars {
top_left: '*',
top: '-',
top_right: '*',
right: '|',
bottom_right: '*',
bottom: '-',
bottom_left: '*',
left: '|',
};
chars() - Get the BoxChars for this styleall() - Iterator over all available stylesto_string() - Convert to lowercase string representationparse() - Parse from string (via FromStr)new() - Constructor for creating custom box charactersbuilder() - Returns a BoxCharsBuilder for fluent API constructiondefault() - Returns BoxChars::SINGLEBoxChars::NONE - Invisible borders (spaces)BoxChars::SINGLE - Single-line Unicode bordersBoxChars::DOUBLE - Double-line Unicode bordersBoxChars::ROUND - Rounded corner bordersBoxChars::BOLD - Bold/thick line bordersBoxChars::SINGLE_DOUBLE - Mixed single/double bordersBoxChars::DOUBLE_SINGLE - Mixed double/single bordersBoxChars::CLASSIC - ASCII-compatible bordersBoxChars::ARROW - Decorative arrow borderscorners(char) - Set all four corner charactershorizontal(char) - Set top and bottom border charactersvertical(char) - Set left and right border characterstop_left(char), top(char), top_right(char) - Set individual charactersright(char), bottom_right(char), bottom(char) - Set individual charactersbottom_left(char), left(char) - Set individual charactersbuild() - Construct the final BoxCharsserde and strum)This library is designed for performance:
When the serde feature is enabled, all types can be serialized and deserialized:
[dependencies]
cli-boxes = { version = "0.1.0", features = ["serde"] }
serde_json = "1.0" # For JSON serialization (not included with cli-boxes)
use cli_boxes::{BoxChars, BorderStyle};
use serde_json;
// Serialize a BorderStyle
let style = BorderStyle::Double;
let json = serde_json::to_string(&style).unwrap();
// Serialize BoxChars
let chars = BoxChars::ROUND;
let json = serde_json::to_string(&chars).unwrap();
This project is licensed under the MIT OR Apache-2.0 License - see the LICENSE file for details.