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
- Add
cli-tablesto yourCargo.tomlfile:
cli-tables = "0.1.0"
- Import the Table struct:
use Table;
- Create a
Vec<Vec<String>>of data that you want to display in a table:
let table_arr: = vec!;
- Create a
Tablestruct from the data:
let mut table = new;
- Generate the ASCII table as a string using the
to_string()method:
let table_str = table.to_string;
- Print the table string to the console:
println!;
- 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 |
+---+------------+-----------+---------------+----------------+