tiny-table 0.2.1

A simple and customizable table library for Rust.
Documentation
  • Coverage
  • 99.12%
    224 out of 226 items documented8 out of 157 items with examples
  • Size
  • Source code size: 93.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.88 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 1s Average build duration of successful builds.
  • all releases: 1m 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • sn0w12/tiny-table
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sn0w12

Tiny Table

Tiny Table is a simple and customizable table library for Rust.

Installation

cargo add tiny-table

Or add it manually:

[dependencies]

tiny-table = "0.1.0"

To disable ANSI styling support:

[dependencies]

tiny-table = { version = "0.1.0", default-features = false }

Examples

Simple

use tiny_table::{Cell, Column, Table};

fn main() {
    let mut table = Table::with_columns(vec![
        Column::new("Name").width(15),
        Column::new("Role").width(20),
        Column::new("Status").width(10),
    ]);

    table.add_row(vec![
        Cell::new("Ada Lovelace"),
        Cell::new("Engineer"),
        Cell::new("Active"),
    ]);

    table.add_row(vec![
        Cell::new("Bob"),
        Cell::new("Support"),
        Cell::new("Away"),
    ]);

    println!("{}", table);
}
┌─────────────────┬──────────────────────┬────────────┐
│ Name            │ Role                 │ Status     │
├─────────────────┼──────────────────────┼────────────┤
│ Ada Lovelace    │ Engineer             │ Active     │
│ Bob             │ Support              │ Away       │
└─────────────────┴──────────────────────┴────────────┘

Styled

use tiny_table::{Align, Cell, Column, ColumnWidth, SectionStyle, Table, Trunc};

fn main() {
    let mut table = Table::with_columns(vec![
        Column::new("Name")
            .bright_cyan()
            .bold()
            .width(ColumnWidth::fill()),
        Column::new("Role").width(0.5).truncate(Trunc::Middle),
        Column::new("Status").bright_yellow().bold().width(0.3),
    ])
    .with_section_style(SectionStyle {
        horiz: "",
        mid_left: "",
        mid_right: "",
        mid_joint: "",
    })
    .with_separator_style(SectionStyle {
        horiz: "",
        mid_joint: "",
        ..SectionStyle::unicode()
    });

    table.add_section("Team").align(Align::Center);
    table.add_row(vec![
        Cell::new("Ada Lovelace"),
        Cell::new("Principal Engineer"),
        Cell::new("Active").bright_green(),
    ]);

    table.add_separator();
    table.add_row(vec![
        Cell::new("Bob"),
        Cell::new("Support"),
        Cell::new("Away"),
    ]);

    println!("{}", table);
}
┌────────────┬────────────────────────┬───────────────┐
│ Name       │ Role                   │ Status        │
╞════════════╪══════════ Team ════════╪═══════════════╡
│ Ada Lovel… │ Principal Engineer     │ Active        │
├╌╌╌╌╌╌╌╌╌╌╌╌│╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌│╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Bob        │ Support                │ Away          │
└────────────┴────────────────────────┴───────────────┘

Feature Flags

Style

Adds ANSI styling functions.