bonsaiden / cursive_tree_view Goto Github PK
View Code? Open in Web Editor NEWA tree view implementation for cursive.
License: Apache License 2.0
A tree view implementation for cursive.
License: Apache License 2.0
If a node is collapsed, and its children is removed, and others are added, then the node is uncollapsed the program crashes.
Example program:
use cursive_tree_view::{Placement, TreeView};
fn main() {
let mut tree = TreeView::new();
tree.insert_item("A", Placement::LastChild, 0);
tree.insert_item("B", Placement::LastChild, 0);
tree.insert_item("C", Placement::LastChild, 1);
tree.insert_item("D", Placement::LastChild, 2);
tree.insert_item("E", Placement::LastChild, 2);
tree.set_collapsed(2, true);
let mut removed = tree.remove_children(2).unwrap().into_iter().collect::<Vec<_>>();
removed.push("F");
for child in removed {
tree.insert_item(child, Placement::LastChild, 2);
}
let mut siv = cursive::default();
siv.add_layer(tree);
siv.run();
}
If you run the program and try to unfold C, it crashes with the following backtrace:
thread 'main' panicked at 'index out of bounds: the len is 6 but the index is 6', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_tree_view-0.8.0/src/lib.rs:504:25
stack backtrace:
0: rust_begin_unwind
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
2: core::panicking::panic_bounds_check
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:84:5
3: <cursive_tree_view::TreeView<T> as cursive_core::view::view_trait::View>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_tree_view-0.8.0/src/lib.rs:504:25
4: cursive_core::view::view_wrapper::ViewWrapper::wrap_draw::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:54:28
5: <cursive_core::views::boxed_view::BoxedView as cursive_core::view::view_wrapper::ViewWrapper>::with_view
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/boxed_view.rs:52:14
6: cursive_core::view::view_wrapper::ViewWrapper::wrap_draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:54:9
7: cursive_core::view::view_wrapper::<impl cursive_core::view::view_trait::View for T>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:112:9
8: cursive_core::view::view_wrapper::ViewWrapper::wrap_draw::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:54:28
9: <cursive_core::views::circular_focus::CircularFocus<T> as cursive_core::view::view_wrapper::ViewWrapper>::with_view
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:183:41
10: cursive_core::view::view_wrapper::ViewWrapper::wrap_draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:54:9
11: cursive_core::view::view_wrapper::<impl cursive_core::view::view_trait::View for T>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:112:9
12: <cursive_core::views::layer::Layer<T> as cursive_core::view::view_wrapper::ViewWrapper>::wrap_draw::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/layer.rs:50:13
13: cursive_core::printer::Printer::with_color
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/printer.rs:349:9
14: <cursive_core::views::layer::Layer<T> as cursive_core::view::view_wrapper::ViewWrapper>::wrap_draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/layer.rs:46:9
15: cursive_core::view::view_wrapper::<impl cursive_core::view::view_trait::View for T>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:112:9
16: <cursive_core::views::shadow_view::ShadowView<T> as cursive_core::view::view_wrapper::ViewWrapper>::wrap_draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/shadow_view.rs:108:9
17: cursive_core::view::view_wrapper::<impl cursive_core::view::view_trait::View for T>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/view/view_wrapper.rs:112:9
18: <cursive_core::views::stack_view::ChildWrapper<T> as cursive_core::view::view_trait::View>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/stack_view.rs:137:44
19: cursive_core::views::stack_view::StackView::draw_fg::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/stack_view.rs:564:17
20: cursive_core::printer::Printer::with_effects
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/printer.rs:424:21
21: cursive_core::printer::Printer::with_style::{{closure}}
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/printer.rs:382:13
22: cursive_core::printer::Printer::with_color
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/printer.rs:349:9
23: cursive_core::printer::Printer::with_style
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/printer.rs:381:9
24: cursive_core::views::stack_view::StackView::draw_fg
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/stack_view.rs:559:9
25: cursive_core::views::screens_view::ScreensView<cursive_core::views::stack_view::StackView>::draw_fg
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/views/screens_view.rs:98:13
26: cursive_core::cursive::Cursive::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive.rs:147:9
27: cursive_core::cursive_run::CursiveRunner<C>::draw
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive_run.rs:100:9
28: cursive_core::cursive_run::CursiveRunner<C>::refresh
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive_run.rs:195:9
29: cursive_core::cursive_run::CursiveRunner<C>::post_events
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive_run.rs:175:13
30: cursive_core::cursive_run::CursiveRunner<C>::step
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive_run.rs:217:9
31: cursive_core::cursive_run::CursiveRunner<C>::run
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive_run.rs:239:13
32: cursive_core::cursive::Cursive::try_run_with
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive_core-0.3.7/src/cursive.rs:919:9
33: cursive::cursive_runnable::CursiveRunnable::try_run
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive-0.20.0/src/cursive_runnable.rs:80:9
34: cursive::cursive_runnable::CursiveRunnable::run
at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cursive-0.20.0/src/cursive_runnable.rs:75:9
35: viewtest::main
at ./src/main.rs:25:5
36: core::ops::function::FnOnce::call_once
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I get the following errors:
Compiling cursive-test v0.1.0 (/home/lemoine/Projects/rust/cursive-test)
error[E0282]: type annotations needed
--> src/file_tree.rs:94:51
|
94 | tree.set_on_collapse(|siv: &mut Cursive, row, is_collapsed, children| {
| ^^^^^^^^^^^^ consider giving this closure parameter a type
|
= note: type must be known at this point
error[E0277]: the trait bound `cursive_tree_view::TreeView<file_tree::main::TreeEntry>: cursive::view::view_wrapper::ViewWrapper` is not satisfied
--> src/file_tree.rs:96:17
|
96 | siv.call_on_id("tree", move |tree: &mut TreeView<TreeEntry>| {
| ^^^^^^^^^^ the trait `cursive::view::view_wrapper::ViewWrapper` is not implemented for `cursive_tree_view::TreeView<file_tree::main::TreeEntry>`
|
= note: required because of the requirements on the impl of `cursive::view::view_trait::View` for `cursive_tree_view::TreeView<file_tree::main::TreeEntry>`
error[E0599]: no method named `with_id` found for type `cursive_tree_view::TreeView<file_tree::main::TreeEntry>` in the current scope
--> src/file_tree.rs:106:39
|
106 | siv.add_layer(Dialog::around(tree.with_id("tree")).title("File View"));
| ^^^^^^^
|
= note: the method `with_id` exists but the following trait bounds were not satisfied:
`&cursive_tree_view::TreeView<file_tree::main::TreeEntry> : cursive::view::identifiable::Identifiable`
`&mut cursive_tree_view::TreeView<file_tree::main::TreeEntry> : cursive::view::identifiable::Identifiable`
`cursive_tree_view::TreeView<file_tree::main::TreeEntry> : cursive::view::identifiable::Identifiable`
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
`use cursive::view::identifiable::Identifiable;
Apparently cursive_tree_view no longer works with cursive v. 0.13 because the ViewWrapper trait is not implemented. I will probably get around to fixing it myself at some point, but a short-term workaround would be to update the README and perhaps cargo.toml.
In my usage of cursive_tree_view I would like to add support for filtering out child nodes whose names don't match some criteria. It will be easier to accomplish this if it is possible to hide the nodes that match the criteria without removing them from the tree view.
Hi,
would be nice to have an implementation for building a TreeView from a Walkdir iterator, possibly more flexible than just From<Walkdir>
because of custom filtering and so on.
Line 401 in e37b9b3
When container is fully emptied by calling remove_item(row)
subtraction overflow happens.
This happens only in debug mode due to additional Rust checks!
I notice you have a take_items method that I need to grab the data from the tree.
Is it possible to grab the data with draining the values ? I won't the tree to remain filled with data.
Thanks
I created a new project with Cursive 0.9 (or 0.8) and I couldn't compile when adding cursive_tree_view:
[dependencies]
cursive = "0.9"
From the basic example, here is the error:
cargo run --example basic
Compiling cursive_tree_view v0.2.1 (file:///path/cursive_tree_view)
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:427:26
|
427 | impl<T: Display + Debug> View for TreeView<T> {
| -- ^^^^
| |
| help: consider adding an explicit lifetime bound `T: 'static`...
|
note: ...so that the type `TreeView<T>` will meet its required lifetime bounds
--> src/lib.rs:427:26
|
427 | impl<T: Display + Debug> View for TreeView<T> {
| ^^^^
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:427:26
|
427 | impl<T: Display + Debug> View for TreeView<T> {
| -- ^^^^
| |
| help: consider adding an explicit lifetime bound `T: 'static`...
|
note: ...so that the type `T` will meet its required lifetime bounds
--> src/lib.rs:427:26
|
427 | impl<T: Display + Debug> View for TreeView<T> {
| ^^^^
error: aborting due to 2 previous errors
This seems like a typo, since there are no mutable calls done in the method body, so the '&mut
seems incorrect.
Would you be interested in an enhancement that brings much of the functionality of examples/file.rs into a new View implementation (still based on TreeView)? Might be up for making this change.
Hello,
I'm using your crate, it's awesome! I have a question: Is it possible to use strings bigger than screen size as items? For now, such strings are cut at the end of screen/layout. Is it possible if item be multi-line, like in TextView?
Would be awesome to have a From<Iterator<Item = PathBuf>>
implementation for TreeView
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.