9 releases (5 breaking)

0.6.1 Jul 1, 2023
0.6.0 Jun 27, 2023
0.5.1 Jun 10, 2023
0.4.0 Jun 3, 2023
0.1.0 May 13, 2023

#136 in Value formatting

Download history 671/week @ 2024-07-20 569/week @ 2024-07-27 320/week @ 2024-08-03 3257/week @ 2024-08-10 3533/week @ 2024-08-17 1626/week @ 2024-08-24 1226/week @ 2024-08-31 619/week @ 2024-09-07 1092/week @ 2024-09-14 731/week @ 2024-09-21 1915/week @ 2024-09-28 1040/week @ 2024-10-05 1088/week @ 2024-10-12 664/week @ 2024-10-19 1065/week @ 2024-10-26 683/week @ 2024-11-02

3,978 downloads per month

MIT/Apache

42KB
765 lines

Table Formatter

Repo   Crates-io Version   Language Count   License
Build Status   Commit Activity   Recent Downloads

This lib is used to format plain-text table.

Example

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.

Future Plan

Waiting for report :)

Change Log

V0.6.0

  • Changed the api of formatter, and add a macro wrapper for them.
  • Added documentations.

If you are using the formatter, you just need to change your vec!s into fmt!s.

V0.5.1

This version is yanked.

V0.5.0

New features

  • Add render target: Markdown.
  • Add cross-cell support.
  • Add macro support.

Warning

This version is Completely Incompatible with previous versions.

License

MIT or Apache-2.0

Dependencies

~0.8–11MB
~68K SLoC