Tabled [v0.6.0] - An easy to use library for pretty print tables of Rust structs and enums.
https://github.com/zhiburt/tabled
There is a list of main features added.
- Added MinWidth type, which changes cell widths in case it's necessary.
- MinWidth and MaxWidth can be used in combination in order to set a table width as a whole. (see terminal\_width example)
- Publicize Span support. It can be used to set a column span.
- Added Extract(by @IsaacCloos). It can be used to extract a segment from a table.
- Added Margin(by @kozmod). Can be used to set a indent of the whole table.
- Added a support for custom sector targeting in Highlight.
Perhaps I did not came up with a good example. But here's an example which shows a list of contributors to this release.
use tabled::{
style::{Border, Style},
Alignment, Cell, Extract, Full, Header, Highlight, Modify, TableIteratorExt, Tabled,
};
#[derive(Tabled)]
struct Contribution {
author: &'static str,
profile: &'static str,
}
fn main() {
let commiters = [
Contribution {
author: "kozmod",
profile: "https:/github.com/kozmod",
},
Contribution {
author: "IsaacCloos",
profile: "https:/github.com/IsaacCloos",
},
];
let issuers = [Contribution {
author: "aharpervc",
profile: "https:/github.com/aharpervc",
}];
let commiters_table = commiters
.table()
.with(Header("Contributors"))
.with(Modify::new(Full).with(Alignment::center()));
let issues_table = issuers
.table()
.with(Header("Issuers"))
.with(Modify::new(Full).with(Alignment::center()));
let a_welcome_table = [
commiters_table.to_string(),
issues_table.to_string(),
]
.table()
.with(Header("Thank You"))
.with(Style::ascii().horizontal_off())
.with(Highlight::new(Cell(0, 0), Border::filled('*')));
println!("{}", a_welcome_table);
}
An output
*************************************************
* Thank You *
*************************************************
| Contributors |
| +------------+------------------------------+ |
| | author | profile | |
| +------------+------------------------------+ |
| | kozmod | https:/github.com/kozmod | |
| +------------+------------------------------+ |
| | IsaacCloos | https:/github.com/IsaacCloos | |
| +------------+------------------------------+ |
| Issuers |
| +-----------+-----------------------------+ |
| | author | profile | |
| +-----------+-----------------------------+ |
| | aharpervc | https:/github.com/aharpervc | |
| +-----------+-----------------------------+ |
+-----------------------------------------------+