#csv #pretty-print #terminal

bin+lib pretty-csv

CSV terminal pretty-printer

2 unstable releases

0.2.0 Feb 12, 2023
0.1.0 Feb 12, 2023

#54 in #pretty-print

49 downloads per month

MIT license

22KB
380 lines

Pretty CSV

Pretty-print your csv files to the terminal:

use pretty_csv::Table;

let mut csv = &b"one,two\nthree,four"[..];
let table = Table::from_csv(csv);
let mut output = vec![];
table.draw(&mut output).unwrap();
assert_eq!(
    std::str::from_utf8(&output).unwrap(),
    concat!(
        "╭───────┬──────╮\n",
        "│ one   │ two  │\n",
        "├───────┼──────┤\n",
        "│ three │ four │\n",
        "╰───────┴──────╯\n"
    )
);

Supports embedding tables in cells:

use pretty_csv::Table;

let mut csv = &b"one,two\n\"[three,four\nfive,six]\",seven"[..];
let table = Table::from_csv(csv);
let mut output = vec![];
table.draw(&mut output).unwrap();
assert_eq!(
    std::str::from_utf8(&output).unwrap(),
    concat!(
        "╭──────────────────┬───────╮\n",
        "│ one              │ two   │\n",
        "├──────────────────┼───────┤\n",
        "│ ╭───────┬──────╮ │ seven │\n",
        "│ │ three │ four │ │       │\n",
        "│ ├───────┼──────┤ │       │\n",
        "│ │ five  │ six  │ │       │\n",
        "│ ╰───────┴──────╯ │       │\n",
        "╰──────────────────┴───────╯\n"
    )
);

Comes with small cli tool called pretty-csv:

$ cargo install pretty-csv
$ echo "1,2,3" | pretty-csv
╭───┬───┬───╮
 1 │ 2 │ 3 │
╰───┴───┴───╯

Dependencies

~28KB