Struct text_grid::GridBuilder
source · pub struct GridBuilder { /* private fields */ }Expand description
A builder used to create plain-text table.
Examples
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push(cell("name").right());
b.push("type");
b.push("value");
});
g.push_separator();
g.push(|b| {
b.push(cell(String::from("X")).right());
b.push("A");
b.push(10);
});
g.push(|b| {
b.push(cell("Y").right());
b.push_with_colspan(cell("BBB").center(), 2);
});
assert_eq!(format!("\n{g}"), r#"
name | type | value |
------|------|-------|
X | A | 10 |
Y | BBB |
"#);Implementations§
source§impl GridBuilder
impl GridBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GridBuilder.
Examples found in repository?
examples/grid_buf.rs (line 3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push(cell("name").right());
b.push("type");
b.push("value");
});
g.push_separator();
g.push(|b| {
b.push(cell(String::from("X")).right());
b.push("A");
b.push(10);
});
g.push(|b| {
b.push(cell("Y").right());
b.push_with_colspan(cell("BBB").center(), 2);
});
print!("{}", g);
}More examples
examples/set_column_separators.rs (line 3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push("A");
b.push("B");
b.push("C");
});
g.push(|b| {
b.push("AAA");
b.push("BBB");
b.push("CCC");
});
g.set_column_separators(vec![true, true]);
println!("{:?}", vec![true, true]);
println!("{}", g);
g.set_column_separators(vec![false, true]);
println!("{:?}", vec![false, true]);
println!("{}", g);
}sourcepub fn set_column_separators(&mut self, separators: Vec<bool>)
pub fn set_column_separators(&mut self, separators: Vec<bool>)
Set column separator’s visibility.
separators[0] indicate visibility of the right side of the leftmost column.
Examples
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push("A");
b.push("B");
b.push("C");
});
g.push(|b| {
b.push("AAA");
b.push("BBB");
b.push("CCC");
});
g.set_column_separators(vec![true, true]);
assert_eq!(format!("\n{g}"), r#"
A | B | C |
AAA | BBB | CCC |
"#);
g.set_column_separators(vec![false, true]);
assert_eq!(format!("\n{g}"), r#"
A B | C |
AAABBB | CCC |
"#);Examples found in repository?
examples/set_column_separators.rs (line 14)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push("A");
b.push("B");
b.push("C");
});
g.push(|b| {
b.push("AAA");
b.push("BBB");
b.push("CCC");
});
g.set_column_separators(vec![true, true]);
println!("{:?}", vec![true, true]);
println!("{}", g);
g.set_column_separators(vec![false, true]);
println!("{:?}", vec![false, true]);
println!("{}", g);
}sourcepub fn push(&mut self, f: impl FnOnce(&mut RowBuilder<'_>))
pub fn push(&mut self, f: impl FnOnce(&mut RowBuilder<'_>))
Append a row to the bottom of the grid.
Examples found in repository?
examples/grid_buf.rs (lines 4-8)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push(cell("name").right());
b.push("type");
b.push("value");
});
g.push_separator();
g.push(|b| {
b.push(cell(String::from("X")).right());
b.push("A");
b.push(10);
});
g.push(|b| {
b.push(cell("Y").right());
b.push_with_colspan(cell("BBB").center(), 2);
});
print!("{}", g);
}More examples
examples/set_column_separators.rs (lines 4-8)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push("A");
b.push("B");
b.push("C");
});
g.push(|b| {
b.push("AAA");
b.push("BBB");
b.push("CCC");
});
g.set_column_separators(vec![true, true]);
println!("{:?}", vec![true, true]);
println!("{}", g);
g.set_column_separators(vec![false, true]);
println!("{:?}", vec![false, true]);
println!("{}", g);
}sourcepub fn push_separator(&mut self)
pub fn push_separator(&mut self)
Append a row separator to the bottom of the grid.
Examples found in repository?
examples/grid_buf.rs (line 9)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
b.push(cell("name").right());
b.push("type");
b.push("value");
});
g.push_separator();
g.push(|b| {
b.push(cell(String::from("X")).right());
b.push("A");
b.push(10);
});
g.push(|b| {
b.push(cell("Y").right());
b.push_with_colspan(cell("BBB").center(), 2);
});
print!("{}", g);
}Trait Implementations§
source§impl Debug for GridBuilder
impl Debug for GridBuilder
source§impl Default for GridBuilder
impl Default for GridBuilder
source§fn default() -> GridBuilder
fn default() -> GridBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl RefUnwindSafe for GridBuilder
impl Send for GridBuilder
impl Sync for GridBuilder
impl Unpin for GridBuilder
impl UnwindSafe for GridBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more