pub fn exec_command<M>(
command: impl ExecCommand + 'static,
done: impl FnOnce(Result<()>) -> M + Send + 'static,
) -> Cmd<M>Expand description
Runs command in the terminal as exec runs a Command, then
sends done(result): Bubble Tea’s tea.Exec, for anything that
needs the terminal to itself.
use petitcarnets as tea;
struct Task;
impl tea::ExecCommand for Task {
fn run(&mut self) -> std::io::Result<()> {
Ok(())
}
}
struct App(Option<bool>);
impl tea::Model for App {
type Msg = std::io::Result<()>;
fn update(&mut self, msg: tea::Msg<Self::Msg>) -> tea::Cmd<Self::Msg> {
match msg {
tea::Msg::KeyPress(k) if k == "x" => tea::exec_command(Task, |r| r),
tea::Msg::App(result) => {
self.0 = Some(result.is_ok());
tea::quit()
}
_ => tea::Cmd::none(),
}
}
fn view(&self) -> tea::View {
"x: run".into()
}
}
let mut test = tea::testing::TestProgram::new(App(None), 20, 2);
test.type_text("x");
assert_eq!(test.final_model().0, Some(true));