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;