Crates.io | table_formatter |
lib.rs | table_formatter |
version | 0.6.1 |
source | src |
created_at | 2023-05-13 07:05:41.575202 |
updated_at | 2023-07-01 05:41:47.858626 |
description | A simple text table formatter written in Rust |
homepage | https://github.com/Embers-of-the-Fire/rust-table-formatter |
repository | https://github.com/Embers-of-the-Fire/rust-table-formatter.git |
max_upload_size | |
id | 863590 |
size | 54,365 |
This lib is used to format plain-text table.
Code:
use itertools::Itertools;
use table_formatter::{cell, table};
use table_formatter::table::{Align, Border};
let table_header = vec![
cell!("Cell Row").with_width(Some(20)),
cell!("Left", align = Align::Left).with_width(Some(10)),
cell!("Center", align = Align::Center).with_width(Some(10)),
cell!("Right", align = Align::Right).with_width(Some(10)),
];
let table_cells = {
let mut v = (0..=3_u8)
.map(|_| {
vec![
cell!("Cell Row"),
cell!("Left", align = Align::Left),
cell!("Center", align = Align::Center),
cell!("Right", align = Align::Right),
]
})
.collect_vec();
v.push(cell!("Cross Cell!", align = Align::Center).with_span(3));
v
};
let table = table! {
table_header
---
table_cells
with Border::ALL
};
let mut buffer = vec![];
table.render(&mut buffer).unwrap();
println!("{}", String::from_utf8(buffer).unwrap());
Output:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Cell Row Left Center Right ┃
┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃
┃ Cell Row Left Center Right ┃
┃ Cell Row Left Center Right ┃
┃ Cell Row Left Center Right ┃
┃ Cell Row Left Center Right ┃
┃ Cross Cell! ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Actually the border of the table is bold, but it cannot be rendered in markdown.
Waiting for report :)
If you are using the formatter, you just need to change your
vec!
s intofmt!
s.
This version is yanked.
This version is Completely Incompatible with previous versions.
MIT or Apache-2.0