use std::sync::Mutex;
use super::state::env_text_mode;
#[derive(Debug, PartialEq, Clone, Copy)]
#[non_exhaustive]
pub enum ProgressOutput {
UI,
Text,
Quiet,
}
static OUTPUT: Mutex<ProgressOutput> = Mutex::new(ProgressOutput::UI);
pub fn set_output(output: ProgressOutput) {
*OUTPUT.lock().unwrap() = output;
}
#[must_use]
pub fn output() -> ProgressOutput {
let stored = *OUTPUT.lock().unwrap();
if stored == ProgressOutput::Quiet {
return ProgressOutput::Quiet;
}
if env_text_mode() {
return ProgressOutput::Text;
}
stored
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_output_get_set() {
let original = output();
set_output(ProgressOutput::Text);
assert_eq!(output(), ProgressOutput::Text);
set_output(ProgressOutput::Quiet);
assert_eq!(output(), ProgressOutput::Quiet);
set_output(ProgressOutput::UI);
assert_eq!(output(), ProgressOutput::UI);
set_output(original);
}
}