cli-tables 0.2.1

A simple Rust library for generating ASCII tables in a CLI application.
Documentation
  • Coverage
  • 42.86%
    6 out of 14 items documented6 out of 12 items with examples
  • Size
  • Source code size: 32.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.57 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ethanhelwig/cli-tables
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ethanhelwig

CLI Tables

This is a simple Rust library for generating ASCII tables in a CLI application.

Functions

Name Description
push pushes a record (or row) to the Table object.
delete deletes a record from the Table object.
get gets a record from the Table object.
set sets multiple records as the Table object.
to_string returns a String containing the formatted Table object.
num_records returns the number of records.
num_fields returns the number of fields.

Usage

  1. Add cli-tables to your Cargo.toml file:
[dependencies]
cli-tables = "0.2.1"
  1. Import the Table struct:
use cli_tables::Table;
  1. Create a new Table:
let mut table = Table::new();
  1. Create a record that you want to display in the table:
let header = vec!["#", "First Name", "Last Name", "Date of Birth", "TV Show"];
table.push_row(&header);
  1. Or create multiple records at once:
let values = vec![
    vec!["0", "Pedro", "Pascal", "1996-07-28", "The Last of Us"],
    vec!["1", "Belle", "Ramsey", "1991-09-17", "The Last of Us"],
    vec!["2", "Scott", "Shepherd", "1990-04-20", "The Last of Us"],
    vec!["3", "Nick", "Offerman", "1970-06-26", "The Last of Us"]
];
table.push_rows(&values);
  1. Print the table with the to_string function:
println!("{}", table.to_string());
  1. The table will look like this:
+---+------------+-----------+---------------+----------------+
| # | First Name | Last Name | Date of Birth | TV Show        |
+---+------------+-----------+---------------+----------------+
| 0 | Pedro      | Pascal    | 1996-07-28    | The Last of Us |
| 1 | Belle      | Ramsey    | 1991-09-17    | The Last of Us |
| 3 | Scott      | Shepherd  | 1990-04-20    | The Last of Us |
| 4 | Nick       | Offerman  | 1970-06-26    | The Last of Us |
+---+------------+-----------+---------------+----------------+