Crate tree_decorator

Source
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;
pub use decorator::Style;

Modules§

decorator

Macros§

close_tree_item
Close one or more tree items.
end_all_tree_items
Close all opened blocks
tree_item
Prepares tree item with provided styles.
tree_item_debug
Tree item call with a log::debug!.
tree_item_error
Tree item call with a log::error!.
tree_item_info
Tree item call with a log::info!.
tree_item_trace
Tree item call with a log::trace!.
tree_item_warn
Tree item call with a log::warn!.

Structs§

DecoratorBuilder
Builds a Decorator and prepares it.
ElementHandler
Handle tree elements by applying styles.
NoDecorator
Placeholder Decorator, it does nothing.
StandardDecorator
Default decorator implementation.

Functions§

decorator
Reference to current Decorator.
element_handler
Mutable reference to current ElementHandler.
level
Current block level.
reset_level
Reset block level.
shutdown
Reset everything to it’s initial state.