mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 11:16:03 +00:00
Add manual-loop methods
is_running() and step()
This commit is contained in:
parent
858067ef6b
commit
2bacfcb11e
25
src/lib.rs
25
src/lib.rs
@ -518,16 +518,38 @@ impl Cursive {
|
||||
|
||||
}
|
||||
|
||||
/// Returns `true` until [`quit(&mut self)`] is called.
|
||||
///
|
||||
/// [`quit(&mut self)`]: #method.quit
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.running
|
||||
}
|
||||
|
||||
|
||||
/// Runs the event loop.
|
||||
///
|
||||
/// It will wait for user input (key presses)
|
||||
/// and trigger callbacks accordingly.
|
||||
///
|
||||
/// Blocks until `quit()` is called.
|
||||
/// Calls [`step(&mut self)`] until [`quit(&mut self)`] is called.
|
||||
///
|
||||
/// [`step(&mut self)`]: #method.step
|
||||
/// [`quit(&mut self)`]: #method.quit
|
||||
pub fn run(&mut self) {
|
||||
|
||||
// And the big event loop begins!
|
||||
while self.running {
|
||||
self.step();
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs a single step from the event loop.
|
||||
///
|
||||
/// Useful if you need tighter control on the event loop.
|
||||
/// Otherwise, [`run(&mut self)`] might be more convenient.
|
||||
///
|
||||
/// [`run(&mut self)`]: #method.run
|
||||
pub fn step(&mut self) {
|
||||
if let Ok(cb) = self.cb_source.try_recv() {
|
||||
cb(self);
|
||||
}
|
||||
@ -570,7 +592,6 @@ impl Cursive {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops the event loop.
|
||||
pub fn quit(&mut self) {
|
||||
|
Loading…
Reference in New Issue
Block a user