tree-formatter-rs 0.1.0

A simple library to format hierarchical structures as text-based trees
Documentation
  • Coverage
  • 0%
    0 out of 21 items documented0 out of 18 items with examples
  • Size
  • Source code size: 27.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 442.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • abhishp/tree-formatter-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • abhishp

tree-formatter-rs

A simple library to format hierarchical structures as text-based trees.

Usage

This library provides macros and formatting utilities to easily create and display tree-like structures in text output. You can customize the appearance of the tree branches and item prefixes.

Example:

Assuming you have a formatter object (e.g., tree_formatter) that implements the necessary methods (begin_level, end_level, write_fmt), you can build a tree like this:

// Import the macros (adjust path as necessary)
// use tree_formatter::{tree_indent, tree_indent_last, tree_unindent, tree_write, tree_write_last};

// Assuming 'tree_formatter' is initialized, potentially with custom formats:
// let context_fmt = ContextFormat::new("    ", "│   "); // Example: default format
// let item_fmt = ItemPrefixFormat::new("├── ", "└── "); // Example: default format
// let mut tree_formatter = TreeFormatter::new(context_fmt, item_fmt); // Hypothetical writer

tree_write!(tree_formatter, "Root Node");

// Start the first branch
tree_indent!(tree_formatter);
tree_write!(tree_formatter, "Child 1");

// Start a nested branch
tree_indent!(tree_formatter);
tree_write!(tree_formatter, "Grandchild 1.1");
tree_write_last!(tree_formatter, "Grandchild 1.2");
tree_unindent!(tree_formatter); // End nested branch

tree_write_last!(tree_formatter, "Child 2 (last in this branch)");
tree_unindent!(tree_formatter); // End first branch

// Start the second (and last) branch from root
tree_indent_last!(tree_formatter);
tree_write!(tree_formatter, "Child 3");
tree_write_last!(tree_formatter, "Child 4 (last overall)");
tree_unindent!(tree_formatter); // End second branch

// Get the final output from the writer
// let output = tree_formatter.to_string();
// println!("{}", output);