pub struct Termit<'a, A: AppEvent> { /* private fields */ }
Expand description
The terminal app facilitator
Use crate::Terminal
to set it up and initialize it.
The simplest approach is to call step()
- that takes care of processing input.
If you’re in a place without async, you can still make it turn
calling update
and dealing with input differently, or block on the step()
.
Finally, Termit exposes input()
and input_squashed()
you can use with update()
to do some inspection/transformation of the input.
Implementations§
source§impl<'a, A: AppEvent> Termit<'a, A>
impl<'a, A: AppEvent> Termit<'a, A>
sourcepub fn new(
control: impl Control + 'a,
inp: impl AsyncRead + 'a,
out: impl Write + 'a
) -> Self
pub fn new( control: impl Control + 'a, inp: impl AsyncRead + 'a, out: impl Write + 'a ) -> Self
Constructor called by crate::Terminal::into_termit()
You probably don’t want to call this unless you’re into something special.
sourcepub fn draw_over(self, draw_over: bool) -> Self
pub fn draw_over(self, draw_over: bool) -> Self
Set this to true to draw over the previous screen content. This would be useful for instance if you’re doing in-terminal clock or some fancy prompt But most apps probably want their own space, which is the default. Non-ttys should drawing over as there’s nothing to draw over.
sourcepub fn true_color(self, true_color: bool) -> Self
pub fn true_color(self, true_color: bool) -> Self
Set this to true if you know the terminal supports it for slightly less IO.
sourcepub fn run_without_input(self, run: bool) -> Self
pub fn run_without_input(self, run: bool) -> Self
By default, termit generates an unexpectedd EOF when the input is closed. Set this to true to make it continue running even without input. This is useful for apps that do not take input.
sourcepub async fn step<M>(
&mut self,
model: &mut M,
ui: &mut impl Widget<M, A>
) -> Result<usize>
pub async fn step<M>( &mut self, model: &mut M, ui: &mut impl Widget<M, A> ) -> Result<usize>
Step one cycle through the event loop, update the model and render the UI.
Typically, you’ll be calling this in a loop where you’ll also be processing quick application logic (commands).
It returns the number of input events processed.
sourcepub fn refresh_time_sender(&self) -> Sender<Duration>
pub fn refresh_time_sender(&self) -> Sender<Duration>
Allows you to update the refresh interval
sourcepub fn screen_mut(&mut self) -> &mut Screen
pub fn screen_mut(&mut self) -> &mut Screen
The screen buffer. Use this if you need to modify the screen directly
sourcepub fn input(&'a mut self) -> impl Stream<Item = Result<Event<A>>> + 'a
pub fn input(&'a mut self) -> impl Stream<Item = Result<Event<A>>> + 'a
The input event stream. Use this if you need to process events outside of UI
pub fn replace_input<A2: AppEvent, F>(self, replacement: F) -> Termit<'a, A2>where F: Fn(Pin<Box<dyn Stream<Item = Result<Event<A>>> + Unpin + 'a>>) -> Pin<Box<dyn Stream<Item = Result<Event<A2>>> + Unpin + 'a>>,
pub fn include_input( self, additional: impl Stream<Item = Result<Event<A>>> + 'a ) -> Self
pub fn include_app_input(self, additional: impl Stream<Item = A> + 'a) -> Self
sourcepub fn print(&mut self, scope: Option<Window>) -> Result<()>
pub fn print(&mut self, scope: Option<Window>) -> Result<()>
Print UI updates
You can print only from a given scope, or pass None for whole screen
This is called by the step
method so you probably won’t call this directly
unless you need to handle output differently
than the step
method.
sourcepub fn update<M>(
&mut self,
model: &mut M,
input: Event<A>,
root: &mut impl Widget<M, A>
)
pub fn update<M>( &mut self, model: &mut M, input: Event<A>, root: &mut impl Widget<M, A> )
Handle input, update the model and widgets
This is called by the step
method so you probably won’t call this directly
unless you need to pre-process the events or do something differently
than the step
method.
sourcepub fn enter_raw_mode(self) -> Result<Self>
pub fn enter_raw_mode(self) -> Result<Self>
Most useful for TUIs, gives access to unfiltered/unbuffered input
sourcepub fn use_alternate_screen(self, alt_screen: bool) -> Result<Self>
pub fn use_alternate_screen(self, alt_screen: bool) -> Result<Self>
Set this to true to draw the UI on an alternate screen. This helps not to overwrite previous console output.
sourcepub fn capture_mouse(self, capture: bool) -> Result<Self>
pub fn capture_mouse(self, capture: bool) -> Result<Self>
Set this to true to receive mouse input events
sourcepub fn enable_line_wrap(self, enable: bool) -> Result<Self>
pub fn enable_line_wrap(self, enable: bool) -> Result<Self>
Wrap around the end? Should not be useful in a well made TUI. You can set it to false.
sourcepub fn show_cursor(self, show: bool) -> Result<Self>
pub fn show_cursor(self, show: bool) -> Result<Self>
Show the cursor? Probably not in a TUI…
sourcepub fn handle_focus_events(self, handle: bool) -> Result<Self>
pub fn handle_focus_events(self, handle: bool) -> Result<Self>
Handle focus in and out? Can be handy.