Improved the select example. (#501)

Now the `OnEventView.on_pre_event_inner()` calls return
`Some(EventResult::Consumed(Some(Callback)))` instead of
`Some(EventResult::Consumed(None))`.
This follows the guidelines from documentation of methods returning a
`Callback`, which say that it should be ran on the `Cursive`.
While in this example this doesn't make a difference, the previous
version created confusion for new users who might not realize you can
pass the `Callback`s to the `Cursive` this way.
This commit is contained in:
Mckol 2020-09-21 23:16:16 +02:00 committed by GitHub
parent e7a813b383
commit 7b579a7d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,12 +27,12 @@ fn main() {
// Let's override the `j` and `k` keys for navigation
let select = OnEventView::new(select)
.on_pre_event_inner('k', |s, _| {
s.select_up(1);
Some(EventResult::Consumed(None))
let cb = s.select_up(1);
Some(EventResult::Consumed(Some(cb)))
})
.on_pre_event_inner('j', |s, _| {
s.select_down(1);
Some(EventResult::Consumed(None))
let cb = s.select_down(1);
Some(EventResult::Consumed(Some(cb)))
});
let mut siv = cursive::default();