Skip to main content

codesearch/
output.rs

1//! Output control for quiet mode and JSON output
2//!
3//! Provides a global quiet mode flag to suppress non-essential output.
4
5use std::sync::atomic::{AtomicBool, Ordering};
6
7/// Global quiet mode flag
8static QUIET_MODE: AtomicBool = AtomicBool::new(false);
9
10/// Enable quiet mode (suppresses informational output)
11pub fn set_quiet(quiet: bool) {
12    QUIET_MODE.store(quiet, Ordering::SeqCst);
13}
14
15/// Check if quiet mode is enabled
16pub fn is_quiet() -> bool {
17    QUIET_MODE.load(Ordering::SeqCst)
18}
19
20/// Print a message only if not in quiet mode (non-macro version for better compatibility)
21/// Uses stderr to avoid corrupting stdout-based protocols (MCP, JSON output)
22pub fn print_info(args: std::fmt::Arguments<'_>) {
23    if !is_quiet() {
24        eprintln!("{}", args);
25    }
26}
27
28/// Print a warning to stderr only if not in quiet mode (non-macro version)
29#[allow(dead_code)] // Used by warn_print! macro
30pub fn print_warn(args: std::fmt::Arguments<'_>) {
31    if !is_quiet() {
32        eprintln!("{}", args);
33    }
34}
35
36/// Print a message only if not in quiet mode
37#[macro_export]
38macro_rules! info_print {
39    ($($arg:tt)*) => {
40        $crate::output::print_info(format_args!($($arg)*));
41    };
42}
43
44/// Print to stderr only if not in quiet mode (for warnings)
45#[macro_export]
46macro_rules! warn_print {
47    ($($arg:tt)*) => {
48        $crate::output::print_warn(format_args!($($arg)*));
49    };
50}