Struct termit::Termit

source ·
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>

source

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.

source

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.

source

pub fn true_color(self, true_color: bool) -> Self

Set this to true if you know the terminal supports it for slightly less IO.

source

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.

source

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.

source

pub fn refresh_time_sender(&self) -> Sender<Duration>

Allows you to update the refresh interval

source

pub fn screen_mut(&mut self) -> &mut Screen

The screen buffer. Use this if you need to modify the screen directly

source

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

source

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

source

pub fn include_input( self, additional: impl Stream<Item = Result<Event<A>>> + 'a ) -> Self

source

pub fn include_app_input(self, additional: impl Stream<Item = A> + 'a) -> Self

source

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.

source

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.

source

pub fn enter_raw_mode(self) -> Result<Self>

Most useful for TUIs, gives access to unfiltered/unbuffered input

source

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.

source

pub fn capture_mouse(self, capture: bool) -> Result<Self>

Set this to true to receive mouse input events

source

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.

source

pub fn show_cursor(self, show: bool) -> Result<Self>

Show the cursor? Probably not in a TUI…

source

pub fn handle_focus_events(self, handle: bool) -> Result<Self>

Handle focus in and out? Can be handy.

source§

impl<'a> Termit<'a, NoAppEvent>

source

pub fn with_app_event_type<A: AppEvent>(self) -> Termit<'a, A>

Trait Implementations§

source§

impl<'a, C, I, O, A: AppEvent> From<Terminal<C, I, O>> for Termit<'a, A>where C: Control + 'a, I: AsyncRead + 'a, O: Write + 'a,

source§

fn from(terminal: Terminal<C, I, O>) -> Self

Converts to this type from the input type.
source§

impl<A: AppEvent> TerminalCommander for Termit<'_, A>

source§

fn send<T: TerminalRequest>(&mut self, request: T) -> Result<()>

Auto Trait Implementations§

§

impl<'a, A> !RefUnwindSafe for Termit<'a, A>

§

impl<'a, A> !Send for Termit<'a, A>

§

impl<'a, A> !Sync for Termit<'a, A>

§

impl<'a, A> Unpin for Termit<'a, A>

§

impl<'a, A> !UnwindSafe for Termit<'a, A>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.