process_terminal/
utils.rs

1use std::process::{Child, Command, Stdio};
2
3/// Create a process that prints messages and sleeps.
4pub fn create_printing_process<'a, const N: usize>(
5    messages: [&str; N],
6    sleep: f64,
7    last: u64,
8) -> Child {
9    let mut args = format!("sleep {sleep}");
10
11    for _ in 0..(last as f64 / sleep / messages.len() as f64) as usize {
12        for message in messages {
13            args.push_str(&format!(" && echo {message} && sleep {sleep}"));
14        }
15    }
16
17    Command::new("sh")
18        .arg("-c")
19        .arg(args)
20        .stdout(Stdio::piped())
21        .stderr(Stdio::piped())
22        .spawn()
23        .unwrap()
24}