process_terminal/
functions.rs

1use {
2    crate::{ProcessSettings, TERMINAL},
3    anyhow::Result,
4    std::process::Child,
5};
6
7#[macro_export]
8/// Print a message in the Main section of the teminal.
9macro_rules! tprintln {
10    ($($arg:tt)*) => {
11        if cfg!(debug_assertions) {
12            process_terminal::TERMINAL.add_message(format!($($arg)*));
13        }
14    };
15}
16
17/// Add a process to the terminal.
18pub fn add_process(name: &str, child: Child, settings: ProcessSettings) -> Result<()> {
19    TERMINAL.add_process(name, child, settings)
20}
21
22/// Blocking function that block the current thread, searching for a substring in a specific process output, returning the whole output message.
23pub fn block_search_message<S, P>(process: P, submsg: S) -> Result<String>
24where
25    S: ToString,
26    P: ToString,
27{
28    TERMINAL.block_search_message(process, submsg)
29}
30
31pub fn end_terminal() {
32    TERMINAL.kill();
33}
34
35pub fn with_exit_callback<F: Fn() + Send + Sync + 'static>(closure: F) {
36    TERMINAL.with_exit_callback(closure);
37}