Skip to main content

AsyncRunner

Struct AsyncRunner 

Source
pub struct AsyncRunner { /* private fields */ }
Available on crate feature async only.
Expand description

An asynchronous Crossterm event and rendering loop.

See the module documentation for the full picture. Construct one with a RunnerConfig, then drive it with run (real terminal), run_with_backend (caller-supplied backend, such as HyperlinkBackend), or run_with_events (caller-supplied backend and event stream, for tests and hosts that own the terminal lifecycle).

Implementations§

Source§

impl AsyncRunner

Source

pub fn new(config: RunnerConfig) -> Self

Create a runner without touching the terminal.

Source

pub fn with_session_config(self, config: TerminalSessionConfig) -> Self

Override terminal lifecycle policy while retaining the async loop.

Source

pub fn scrollback(&self) -> Scrollback

Return a handle for publishing content above a ScreenMode::SplitFooter — see Scrollback. Blocks queued while running in ScreenMode::Alternate are discarded, since there is no scrollback of the host’s to write into.

Source

pub async fn run<S, V, U>( &self, theme: &Theme, state: &mut S, view: V, update: U, ) -> Result<()>

Run on the real terminal until update returns UpdateResult::Exit.

Enters a TerminalSession (restored on return, including on error or panic) and reads input from crossterm’s async EventStream.

Source

pub async fn run_with_backend<S, B, V, U>( &self, theme: &Theme, backend: B, state: &mut S, view: V, update: U, ) -> Result<()>
where B: Backend<Error = Error>, V: FnMut(&S, u64) -> Element, U: AsyncFnMut(&mut S, Signal) -> UpdateResult,

Run with a caller-provided backend, such as HyperlinkBackend. Otherwise identical to run: it owns the TerminalSession and the EventStream.

Source

pub async fn run_with_events<S, B, V, U, E, Er>( &self, terminal: &mut Terminal<B>, theme: &Theme, state: &mut S, events: E, view: V, update: U, ) -> Result<(), Er>
where B: Backend<Error = Er>, E: Stream<Item = Result<Event, Er>> + Unpin, V: FnMut(&S, u64) -> Element, U: AsyncFnMut(&mut S, Signal) -> UpdateResult,

The core loop: caller-owned terminal and events, no terminal lifecycle. This is what run builds on, and the seam tests use to drive the runner against a TestBackend with a scripted event stream. Hosts that already own their terminal and event source (or want a non-crossterm one) can call it directly.

The backend error and the event-stream error share one type Er, which is the run’s error type: for the real terminal that is io::Error, but leaving it generic lets an infallible backend (TestBackend, whose error is Infallible) pair with an infallible stream.

events yields already-translated tuika Events. An Err item ends the run by propagating out; None (a finite stream running dry) stops event delivery but leaves the tick timer running, so the loop still exits only when update returns UpdateResult::Exit.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.