Crossterm

Struct Crossterm 

Source
pub struct Crossterm<PainterT: Painter = IncrementalPainter> { /* private fields */ }
Expand description

A terminal backend implementation for Zi using crossterm

fn main() -> zi_term::Result<()> {
    zi_term::incremental()?
        .run_event_loop(Text::with(TextProperties::new().content("Hello, world!")))
}

Implementations§

Source§

impl<PainterT: Painter> Crossterm<PainterT>

Source

pub fn new() -> Result<Self>

Create a new backend instance.

This method initialises the underlying tty device, enables raw mode, hides the cursor and enters alternative screen mode. Additionally, an async event stream with input events from stdin is started.

Source

pub fn run_event_loop(&mut self, layout: Layout) -> Result<()>

Starts the event loop. This is the main entry point of a Zi application. It draws and presents the components to the backend, handles user input and delivers messages to components. This method returns either when prompted using the exit method on ComponentLink or on error.

fn main() -> zi_term::Result<()> {
    zi_term::incremental()?
        .run_event_loop(Text::with(TextProperties::new().content("Hello, world!")))
}
Source

pub fn suspend(&mut self) -> Result<()>

Suspends the event stream.

This is used when running something that needs exclusive access to the underlying terminal (i.e. to stdin and stdout). For example spawning an external editor to collect or display text. The resume function is called upon returning to the application.

Source

pub fn resume(&mut self) -> Result<()>

Recreates the event stream and reinitialises the underlying terminal.

This function is used to return execution to the application after running something that needs exclusive access to the underlying backend. It will only be called after a call to suspend.

In addition to restarting the event stream, this function should perform any other required initialisation of the backend. For ANSI terminals, this typically hides the cursor and saves the current screen content (i.e. “alternative screen mode”) in order to restore the previous terminal content on exit.

Trait Implementations§

Source§

impl<PainterT: Painter> Drop for Crossterm<PainterT>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<PainterT> Freeze for Crossterm<PainterT>
where PainterT: Freeze,

§

impl<PainterT = IncrementalPainter> !RefUnwindSafe for Crossterm<PainterT>

§

impl<PainterT> Send for Crossterm<PainterT>
where PainterT: Send,

§

impl<PainterT = IncrementalPainter> !Sync for Crossterm<PainterT>

§

impl<PainterT> Unpin for Crossterm<PainterT>
where PainterT: Unpin,

§

impl<PainterT = IncrementalPainter> !UnwindSafe for Crossterm<PainterT>

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

Source§

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

Source§

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.