mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +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.
|
/// 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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user