pub fn run_app<W: Widget, E: Error, FW: FnMut(Event) -> Result<Option<W>, E>>(
func: FW,
) -> Result<()>Expand description
Runs a tuviv app
This sets up all the terminal
-
It takes a function (or closure) that:
- Takes a
crossterm::event::Eventas input - Returns:
Ok(Some(W))on sucess - thus rendering a widgetOk(None)for a graceful closing of the applicationErr(e)for an error - which is printed to the stderr by tuviv
- Takes a
-
The generics are:
W: the widget this returnsE: the error type. UseInfallibleifFWdoesn’t failFW: the funtion
-
A simple example function would be:
run_app(|event| {
// Allows for the app to be quit
if let Event::Key(key) = event {
if let KeyCode::Char('q') = key.code {
return Ok(None);
}
}
// Create a widget
let w = Paragraph::label("Press q to to quit").centered();
// This app never fails, so we return Infallible (`!`)
Ok::<_, Infallible>(w)
})