SalsaContext

Trait SalsaContext 

Source
pub trait SalsaContext<Event, Error>
where Event: 'static, Error: 'static,
{
Show 23 methods // Required methods fn set_salsa_ctx(&mut self, app_ctx: SalsaAppContext<Event, Error>); fn salsa_ctx(&self) -> &SalsaAppContext<Event, Error>; // Provided methods fn count(&self) -> usize { ... } fn last_render(&self) -> Duration { ... } fn last_event(&self) -> Duration { ... } fn set_screen_cursor(&self, cursor: Option<(u16, u16)>) { ... } fn add_timer(&self, t: TimerDef) -> TimerHandle { ... } fn remove_timer(&self, tag: TimerHandle) { ... } fn replace_timer(&self, h: Option<TimerHandle>, t: TimerDef) -> TimerHandle { ... } fn spawn_ext( &self, task: impl FnOnce(Cancel, &Sender<Result<Control<Event>, Error>>) -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(Cancel, Liveness), SendError<()>> where Event: 'static + Send, Error: 'static + Send { ... } fn spawn( &self, task: impl FnOnce() -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(), SendError<()>> where Event: 'static + Send, Error: 'static + Send { ... } fn queue_event(&self, event: Event) { ... } fn queue(&self, ctrl: impl Into<Control<Event>>) { ... } fn queue_err(&self, err: Error) { ... } fn set_focus(&self, focus: Focus) { ... } fn take_focus(&self) -> Option<Focus> { ... } fn clear_focus(&self) { ... } fn focus<'a>(&'a self) -> Ref<'a, Focus> { ... } fn focus_mut<'a>(&'a mut self) -> RefMut<'a, Focus> { ... } fn handle_focus<E>(&mut self, event: &E) where Focus: HandleEvent<E, Regular, Outcome> { ... } fn terminal(&mut self) -> Rc<RefCell<dyn Terminal<Error>>> { ... } fn clear_terminal(&mut self) { ... } fn insert_before( &mut self, height: u16, draw_fn: impl FnOnce(&mut Buffer) + 'static, ) { ... }
}
Expand description

This trait gives access to all facilities built into rat-salsa.

Your global state struct has to implement this trait. This allows rat-salsa to add its facilities to it.

run_tui sets it during initialization, it will be up and running by the time init() is called.

Required Methods§

Source

fn set_salsa_ctx(&mut self, app_ctx: SalsaAppContext<Event, Error>)

The AppContext struct holds all the data for the rat-salsa functionality. run_tui calls this to set the initialized struct.

Source

fn salsa_ctx(&self) -> &SalsaAppContext<Event, Error>

Access the AppContext previously set.

Provided Methods§

Source

fn count(&self) -> usize

Get the current frame/render-count.

Source

fn last_render(&self) -> Duration

Get the last render timing.

Source

fn last_event(&self) -> Duration

Get the last event-handling timing.

Source

fn set_screen_cursor(&self, cursor: Option<(u16, u16)>)

Set the cursor, if the given value is something, hides it otherwise.

This should only be set during rendering.

Source

fn add_timer(&self, t: TimerDef) -> TimerHandle

Add a timer.

Panic

Panics if no timer support is configured.

Source

fn remove_timer(&self, tag: TimerHandle)

Remove a timer.

Panic

Panics if no timer support is configured.

Source

fn replace_timer(&self, h: Option<TimerHandle>, t: TimerDef) -> TimerHandle

Replace a timer. Remove the old timer and create a new one. If the old timer no longer exists it just creates the new one.

Panic

Panics if no timer support is configured.

Source

fn spawn_ext( &self, task: impl FnOnce(Cancel, &Sender<Result<Control<Event>, Error>>) -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(Cancel, Liveness), SendError<()>>
where Event: 'static + Send, Error: 'static + Send,

Add a background worker task.

let cancel = ctx.spawn(|cancel, send| {
    // ... do stuff
    if cancel.is_canceled() {
        return; // return early
    }
    Ok(Control::Continue)
});
  • Cancel token

The cancel token can be used by the application to signal an early cancellation of a long-running task. This cancellation is cooperative, the background task must regularly check for cancellation and quit if needed.

  • Liveness token

This token is set whenever the given task has finished, be it regularly or by panicking.

Panic

Panics if no worker-thread support is configured.

Source

fn spawn( &self, task: impl FnOnce() -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(), SendError<()>>
where Event: 'static + Send, Error: 'static + Send,

Add a background worker task.

let cancel = ctx.spawn(|| {
    // ...
    Ok(Control::Continue)
});

Panic

Panics if no worker-thread support is configured.

Source

fn queue_event(&self, event: Event)

Queue an application event.

Source

fn queue(&self, ctrl: impl Into<Control<Event>>)

Queue additional results.

Source

fn queue_err(&self, err: Error)

Queue an error.

Source

fn set_focus(&self, focus: Focus)

Set the Focus.

Source

fn take_focus(&self) -> Option<Focus>

Take the Focus back from the Context.

Source

fn clear_focus(&self)

Clear the Focus.

Source

fn focus<'a>(&'a self) -> Ref<'a, Focus>

Access the Focus.

Panic

Panics if no focus has been set.

Source

fn focus_mut<'a>(&'a mut self) -> RefMut<'a, Focus>

Mutably access the focus-field.

Panic

Panics if no focus has been set.

Source

fn handle_focus<E>(&mut self, event: &E)

Handle the focus-event and automatically queue the result.

Panic

Panics if no focus has been set.

Source

fn terminal(&mut self) -> Rc<RefCell<dyn Terminal<Error>>>

Access the terminal.

Source

fn clear_terminal(&mut self)

Clear the terminal and do a full redraw before the next draw.

Source

fn insert_before( &mut self, height: u16, draw_fn: impl FnOnce(&mut Buffer) + 'static, )

Call insert_before() before the next draw.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Event, Error> SalsaContext<Event, Error> for SalsaAppContext<Event, Error>
where Event: 'static, Error: 'static,