pub struct Crossterm<PainterT: Painter = IncrementalPainter> { /* private fields */ }Expand description
Implementations§
Source§impl<PainterT: Painter> Crossterm<PainterT>
impl<PainterT: Painter> Crossterm<PainterT>
Sourcepub fn new() -> Result<Self>
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.
Sourcepub fn run_event_loop(&mut self, layout: Layout) -> Result<()>
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!")))
}Sourcepub fn suspend(&mut self) -> Result<()>
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.
Sourcepub fn resume(&mut self) -> Result<()>
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.