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§
Sourcefn set_salsa_ctx(&mut self, app_ctx: SalsaAppContext<Event, Error>)
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.
Sourcefn salsa_ctx(&self) -> &SalsaAppContext<Event, Error>
fn salsa_ctx(&self) -> &SalsaAppContext<Event, Error>
Access the AppContext previously set.
Provided Methods§
Sourcefn last_render(&self) -> Duration
fn last_render(&self) -> Duration
Get the last render timing.
Sourcefn last_event(&self) -> Duration
fn last_event(&self) -> Duration
Get the last event-handling timing.
Sourcefn set_screen_cursor(&self, cursor: Option<(u16, u16)>)
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.
Sourcefn add_timer(&self, t: TimerDef) -> TimerHandle
fn add_timer(&self, t: TimerDef) -> TimerHandle
Add a timer.
Panic
Panics if no timer support is configured.
Sourcefn remove_timer(&self, tag: TimerHandle)
fn remove_timer(&self, tag: TimerHandle)
Remove a timer.
Panic
Panics if no timer support is configured.
Sourcefn replace_timer(&self, h: Option<TimerHandle>, t: TimerDef) -> TimerHandle
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.
Sourcefn spawn_ext(
&self,
task: impl FnOnce(Cancel, &Sender<Result<Control<Event>, Error>>) -> Result<Control<Event>, Error> + Send + 'static,
) -> Result<(Cancel, Liveness), SendError<()>>
fn spawn_ext( &self, task: impl FnOnce(Cancel, &Sender<Result<Control<Event>, Error>>) -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(Cancel, Liveness), SendError<()>>
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.
Sourcefn spawn(
&self,
task: impl FnOnce() -> Result<Control<Event>, Error> + Send + 'static,
) -> Result<(), SendError<()>>
fn spawn( &self, task: impl FnOnce() -> Result<Control<Event>, Error> + Send + 'static, ) -> Result<(), SendError<()>>
Add a background worker task.
let cancel = ctx.spawn(|| {
// ...
Ok(Control::Continue)
});Panic
Panics if no worker-thread support is configured.
Sourcefn queue_event(&self, event: Event)
fn queue_event(&self, event: Event)
Queue an application event.
Sourcefn take_focus(&self) -> Option<Focus>
fn take_focus(&self) -> Option<Focus>
Take the Focus back from the Context.
Sourcefn clear_focus(&self)
fn clear_focus(&self)
Clear the Focus.
Sourcefn focus<'a>(&'a self) -> Ref<'a, Focus>
fn focus<'a>(&'a self) -> Ref<'a, Focus>
Access the Focus.
Panic
Panics if no focus has been set.
Sourcefn focus_mut<'a>(&'a mut self) -> RefMut<'a, Focus>
fn focus_mut<'a>(&'a mut self) -> RefMut<'a, Focus>
Mutably access the focus-field.
Panic
Panics if no focus has been set.
Sourcefn handle_focus<E>(&mut self, event: &E)
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.
Sourcefn clear_terminal(&mut self)
fn clear_terminal(&mut self)
Clear the terminal and do a full redraw before the next draw.
Sourcefn insert_before(
&mut self,
height: u16,
draw_fn: impl FnOnce(&mut Buffer) + 'static,
)
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.