Skip to main content

tiny_table/
lib.rs

1//! A terminal table renderer with column sizing, truncation, wrapping, and
2//! section separators.
3//!
4//! The crate is designed around three core building blocks:
5//!
6//! - [`Table`] holds headers, rows, and the rendering configuration.
7//! - [`Column`] defines a header plus default styling for a column.
8//! - [`Cell`] lets you override styling or truncation on individual values.
9//!
10//! # Quick Start
11//!
12//! ```rust
13//! use tiny_table::{Cell, Column, Align, Table, Trunc};
14//!
15//! let mut table = Table::with_columns(vec![
16//!     Column::new("Name").width(0.30),
17//!     Column::new("Role").truncate(Trunc::Middle),
18//!     Column::new("Status"),
19//! ]);
20//!
21//! table.add_section("Team").align(Align::Left);
22//! table.add_row(vec![
23//!     Cell::new("Ada Lovelace"),
24//!     Cell::new("Principal Engineer"),
25//!     Cell::new("Active").bright_green().bold(),
26//! ]);
27//!
28//! let rendered = table.render();
29//! assert!(rendered.contains("Name"));
30//! assert!(rendered.contains("Ada Lovelace"));
31//! ```
32//!
33//! # How It Fits Together
34//!
35//! - Use [`Table::with_columns`] when you already know the schema.
36//! - Use [`Table::add_row`] to append values.
37//! - Use [`Table::column`] to tweak one column by index or header text.
38//! - Use [`Table::add_section`] or [`Table::add_separator`] to break the table
39//!   into visual groups.
40//! - Use [`Table::render`] when you want the formatted string, or [`Table::print`]
41//!   when you just want to write it to standard output.
42//!
43//! When a terminal width is available, fractional columns are distributed across
44//! the remaining content width after fixed and content-based columns are resolved.
45
46#![warn(missing_docs)]
47
48/// Color types and ANSI escape-code generation used by the styling API.
49#[cfg(feature = "style")]
50pub mod color;
51pub mod table;
52
53/// A convenience type for specifying truecolor values by RGB components.
54#[cfg(feature = "style")]
55pub use color::CustomColor;
56/// Alignment options for section labels.
57pub use table::Align;
58/// A table cell containing content and optional styling overrides.
59pub use table::Cell;
60/// A color selector used by styling methods.
61#[cfg(feature = "style")]
62pub use table::Color;
63/// A column definition with a header and default styling.
64pub use table::Column;
65/// A selector used to style a column by index or header text.
66pub use table::ColumnTarget;
67/// A column width configuration used when rendering a table.
68pub use table::ColumnWidth;
69/// A section definition used to group rows and render a label.
70pub use table::SectionStyle;
71/// The main table type.
72pub use table::Table;
73/// A border style used for tables, sections, and separators.
74pub use table::TableStyle;
75/// Truncation modes for cell content.
76pub use table::Trunc;