Struct tuirealm::Application

source ·
pub struct Application<ComponentId, Msg, UserEvent>
where ComponentId: Eq + PartialEq + Clone + Hash, Msg: PartialEq, UserEvent: Eq + PartialEq + Clone + PartialOrd + Send + 'static,
{ /* private fields */ }
Expand description

The application defines a tui-realm application. It will handle events, subscriptions and the view too. It provides functions to interact with the view (mount, umount, query, etc), but also the main function: tick(). See tick

Implementations§

source§

impl<K, Msg, UserEvent> Application<K, Msg, UserEvent>
where K: Eq + PartialEq + Clone + Hash, Msg: PartialEq, UserEvent: Eq + PartialEq + Clone + PartialOrd + Send + 'static,

source

pub fn init(listener_cfg: EventListenerCfg<UserEvent>) -> Self

Initialize a new Application. The event listener is immediately created and started.

source

pub fn restart_listener( &mut self, listener_cfg: EventListenerCfg<UserEvent> ) -> ApplicationResult<()>

Restart listener in case the previous listener has died or if you want to start a new one with a new configuration.

The listener has died if you received a ApplicationError::Listener(ListenerError::ListenerDied))

source

pub fn lock_ports(&mut self) -> ApplicationResult<()>

Lock ports. As long as Ports are locked, ports won’t be polled. Locking ports will also prevent Tick events from being generated.

source

pub fn unlock_ports(&mut self) -> ApplicationResult<()>

Unlock Ports. Once called, the event listener will resume polling Ports.

source

pub fn tick(&mut self, strategy: PollStrategy) -> ApplicationResult<Vec<Msg>>

The tick method makes the application to run once. The workflow of the tick method is the following one:

  1. The event listener is fetched according to the provided PollStrategy
  2. All the received events are sent to the current active component
  3. All the received events are forwarded to the subscribed components which satisfy the received events and conditions.
  4. Returns messages to process

As soon as function returns, you should call the view() method.

You can also call view from the update() if you need it

source

pub fn add_injector(&mut self, injector: Box<dyn Injector<K>>)

Add an injector to the view

source

pub fn mount( &mut self, id: K, component: Box<dyn Component<Msg, UserEvent>>, subs: Vec<Sub<K, UserEvent>> ) -> ApplicationResult<()>

Mount component to view and associate subscriptions for it. Returns error if component is already mounted NOTE: if subs vector contains duplicated, these will be discarded

source

pub fn umount(&mut self, id: &K) -> ApplicationResult<()>

Umount component associated to id and remove ALL its SUBSCRIPTIONS. Returns Error if the component doesn’t exist

source

pub fn remount( &mut self, id: K, component: Box<dyn Component<Msg, UserEvent>>, subs: Vec<Sub<K, UserEvent>> ) -> ApplicationResult<()>

Remount provided component. Returns Err if failed to mount. It ignores whether the component already exists or not. If component had focus, focus is preserved

source

pub fn umount_all(&mut self)

Umount all components in the view and removed all associated subscriptions

source

pub fn mounted(&self, id: &K) -> bool

Returns whether component id is mounted

source

pub fn view(&mut self, id: &K, f: &mut Frame<'_>, area: Rect)

Render component called id

source

pub fn query( &self, id: &K, query: Attribute ) -> ApplicationResult<Option<AttrValue>>

Query view component for a certain AttrValue Returns error if the component doesn’t exist Returns None if the attribute doesn’t exist.

source

pub fn attr( &mut self, id: &K, attr: Attribute, value: AttrValue ) -> ApplicationResult<()>

Set attribute for component id Returns error if the component doesn’t exist

source

pub fn state(&self, id: &K) -> ApplicationResult<State>

Get state for component id. Returns Err if component doesn’t exist

source

pub fn active(&mut self, id: &K) -> ApplicationResult<()>

Shorthand for attr(id, Attribute::Focus(AttrValue::Flag(true))). It also sets the component as the current one having focus. Previous active component, if any, GETS PUSHED to the STACK Returns error: if component doesn’t exist. Use mounted() to check if component exists

NOTE: users should always use this function to give focus to components.

source

pub fn blur(&mut self) -> ApplicationResult<()>

Blur selected element AND DON’T PUSH CURRENT ACTIVE ELEMENT INTO THE STACK Shorthand for attr(id, Attribute::Focus(AttrValue::Flag(false))). It also unset the current focus and give it to the first element in stack. Returns error: if no component has focus

NOTE: users should always use this function to remove focus to components.

source

pub fn focus(&self) -> Option<&K>

Get a reference to the id of the current active component in the view

source

pub fn subscribe( &mut self, id: &K, sub: Sub<K, UserEvent> ) -> ApplicationResult<()>

Subscribe component to a certain event. Returns Error if the component doesn’t exist or if the component is already subscribed to this event

source

pub fn unsubscribe( &mut self, id: &K, ev: SubEventClause<UserEvent> ) -> ApplicationResult<()>

Unsubscribe a component from a certain event. Returns error if the component doesn’t exist or if the component is not subscribed to this event

source

pub fn lock_subs(&mut self)

Lock subscriptions. As long as the subscriptions are locked, events won’t be propagated to subscriptions.

source

pub fn unlock_subs(&mut self)

Unlock subscriptions. Application will now resume propagating events to subscriptions.

Auto Trait Implementations§

§

impl<ComponentId, Msg, UserEvent> !RefUnwindSafe for Application<ComponentId, Msg, UserEvent>

§

impl<ComponentId, Msg, UserEvent> !Send for Application<ComponentId, Msg, UserEvent>

§

impl<ComponentId, Msg, UserEvent> !Sync for Application<ComponentId, Msg, UserEvent>

§

impl<ComponentId, Msg, UserEvent> Unpin for Application<ComponentId, Msg, UserEvent>
where ComponentId: Unpin, UserEvent: Unpin,

§

impl<ComponentId, Msg, UserEvent> !UnwindSafe for Application<ComponentId, Msg, UserEvent>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.