Expand description
A CLI Table Output for Rust 🦀 projects.
Usage
Add rct
in your dependencies
section
[dependencies]
rct = "0.2.1"
Basic usage
use rct::cell::ICell;
use rct::table::Table;
let mut table = Table::new();
table
.add_header(vec!["ID".cell(), "Title".cell(), "Price €".cell()])
.add_row(vec![1.cell(),"Harry \nPotter".cell(), "14.87".cell()])
.add_row(vec![2.cell(),"Spider-man".cell(),"18.80".cell()])
.add_row(vec![3.cell(), "Avenger".cell(), "18.50".cell()]);
table.view();
╔════╤════════════╤═════════╗
║ ID │ Title │ Price € ║
╟────┼────────────┼─────────╢
║ 1 │ Harry │ 14.87 ║
║ │ Potter │ ║
╟────┼────────────┼─────────╢
║ 2 │ Spider-man │ 18.80 ║
╟────┼────────────┼─────────╢
║ 3 │ Avenger │ 18.50 ║
╚════╧════════════╧═════════╝
Add styles
use rct::cell::ICell;
use rct::table::Table;
use rct::styles::color::{Colorizer, Font};
let mut table = Table::new();
table
.add_header(vec!["ID".cell(), "Title".cell(), "Price €".cell()])
.add_row(vec![1.cell(),"Harry \nPotter".cell().color("#ff0000"), "14.87".cell()])
.add_row(vec![2.cell(),"Spider-man".cell(),"18.80".cell()])
.add_row(vec![3.cell(), "Avenger".cell(), "18.50".cell().font(Font::Italic)]);
table.view();
Use derive macro
#[derive(ToTable)]
can be used to display a Vec
or slice of struct
as a table.
use rct::ToTable;
#[derive(ToTable)]
struct Movies {
#[table(rename = "ID")]
id: u32,
#[table(rename = "Title")]
title: String,
#[table(rename = "Price €")]
price: f32,
}
let movies = [
Movies {
id: 1,
title: "Harry \nPotter".to_string(),
price: 14.87,
},
Movies {
id: 2,
title: "Spider-man".to_string(),
price: 18.80,
},
];
let table = movies.into_iter().to_table();
println!("{}", table);
Features
derive
: Enables derive macro for creating tables using structs.
Re-exports
pub use self::cell::Cell;
pub use self::cell::ICell;
pub use self::row::Row;
pub use self::table::Table;