Skip to main content

App

Struct App 

Source
pub struct App {
    pub theme: Mutable<Arc<Theme>>,
    pub animator: Mutex<Animator>,
    /* private fields */
}
Expand description

The boba application runner.

Create an App with your View implementation, configure its theme, then run it asynchronously. The terminal is managed automatically: raw mode is enabled, an alternate screen is used, and state is restored on exit.

Fields§

§theme: Mutable<Arc<Theme>>

The currently active Theme. Change it with App::set_theme.

§animator: Mutex<Animator>

Implementations§

Source§

impl App

Source

pub fn new(v: impl View + 'static) -> Self

Construct an app wrapping view.

Examples found in repository?
examples/hello_layout.rs (line 88)
85fn main() {
86    let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap();
87    rt.block_on(async {
88        App::new(HelloView).run().await.unwrap();
89    });
90}
More examples
Hide additional examples
examples/layout.rs (line 458)
452fn main() {
453    let rt = tokio::runtime::Builder::new_multi_thread()
454        .enable_all()
455        .build()
456        .unwrap();
457    rt.block_on(async {
458        App::new(LayoutView::new()).run().await.unwrap();
459    });
460}
Source

pub fn set_theme(&self, theme: Theme)

Replace the active theme at runtime.

Source

pub async fn run(self) -> Result<()>

Run the app until a AppEvent::Quit is emitted.

Initializes raw mode, the alternate screen, and mouse capture; restores everything on exit.

Examples found in repository?
examples/hello_layout.rs (line 88)
85fn main() {
86    let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap();
87    rt.block_on(async {
88        App::new(HelloView).run().await.unwrap();
89    });
90}
More examples
Hide additional examples
examples/layout.rs (line 458)
452fn main() {
453    let rt = tokio::runtime::Builder::new_multi_thread()
454        .enable_all()
455        .build()
456        .unwrap();
457    rt.block_on(async {
458        App::new(LayoutView::new()).run().await.unwrap();
459    });
460}

Methods from Deref<Target = EventTarget<AppEvent>>§

Source

pub fn set_parent(&self, _name: impl Into<String>, parent: Weak<EventTarget<T>>)

Attach a parent target so events can bubble up.

Source

pub fn emit(&self, v: impl Into<Arc<T>> + Debug)

Examples found in repository?
examples/hello_layout.rs (line 31)
26    fn mount(&self, app: &EventTarget<AppEvent>) {
27        let app_for_quit = app.clone();
28        app.on_key(SubscriptionPriority::High, move |ev, key| {
29            if key.code == KeyCode::Char('q') {
30                ev.cancel();
31                app_for_quit.emit(AppEvent::Quit);
32            }
33        })
34        .forget();
35    }
More examples
Hide additional examples
examples/layout.rs (line 399)
394    fn mount(&self, app: &EventTarget<AppEvent>) {
395        let app_for_quit = app.clone();
396        app.on_key(SubscriptionPriority::High, move |ev, key| {
397            if key.code == KeyCode::Char('q') {
398                ev.cancel();
399                app_for_quit.emit(AppEvent::Quit);
400            }
401        })
402        .forget();
403    }
Source

pub fn emit_bubbling(&self, v: impl Into<Arc<T>> + Debug)

Emit and bubble up the parent chain.

Source

pub fn on( &self, priority: SubscriptionPriority, handler: impl Fn(Arc<Cancellable<T>>) + Send + Sync + 'static, ) -> SubscriptionHandle<T>

Source

pub fn as_stream(&self, p: SubscriptionPriority) -> EventStream<T>
where T: Send + Sync + 'static,

Source

pub fn on_key( &self, priority: SubscriptionPriority, handler: impl Fn(Arc<Cancellable<AppEvent>>, KeyEvent) + Send + Sync + 'static, ) -> SubscriptionHandle<AppEvent>

Subscribe only to AppEvent::KeyEvent payloads.

The handler receives the original event (so it can call Cancellable::cancel) plus the extracted KeyEvent.

Examples found in repository?
examples/hello_layout.rs (lines 28-33)
26    fn mount(&self, app: &EventTarget<AppEvent>) {
27        let app_for_quit = app.clone();
28        app.on_key(SubscriptionPriority::High, move |ev, key| {
29            if key.code == KeyCode::Char('q') {
30                ev.cancel();
31                app_for_quit.emit(AppEvent::Quit);
32            }
33        })
34        .forget();
35    }
More examples
Hide additional examples
examples/layout.rs (lines 396-401)
394    fn mount(&self, app: &EventTarget<AppEvent>) {
395        let app_for_quit = app.clone();
396        app.on_key(SubscriptionPriority::High, move |ev, key| {
397            if key.code == KeyCode::Char('q') {
398                ev.cancel();
399                app_for_quit.emit(AppEvent::Quit);
400            }
401        })
402        .forget();
403    }

Trait Implementations§

Source§

impl Deref for App

Source§

type Target = EventTarget<AppEvent>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl !Freeze for App

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl !UnwindSafe for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more