Expand description
Multi-Format Data Visualization Library
Deprecated: This crate has been renamed to
data_fmt.
Use data_fmt for all new projects — the API is identical.
10 formatters, 33 variants, zero core dependencies. Build your data structure once, then output as table, tree, expanded, JSON, HTML, SQL, YAML, TOML, logfmt, or text.
§Features
RowBuilder: Constructs tabular data (headers + rows)TreeBuilder: Constructs trees from flat data with path-based insertion- 10 Formatters: Table (9 styles), Tree (3), Expanded (2), JSON, HTML (4), SQL (4), YAML, TOML, Logfmt, Text (6)
- String Output: All formatters return
String, no direct console output
The library supports 10 output formats across 33 variants:
- Table: 9 styles (plain, markdown, csv, bordered, grid, unicode, minimal, tsv, compact)
- Expanded: Vertical record display (
PostgreSQL\xmode, property list) - Tree: Hierarchical display (hierarchical, aligned, aggregated)
- JSON/YAML/TOML: Data serialization formats
- HTML: 4 themes (minimal, bootstrap, tailwind, custom)
- SQL: 4 dialects (ANSI,
PostgreSQL,MySQL,SQLite) - Logfmt: Structured log output
- Text: 6 styles (bullets, numbered, sections, key-value, compact, CLI help)
§Examples
§Same data in three visual formats
use tree_fmt::{ RowBuilder, TableFormatter, ExpandedFormatter, TreeFormatter };
// Create tabular data
let tree = RowBuilder::new( vec![ "Name".into(), "Age".into() ] )
.add_row( vec![ "Alice".into(), "30".into() ] )
.add_row( vec![ "Bob".into(), "25".into() ] )
.build();
// Table format
let table_fmt = TableFormatter::new();
let output = table_fmt.format( &tree );
// Expanded format
let expanded_fmt = ExpandedFormatter::new();
let output = expanded_fmt.format( &tree );
// Tree format (table-shaped tree)
let tree_fmt = TreeFormatter::default();
let output = tree_fmt.format( &tree, Clone::clone );§Expanded format with colored keys
use tree_fmt::{ RowBuilder, ExpandedFormatter, ExpandedConfig };
let tree = RowBuilder::new( vec![ "Name".into(), "Score".into() ] )
.add_row( vec![ "Alice".into(), "95".into() ] )
.build();
// Gray keys for terminal output (PostgreSQL style)
let formatter = ExpandedFormatter::with_config(
ExpandedConfig::new().colorize_keys( true )
);
let output = formatter.format( &tree );§Property list style (colon separator)
use tree_fmt::{ RowBuilder, ExpandedFormatter, ExpandedConfig };
let tree = RowBuilder::new( vec![ "Command".into(), "Status".into() ] )
.add_row( vec![ "build".into(), "success".into() ] )
.build();
// Property list style: no record headers, colon separator
let formatter = ExpandedFormatter::with_config( ExpandedConfig::property_style() );
let output = formatter.format( &tree );
// Output:
// Command: build
// Status: success§Building and formatting a tree
use tree_fmt::{ TreeBuilder, TreeFormatter };
let tree = TreeBuilder::new( "root" )
.insert( &[ "src", "main.rs" ], 150 )
.insert( &[ "src", "lib.rs" ], 300 )
.build();
let formatter = TreeFormatter::new();
let output = formatter.format( &tree, | lines | format!( "{} lines", lines ) );
println!( "{}", output );§Building from items
use tree_fmt::TreeBuilder;
use std::path::PathBuf;
let files = vec![
( PathBuf::from( "src/main.rs" ), 100 ),
( PathBuf::from( "tests/test.rs" ), 50 ),
];
let tree = TreeBuilder::from_items( &files, | ( path, _size ) | {
path.components().map( | c | c.as_os_str().to_string_lossy().to_string() ).collect()
}, | ( path, size ) | ( path.clone(), *size ) );§Formatting a table
use tree_fmt::{ RowBuilder, TableFormatter };
let tree = RowBuilder::new( vec![ "File".into(), "Lines".into() ] )
.add_row( vec![ "main.rs".into(), "100".into() ] )
.add_row( vec![ "lib.rs".into(), "200".into() ] )
.build();
let formatter = TableFormatter::new();
let output = formatter.format( &tree );
println!( "{}", output );Re-exports§
pub use formatters::Format;pub use formatters::FormatError;pub use formatters::TableFormatter;pub use formatters::ExpandedFormatter;pub use formatters::TreeFormatter;pub use formatters::LogfmtFormatter;pub use formatters::TableShapedFormatter;
Modules§
- conversions
- Data conversion utilities between tree representations
- formatters
- Formatting implementations for different display modes
Structs§
- Colorful
Text - Text string paired with an optional ANSI color prefix.
- Column
Data - Multi-column data for aligned tree formatting
- Expanded
Config - Formatter parameters for expanded (vertical record) output
- RowBuilder
- Builder for constructing table-shaped trees
- Table
Config - Formatter parameters for table output
- Table
Metadata - Metadata describing table structure and column types
- Table
View - Canonical table data structure for unified formatting
- Tree
Builder - Builder for constructing tree structures from flat data
- Tree
Config - Formatter parameters for tree output
- Tree
Node - Generic tree node that can hold any data type
- Tree
Symbols - Tree symbols used for rendering
- Wrap
Config - Configuration for word-wrap behavior.
- Wrap
Formatter - Word-wrap formatter; wraps strings to configured width using
WrapConfig.
Enums§
- Border
Variant - Border rendering variant for tables
- Break
Strategy - Controls how lines are broken when content exceeds
WrapConfig::width. - Column
Flex - Column flexibility classification for auto-wrapping budget allocation
- Column
Separator - Column separator parameter
- Data
Type - Data type classification for table columns
- Fold
Style - Determines how overflow columns are rendered as continuation lines below a row.
- Header
Separator Variant - Header separator line variant
- Overflow
- Controls output behavior when
max_linesis exceeded. - Padding
Side - Where to place alignment padding in key-value pairs
Traits§
- Table
Shaped View - Trait for working with table-shaped trees
Functions§
- pad_
to_ width - Own namespace of the module. Pad text to target display width while respecting ANSI codes and wide Unicode characters.
- truncate_
cell - Truncate text to maximum visual width with ANSI code preservation
- visual_
len - Own namespace of the module. Calculate the visible character count (char-based, Tier 1).