Crate tree_decorator[][src]

Expand description

An utility rust lib to render pleasing tree structures at terminal programs.

The tree_decorator crate goal is to simplify tree structure display while ensuring a good looking to it. So it just handle strings, returning the expected result (with current level and supplied styles) and nothing more.

Usage

Before everything, a Decorator must be built using DecoratorBuilder, a custom one can be used or just use the default one StandardDecorator.

use tree_decorator::DecoratorBuilder;

DecoratorBuilder::default()
                 .build();

After that, everything works around tree_item! macro (please, see it to detailed explanations).

Styles

Some styles can be applied to a tree item by using a defined Style struct field’s name, multiple ones can be used separating them with ; and ending with , (see tree_item! to more examples).

Order doesn’t matter, at style list, it can be defined at any arbitrary order.

Custom Value

By default, only using style’s name, will apply an enable value (see at StyleItemValue).

Most of it, such as block, dashed or last, don’t need a specialized value (even if it could be explicit defined), but entry should be specified using a custom Entry value.

use tree_decorator::{
    decorator::Entry,
    tree_item
};

tree_item!(entry: Entry::Double, "Item with style custom value");

Examples

use tree_decorator::tree_item;

tree_item!(block, "Items List");
tree_item!("Sub Item");
tree_item!("Another Sub Item");
tree_item!(last, "Last Sub Item");

At some occasions, because how tree_decorator works, some blocks may still be opened, as there is no way to know when it should be closed by context, and another tree_item! doesn’t applies (or simply because it’s too much blocks to close).

There is some options:

use tree_decorator::{
    close_tree_item,
    tree_item
};

tree_item!(block, "Items List");
tree_item!(block, "Sub Item");
tree_item!(block, "Another Sub Item");
tree_item!(last, "Last Sub Item");
close_tree_item!(2); // close two remaining opened blocks
use tree_decorator::{
    end_all_tree_items,
    tree_item
};

tree_item!(block, "Items List");
tree_item!(block, "Sub Item");
tree_item!(block, "Another Sub Item");
tree_item!(last, "Last Sub Item");
end_all_tree_items!(); // close all opened blocks

Features

Re-exports

pub use decorator::Decorator;

Modules

Macros

Close one or more tree items.

Close all opened blocks

Prepares tree item with provided styles.

Tree item call with a log::debug!.

Tree item call with a log::error!.

Tree item call with a log::info!.

Tree item call with a log::trace!.

Tree item call with a log::warn!.

Structs

Builds a Decorator and prepares it.

Handle tree elements by applying styles.

Placeholder Decorator, it does nothing.

Default decorator implementation.

A style to be applied to tree item.

Functions

Reference to current Decorator.

Mutable reference to current ElementHandler.

Current block level.

Reset block level.

Reset everything to it’s initial state.