pub struct Boxy<'a> {Show 15 fields
pub type_enum: BoxType,
pub data: Vec<Vec<Cow<'a, str>>>,
pub sect_count: usize,
pub box_col: String,
pub colors: Vec<Vec<Cow<'a, str>>>,
pub int_padding: BoxPad,
pub ext_padding: BoxPad,
pub align: BoxAlign,
pub seg_align: Vec<BoxAlign>,
pub fixed_width: usize,
pub fixed_height: usize,
pub seg_v_div_count: Vec<usize>,
pub seg_v_div_ratio: Vec<Vec<usize>>,
pub tot_seg: usize,
pub terminal_width_offset: i32,
}Expand description
The main struct that represents a text box for CLI display.
Boxy contains all the configuration and content needed to render a styled text box
in the terminal, including borders, text content, colors, padding, and alignment options.
§Examples
use boxy_cli::prelude::*;
// Create a simple text box
let mut my_box = Boxy::new(BoxType::Double, "#00ffff");
my_box.add_text_sgmt("Hello, World!", "#ffffff", BoxAlign::Center);
my_box.display();Fields§
§type_enum: BoxType§data: Vec<Vec<Cow<'a, str>>>§sect_count: usize§box_col: String§colors: Vec<Vec<Cow<'a, str>>>§int_padding: BoxPad§ext_padding: BoxPad§align: BoxAlign§seg_align: Vec<BoxAlign>§fixed_width: usize§fixed_height: usize§seg_v_div_count: Vec<usize>§seg_v_div_ratio: Vec<Vec<usize>>§tot_seg: usize§terminal_width_offset: i32Implementations§
Source§impl<'a> Boxy<'a>
impl<'a> Boxy<'a>
Sourcepub fn new(box_type: BoxType, box_color: &str) -> Self
pub fn new(box_type: BoxType, box_color: &str) -> Self
Creates a new instance of the Boxy struct with the specified border type and color.
§Arguments
box_type- The border style to use from theBoxTypeenumbox_color- A hex color code (e.g. “#00ffff”) for the border color
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Double, "#00ffff");Sourcepub fn builder() -> BoxyBuilder<'a>
pub fn builder() -> BoxyBuilder<'a>
Returns a new BoxyBuilder to create a textbox using the builder pattern.
The builder pattern provides a more fluent interface for configuring and creating a Boxy instance.
§Examples
use boxy_cli::prelude::*;
let my_box = Boxy::builder()
.box_type(BoxType::Double)
.color("#00ffff")
.add_segment("Hello, World!", "#ffffff", BoxAlign::Center)
.build();Sourcepub fn add_text_sgmt(
&mut self,
data_string: &str,
color: &str,
text_align: BoxAlign,
)
pub fn add_text_sgmt( &mut self, data_string: &str, color: &str, text_align: BoxAlign, )
Adds a new text segment/section to the textbox, separated by a horizontal divider.
Each segment represents a distinct section of the textbox that will be separated by horizontal dividers. This method is typically used to add the first or later major sections of content.
§Arguments
data_string- The text content for this segmentcolor- A hex color code (e.g. “#ffffff”) for the text colortext_align- The alignment (left, center, right) for this text segment
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.add_text_sgmt("Header section", "#ffffff", BoxAlign::Center);
my_box.add_text_sgmt("Content section", "#ffffff", BoxAlign::Left);Sourcepub fn add_text_line_indx(
&mut self,
data_string: &str,
color: &str,
seg_index: usize,
)
pub fn add_text_line_indx( &mut self, data_string: &str, color: &str, seg_index: usize, )
Adds a new text line to the segment with a specific index.
This method allows adding additional lines of text to an existing segment by specifying the segment’s index. The new line will appear below the existing content in that segment.
§Arguments
data_string- The text content to addcolor- A hex color code (e.g. “#ffffff”) for the text colorseg_index- The index of the segment to add this line to (0-based)
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.add_text_sgmt("First segment", "#ffffff", BoxAlign::Left);
my_box.add_text_sgmt("Second segment", "#ffffff", BoxAlign::Left);
// Add a line to the first segment (index 0)
my_box.add_text_line_indx("Additional line in first segment", "#32CD32", 0);§Panics
Panics if seg_index is out of bounds.
Sourcepub fn add_text_line(&mut self, data_string: &str, color: &str)
pub fn add_text_line(&mut self, data_string: &str, color: &str)
Adds a new text line to the most recently added segment.
This is a convenience method that adds a line of text to the last segment that was created, eliminating the need to specify the segment index.
§Arguments
data_string- The text content to addcolor- A hex color code (e.g. “#ffffff”) for the text color
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.add_text_sgmt("Header", "#ffffff", BoxAlign::Center);
my_box.add_text_line("Additional details below the header", "#32CD32");§Panics
Panics if no segments have been added yet.
Sourcepub fn set_align(&mut self, align: BoxAlign)
pub fn set_align(&mut self, align: BoxAlign)
Sets the overall alignment of the textbox within the terminal.
This controls the horizontal positioning of the entire textbox relative to the terminal width. It does not affect the alignment of text within the box segments.
§Arguments
align- The alignment to use:BoxAlign::Left,BoxAlign::Center, orBoxAlign::Right
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.set_align(BoxAlign::Center); // Center the box in the terminalSourcepub fn set_int_padding(&mut self, int_padding: BoxPad)
pub fn set_int_padding(&mut self, int_padding: BoxPad)
Sets the internal padding between the textbox border and its text content.
Internal padding creates space between the border of the box and the text inside it.
§Arguments
int_padding- ABoxPadinstance specifying the padding values
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
// Set uniform padding of 2 spaces on all sides
my_box.set_int_padding(BoxPad::uniform(2));
// Or set different padding for each side (top, left, down, right)
my_box.set_int_padding(BoxPad::from_tldr(1, 3, 1, 3));Sourcepub fn set_ext_padding(&mut self, ext_padding: BoxPad)
pub fn set_ext_padding(&mut self, ext_padding: BoxPad)
Sets the external padding between the terminal edges and the textbox.
External padding creates space between the edges of the terminal and the border of the box. This affects the positioning of the box within the terminal.
§Arguments
ext_padding- ABoxPadinstance specifying the padding values
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
// Add 5 spaces of padding on all sides
my_box.set_ext_padding(BoxPad::uniform(5));
// Or set different padding for each side (top, left, down, right)
my_box.set_ext_padding(BoxPad::from_tldr(0, 10, 0, 0));Sourcepub fn set_padding(&mut self, ext_padding: BoxPad, int_padding: BoxPad)
pub fn set_padding(&mut self, ext_padding: BoxPad, int_padding: BoxPad)
Sets both internal and external padding for the textbox in a single call.
This is a convenience method that combines set_int_padding and set_ext_padding.
§Arguments
ext_padding- ABoxPadinstance for the external padding (between terminal edges and box)int_padding- ABoxPadinstance for the internal padding (between box border and text)
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
// Set both internal and external padding
my_box.set_padding(
BoxPad::from_tldr(1, 5, 1, 5), // external padding
BoxPad::uniform(2) // internal padding
);Sourcepub fn set_width(&mut self, width: usize)
pub fn set_width(&mut self, width: usize)
Sets a fixed width for the textbox instead of dynamically sizing it to the terminal width.
By default, the textbox automatically adjusts its width based on the terminal size. This method allows you to specify a fixed width instead.
§Arguments
width- The desired width in characters (including borders)
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.set_width(50); // Fix the box width to 50 characters§Note
Setting width to 0 returns to dynamic sizing based on terminal width.
Sourcepub fn set_height(&mut self, height: usize)
pub fn set_height(&mut self, height: usize)
Sets a fixed height for the textbox by adding whitespace above and below the text.
§Arguments
height- The desired height in characters (including borders)
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Single, "#00ffff");
my_box.set_height(20); // Set box height to 20 lines§Note
This feature is experimental and may not work as expected in the current version. Setting height to 0 returns to dynamic sizing based on content.
Sourcepub fn set_segment_ratios(&mut self, seg_index: usize, ratios: Vec<usize>)
pub fn set_segment_ratios(&mut self, seg_index: usize, ratios: Vec<usize>)
Sets the size-ratio between segments when using vertical divisions
This feature is still experimental and not yet implemented fully, and hence may not work in the current version of the crate.
Sourcepub fn display(&mut self)
pub fn display(&mut self)
Renders and displays the textbox in the terminal.
This method performs all the necessary calculations to render the textbox with the configured settings, including border style, colors, padding, and text content. It then prints the textbox to the standard output.
§Examples
use boxy_cli::prelude::*;
let mut my_box = Boxy::new(BoxType::Double, "#00ffff");
my_box.add_text_sgmt("Hello, World!", "#ffffff", BoxAlign::Center);
my_box.display(); // Renders the box to the terminal§Note
The appearance may vary depending on terminal support for colors and Unicode characters.