Add manual-loop methods

is_running() and step()
This commit is contained in:
Alexandre Bury 2016-12-15 20:24:48 +01:00
parent 858067ef6b
commit 2bacfcb11e

View File

@ -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. /// Runs the event loop.
/// ///
/// It will wait for user input (key presses) /// It will wait for user input (key presses)
/// and trigger callbacks accordingly. /// 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) { pub fn run(&mut self) {
// And the big event loop begins! // And the big event loop begins!
while self.running { 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() { if let Ok(cb) = self.cb_source.try_recv() {
cb(self); cb(self);
} }
@ -570,7 +592,6 @@ impl Cursive {
} }
} }
} }
}
/// Stops the event loop. /// Stops the event loop.
pub fn quit(&mut self) { pub fn quit(&mut self) {