pub struct EventLoop<'a> { /* private fields */ }Expand description
Runs mounted components until every one has finished. See the module docs.
Implementations§
Source§impl<'a> EventLoop<'a>
impl<'a> EventLoop<'a>
pub fn new(backend: impl Backend + 'a, options: LoopOptions) -> EventLoop<'a>
Sourcepub fn terminal(
session: SessionOptions,
options: LoopOptions,
) -> Result<EventLoop<'a>>
pub fn terminal( session: SessionOptions, options: LoopOptions, ) -> Result<EventLoop<'a>>
A loop on the real terminal, starting a Session.
Sourcepub fn mount<C: Component + 'a>(&mut self, component: C) -> Handle<C::Output>
pub fn mount<C: Component + 'a>(&mut self, component: C) -> Handle<C::Output>
Add a component. Its outcome is in the handle once it finishes.
Sourcepub fn graphics(&mut self, source: Arc<dyn PlacementSource>)
pub fn graphics(&mut self, source: Arc<dyn PlacementSource>)
Draw the graphics source places on the views’ cells (micro assets
through Kitty, iTerm2 or Sixel). The loop wakes when an animation
among them shows its next frame. Give it only on a terminal that
showed it can draw them.
Sourcepub fn every(&mut self, interval: Duration, callback: impl FnMut() -> bool + 'a)
pub fn every(&mut self, interval: Duration, callback: impl FnMut() -> bool + 'a)
Call callback every interval while the loop runs, until it
returns false.
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Run until every mounted component has finished. Ctrl+C finishes all of them as interrupted.
Sourcepub fn step(&mut self, event: Event) -> Result<bool>
pub fn step(&mut self, event: Event) -> Result<bool>
Push driving, for a host that cannot block in
Backend::read (a browser tab, another program’s event loop):
deliver event, as run does with one it read, then
fire the ticks and timers due by the backend’s
elapsed time and paint. Returns whether a
component is still running. The first call (of this or
pump) starts the components and paints them first;
once none is running, events are dropped. Call
finish at the end.
Steps give the same results as run given the same
events at the same times. PushBackend is a
backend made for it: the host sets its time and takes what was
painted.
use rich_interact::{EventLoop, Event, Key, KeyCode, LoopOptions, Outcome, PushBackend, Select};
let backend = PushBackend::new(30, 6);
let port = backend.port();
let mut event_loop = EventLoop::new(backend, LoopOptions::default());
let handle = event_loop.mount(Select::new("Pick", vec!["red".to_string(), "green".to_string()]));
event_loop.pump().unwrap();
assert!(port.take_output().contains("red"));
event_loop.step(Event::Key(Key::new(KeyCode::Down))).unwrap();
let running = event_loop.step(Event::Key(Key::new(KeyCode::Enter))).unwrap();
assert!(!running);
event_loop.finish().unwrap();
assert_eq!(handle.take(), Some(Outcome::Done("green".to_string())));Sourcepub fn pump(&mut self) -> Result<bool>
pub fn pump(&mut self) -> Result<bool>
Push driving without an event: the turn run takes
when a read times out. Fires the ticks and timers due by the
backend’s time, starts what was mounted, and paints; returns whether
a component is still running. Call it when
timeout has passed (after moving the backend’s
clock), and once at the start to paint the first view.
Sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
How long until a tick or timer is due, by the backend’s time:
when to pump next. None: only an event changes
anything.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether a mounted component is still running.