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:
- Specific close one or more blocks using
close_tree_item!
:
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
end_all_tree_items!
to close it all:
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
no_log
: Opt-out log dependency and it’s related macros (tree_item_debug!
,tree_item_error!
,tree_item_info!
,tree_item_trace!
andtree_item_warn!
).
Re-exports§
Modules§
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§
- Decorator
Builder - Builds a
Decorator
and prepares it. - Element
Handler - Handle tree elements by applying styles.
- NoDecorator
- Placeholder
Decorator
, it does nothing. - Standard
Decorator - 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.