ascii_table_rs

Crates.ioascii_table_rs
lib.rsascii_table_rs
version1.0.2
created_at2025-10-14 21:45:48.742538+00
updated_at2025-11-17 21:12:18.534859+00
descriptionElegant ASCII table renderer for Rust CLI and terminal apps
homepagehttps://github.com/bieli/ascii-table-rs
repositoryhttps://github.com/bieli/ascii-table-rs
max_upload_size
id1883253
size26,998
Marcin Bielak (bieli)

documentation

README

ascii-table-rs

CI status github_tag Crates.io

ascii-table-rs is a lightweight, flexible Rust library for rendering beautiful ASCII tables in the terminal.

It supports automatic column sizing, customizable float precision, summary rows, and Unicode box-drawing characters for a polished CLI/terminals experience.

Features

  • Easy-to-use API for defining headers, rows, and summaries
  • Auto-resizing columns based on content width
  • Supports String, i64, and f64 cell types
  • Configurable decimal precision for floats (with truncation, not rounding)
  • Unicode box-drawing borders for clean layout
  • Unit-tested and ready for production use

Demo example

Run demo example program with:

$ cargo run --example demo
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/demo`
╭───────────────────────────────────────────────────────────────────────────────────────╮
│                                   Cluster Overview                                    │
├─────────┬────────────┬───────────────────┬───────────────────┬─────────────┬──────────┤
│ Cluster │ Node Count │ Outgoing Gateways │ Incoming Gateways │ Connections │ RTT [ms] │
├─────────┼────────────┼───────────────────┼───────────────────┼─────────────┼──────────┤
│ west    │ 1          │ 2                 │ 2                 │ 0           │ 1.234    │
│ east    │ 1          │ 2                 │ 2                 │ 0           │ 4.321    │
│ central │ 1          │ 2                 │ 2                 │ 1           │ 3.345    │
├─────────┼────────────┼───────────────────┼───────────────────┼─────────────┼──────────┤
│         │ 3          │ 6                 │ 6                 │ 1           │ 8.900    │
╰─────────┴────────────┴───────────────────┴───────────────────┴─────────────┴──────────╯

Quick Start

Add to your Cargo.toml

[dependencies]
ascii-table-rs = "1.0.0"

Create and render a table

use ascii_table_rs::{AsciiTable, CellValue};

fn main() {
    let mut table = AsciiTable::new("Cluster Overview");
    table.set_headers(vec!["Cluster", "Nodes", "Gateways", "Load"]);
    table.set_decimal_places(3); // Optional: set float precision

    table.add_row(vec![
        CellValue::Str("west".into()),
        CellValue::Int(3),
        CellValue::Int(5),
        CellValue::Float(0.8234),
    ]);

    table.add_row(vec![
        CellValue::Str("east".into()),
        CellValue::Int(2),
        CellValue::Int(4),
        CellValue::Float(0.9127),
    ]);

    table.set_summary(vec![
        CellValue::Str("Total".into()),
        CellValue::Int(5),
        CellValue::Int(9),
        CellValue::Float(1.7361),
    ]);

    table.render();
}

After running below program, you can see ASCII table like this:

╭────────────────────────────────────╮
│          Cluster Overview          │
├─────────┬───────┬──────────┬───────┤
│ Cluster │ Nodes │ Gateways │ Load  │
├─────────┼───────┼──────────┼───────┤
│ west    │ 3     │ 5        │ 0.823 │
│ east    │ 2     │ 4        │ 0.912 │
├─────────┼───────┼──────────┼───────┤
│ Total   │ 5     │ 9        │ 1.736 │
╰─────────┴───────┴──────────┴───────╯

Public API overview for this library

  • AsciiTable::new(title: &str) - Creates a new table with a title.

  • set_headers(Vec<&str>) - Defines column headers.

  • add_row(Vec<CellValue>) - Adds a row of data.

  • set_summary(Vec<CellValue>) -Adds a summary row at the bottom.

  • set_decimal_places(usize) - Sets float precision (default is 2 digits, truncates not rounds).

  • render_to_string(&self) -> String - Renders the table to String (without printing to STDOUT).

  • render() - Prints the table to STDOUT.

Testing

Run unit tests with:

$ cargo test

TODO list

  • create tag and release for first version

  • add CI for Rust in GIthub Actions

  • update unit tests

  • publish library to cargo repository

  • add summary auto aggregates (sum, mul, avg, mean, std_dev, percentile_99)

  • add CSV file as input to table to visualize CSV cells

  • connect previous features to auto aggregates and CSV view, to calculate aggregates from CSV files

  • create bin program for exucure below features in terminal pipeline like cat salaries.csv | csv2tab --summary sum

  • add feature to auto refresh table on terminal with defined seconds

  • add code test coverage metrics

Contributing

Pull requests, issues, and feedback are welcome! Let’s make ASCII tables beautiful together.

Commit count: 0

cargo fmt