use {
cursive::{view::*, views::*, *},
cursive_tree::*,
};
fn main() -> Result<(), ()> {
let mut cursive = default();
let mut tree = SimpleTreeBackend::tree_view();
tree.model.add_root(NodeKind::Leaf, (), "Hello");
tree.model.add_root(NodeKind::Branch, (), "World");
let world = tree.model.at_path_mut([1].into()).expect("at_path_mut");
for i in 0..10 {
world.add_child(NodeKind::Leaf, (), format!("Child #{}", i + 1));
}
let mut gc = 0;
for c in 4..10 {
let child = tree.model.at_path_mut([1, c].into()).expect("at_path_mut");
child.kind = NodeKind::Branch;
for _ in 0..10 {
child.add_child(NodeKind::Leaf, (), format!("Grandchild #{}", gc + 1));
gc += 1;
}
}
tree.model.expand(None)?;
cursive.add_fullscreen_layer(Panel::new(tree.scrollable()));
cursive.add_global_callback('q', |cursive| cursive.quit());
cursive.run();
Ok(())
}