cli-tables 0.1.0

A simple Rust library for generating ASCII tables in a CLI application.
Documentation

CLI Tables

This is a simple Rust library for generating ASCII tables in a CLI application. The Table struct takes in a Vec<Vec<String>> of data and generates an ASCII table from it.

Usage

  1. Add cli-tables to your Cargo.toml file:
[dependencies]
cli-tables = "0.1.0"
  1. Import the Table struct:
use cli_tables::Table;
  1. Create a Vec<Vec<String>> of data that you want to display in a table:
let table_arr: Vec<Vec<String>> = vec![
    vec!["#".to_string(), "First Name".to_string(), "Last Name".to_string(), "Date of Birth".to_string(), "TV Show".to_string()],
    vec!["0".to_string(), "Pedro".to_string(), "Pascal".to_string(), "1996-07-28".to_string(), "The Last of Us".to_string()],
    vec!["1".to_string(), "Belle".to_string(), "Ramsey".to_string(), "1991-09-17".to_string(), "The Last of Us".to_string()],
    vec!["3".to_string(), "Scott".to_string(), "Shepherd".to_string(), "1990-04-20".to_string(), "The Last of Us".to_string()],
    vec!["4".to_string(), "Nick".to_string(), "Offerman".to_string(), "1970-06-26".to_string(), "The Last of Us".to_string()]
];
  1. Create a Table struct from the data:
let mut table = Table::new(&table_arr);
  1. Generate the ASCII table as a string using the to_string() method:
let table_str = table.to_string();
  1. Print the table string to the console:
println!("{}", table_str);
  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 |
+---+------------+-----------+---------------+----------------+