Crates.io | tabprinter |
lib.rs | tabprinter |
version | |
source | src |
created_at | 2024-09-16 04:21:57.624283+00 |
updated_at | 2025-02-18 05:53:14.962287+00 |
description | tabprinter is a Rust library for creating and printing formatted tables in the terminal. It supports various table styles and offers both color and non-color output options. |
homepage | |
repository | https://github.com/vschwaberow/tabprinter |
max_upload_size | |
id | 1375987 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
tabprinter
is a Rust library for creating and printing formatted tables in the terminal. It supports various table styles and offers both color and non-color output options.
Add this to your Cargo.toml
:
[dependencies]
tabprinter = "0.1.0"
Here's a basic example of how to use tabprinter
:
use tabprinter::{Table, TableStyle, Alignment};
fn main() {
let mut table = Table::new(TableStyle::Grid);
table.add_column("Name", 10, Alignment::Left);
table.add_column("Age", 5, Alignment::Right);
table.add_column("City", 15, Alignment::Center);
table.add_row(vec![
"Alice".to_string(),
"30".to_string(),
"New York".to_string(),
]);
table.add_row(vec![
"Bob".to_string(),
"25".to_string(),
"Los Angeles".to_string(),
]);
table.print().unwrap();
}
This will output:
+------------+-------+-----------------+
| Name | Age | City |
+------------+-------+-----------------+
| Alice | 30 | New York |
| Bob | 25 | Los Angeles |
+------------+-------+-----------------+
tabprinter
supports the following table styles:
Simple
: No bordersGrid
: ASCII bordersFancyGrid
: Unicode bordersClean
: Minimal bordersRound
: Rounded cornersBanner
: Top and bottom bannersBlock
: Block-style bordersAmiga
: Amiga-inspired style (color output only)To change the style, simply use a different TableStyle
when creating the table:
let mut table = Table::new(TableStyle::FancyGrid);
To use color output, use the print_color
method instead of print
:
use termcolor::{ColorChoice, StandardStream};
let mut stdout = StandardStream::stdout(ColorChoice::Always);
table.print_color(&mut stdout).unwrap();
Check out the examples
directory for more usage examples:
basic_usage.rs
: Demonstrates basic table creation and printingdifferent_styles.rs
: Shows all available table stylescustom_data.rs
: Example of using custom data structures with tablesTo run an example:
cargo run --example basic_usage
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.