Skip to main content

Crate tree_fmt

Crate tree_fmt 

Source
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 \x mode, 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§

ColorfulText
Text string paired with an optional ANSI color prefix.
ColumnData
Multi-column data for aligned tree formatting
ExpandedConfig
Formatter parameters for expanded (vertical record) output
RowBuilder
Builder for constructing table-shaped trees
TableConfig
Formatter parameters for table output
TableMetadata
Metadata describing table structure and column types
TableView
Canonical table data structure for unified formatting
TreeBuilder
Builder for constructing tree structures from flat data
TreeConfig
Formatter parameters for tree output
TreeNode
Generic tree node that can hold any data type
TreeSymbols
Tree symbols used for rendering
WrapConfig
Configuration for word-wrap behavior.
WrapFormatter
Word-wrap formatter; wraps strings to configured width using WrapConfig.

Enums§

BorderVariant
Border rendering variant for tables
BreakStrategy
Controls how lines are broken when content exceeds WrapConfig::width.
ColumnFlex
Column flexibility classification for auto-wrapping budget allocation
ColumnSeparator
Column separator parameter
DataType
Data type classification for table columns
FoldStyle
Determines how overflow columns are rendered as continuation lines below a row.
HeaderSeparatorVariant
Header separator line variant
Overflow
Controls output behavior when max_lines is exceeded.
PaddingSide
Where to place alignment padding in key-value pairs

Traits§

TableShapedView
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).