3 releases (1 stable)

Uses new Rust 2024

1.0.0 Apr 19, 2025
0.1.1 Apr 15, 2025
0.1.0 Apr 14, 2025

#256 in Command-line interface

Download history 136/week @ 2025-04-09 230/week @ 2025-04-16 10/week @ 2025-04-23

376 downloads per month

MIT/Apache

42KB
671 lines

boxy-cli

Static Badge Crates.io Docs.rs Crates.io Static Badge Static Badge Build Status

A Crate to create boxes in command-line interfaces with Rust

Dual-licensed under Apache 2.0 or MIT.

About:

boxy-cli is a crate to create simple textboxes in command-line interfaces, with a simple and easy-to-use design.

How to use:

Using the Builder:

you can directly create (and simutaneously print the textbox) using the BoxyBuilder Struct. here is how to use it:

Importing the necessary:

use boxy_cli::prelude::*;
use boxy_cli::constructs::BoxPad;

Next, you can create the BoxyBuilder struct

let mut my_box = Boxy::builder()
        .box_type(BoxType::Double)
        .color("#00ffff")
        .padding(BoxPad::uniform(1), BoxPad::from_tldr(2, 2, 1, 1))
        .align(BoxAlign::Center)
        .add_segment("Hello, Boxy!", "#ffffff")
        .add_line("This is a new line.", "#32CD32")
        .add_segment("Another section", "#663399")
        .width(50)
        .build();

and now, display it:

my_box.display();

Or do both simultanrously:

Boxy::builder()
        .box_type(BoxType::Double)
        .color("#aaffff")
        .padding(BoxPad::uniform(1), BoxPad::from_tldr(2, 2, 1, 1))
        .align(BoxAlign::Center)
        .add_segment("Hello, Boxy!", "#ffffff")
        .add_line("This is a new line.", "#32CD32")
        .add_segment("Another section", "#f19356")
        .width(50)
        .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 boxy_cli::prelude::*;
use boxy_cli::constructs::BoxPad;

Next you create a new boxy struct with either the new method:

let mut box1 = Boxy::new(BoxType::Double,"#00ffff");

or the macro:

let mut box2 = boxy!(type: BoxType::Double, color:"#00ffff");

for more info on the macro, view the macro documentation

Next, we just add in text sections:

box1.add_text_sgmt("Lorem ipsum dolor sit amet", "#fffff");

Add some more text to the same segment (or the latest segment):

box1.add_text_line("consectetur adipiscing elit", "#32CD32");

or to a segment with a particular index:

box1.add_text_line_indx(" consectetur adipiscing elit", "#32CD32", 0);

Once you are done, just display the TextBox:

box1.display();

the text colour is a required argument, and will be implemented into a usable feature in the very near future. But for now, it does not work

Examples:

Example 1

use boxy_cli::prelude::*;

fn main() {
    let mut box1 = Boxy::new(BoxType::Double,"#bfff00");
    box1.add_text_sgmt("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur", "#ffff");
    box1.add_text_sgmt("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.", "#ffff");
    box1.add_text_sgmt("Hello Theree", "#ffff");
    box1.display();
}

Example 2 (with the macro)

use boxy_cli::prelude::*;

fn main() {
    let mut box2 = boxy!(type: BoxType::Double, color:"#00ffff");
    box2.add_text_sgmt("Hello There Mateojablij trhwesoiuethj 0piswe hjgtgoise jgtowie3thj q3o-oitujpwiej toiq 0iweeh gt owjtpiewrwh WOKWRHJ JRQWE4IHYNE5R bfg oiwhf apeih aepih aepih aepihetm wf[ohgwlMRF [POWQWRF]] [OJTQEA [OJ]]OJBDGISUDBG SIUGRG OGUFOSIJGOSN SOGUIHSGIORNGR ORIRHGOSJRNGOIJRG OPIFGHRPGNPERIJG ORIRGRPIGNERPGOSJH ", "#ffff");
    box2.add_text_line("Hello Theree", "#32CD32");
    box2.display();
}

Dependencies

~0.2–6.5MB
~35K SLoC