Crates.io | unicode-prettytable |
lib.rs | unicode-prettytable |
version | 0.3.1 |
source | src |
created_at | 2021-02-07 19:15:02.406941 |
updated_at | 2021-03-10 20:41:22.454831 |
description | Table formatting library using Unicode Box-drawing characters |
homepage | |
repository | https://github.com/srithon/unicode-prettytable |
max_upload_size | |
id | 352035 |
size | 15,455 |
Rust table formatting library using Unicode Box-drawing characters.
NOTE: the version that was previously 1.0.0
has become 0.3.0
.
use unicode_prettytable::*;
fn main() -> Result<(), String> {
let input = vec![
vec!["oh hello there", "hello there", "hello"],
vec!["hello there", "oh hello there", "hello"],
vec!["oh hello there", "hello", "hello there"],
vec!["oh hello there", "hello there", "hello"],
vec!["oh hello there", "hello there", "hello"],
];
// uses double bar characters for header and centers text within columns
let table1 = TableBuilder::default()
.header(
HeaderBuilder::default()
.double_bar(true)
.centered_text(true)
.build()?
)
.rows(&input)
.build()?;
// does not use double bar characters for header, but centers header text within columns
let table2 = TableBuilder::default()
.header(
HeaderBuilder::default()
.double_bar(false)
.centered_text(true)
.build()?
)
.rows(&input)
.build()?;
// uses default header settings
let table3 = TableBuilder::default()
.rows(&input)
.build()?;
println!("{}\n", table1);
println!("{}\n", table2);
println!("{}", table3);
Ok(())
}
The code above outputs
╒══════════════════╤═══════════════╤═══════════╕
│ oh hello there │ hello there │ hello │
╞══════════════════╪═══════════════╪═══════════╡
│hello there │oh hello there │hello │
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello │hello there│
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello there │hello │
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello there │hello │
└──────────────────┴───────────────┴───────────┘
┌──────────────────┬───────────────┬───────────┐
│ oh hello there │ hello there │ hello │
├──────────────────┼───────────────┼───────────┤
│hello there │oh hello there │hello │
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello │hello there│
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello there │hello │
├──────────────────┼───────────────┼───────────┤
│oh hello there │hello there │hello │
└──────────────────┴───────────────┴───────────┘
┌──────────────┬──────────────┬───────────┐
│oh hello there│hello there │hello │
├──────────────┼──────────────┼───────────┤
│hello there │oh hello there│hello │
├──────────────┼──────────────┼───────────┤
│oh hello there│hello │hello there│
├──────────────┼──────────────┼───────────┤
│oh hello there│hello there │hello │
├──────────────┼──────────────┼───────────┤
│oh hello there│hello there │hello │
└──────────────┴──────────────┴───────────┘
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.