workbloom/
output.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2use std::process::{Command, Stdio};
3
4static MACHINE_OUTPUT: AtomicBool = AtomicBool::new(false);
5
6pub fn set_machine_output(enabled: bool) {
7    MACHINE_OUTPUT.store(enabled, Ordering::Relaxed);
8}
9
10pub fn is_machine_output() -> bool {
11    MACHINE_OUTPUT.load(Ordering::Relaxed)
12}
13
14pub fn configure_command_for_machine_output(command: &mut Command) -> &mut Command {
15    if is_machine_output() {
16        command.stdout(Stdio::null());
17        command.stderr(Stdio::inherit());
18    }
19    command
20}
21
22#[macro_export]
23macro_rules! outln {
24    () => {
25        if $crate::output::is_machine_output() {
26            eprintln!();
27        } else {
28            println!();
29        }
30    };
31    ($($arg:tt)*) => {
32        if $crate::output::is_machine_output() {
33            eprintln!($($arg)*);
34        } else {
35            println!($($arg)*);
36        }
37    };
38}