Skip to main content

harmont_cli/output/
mod.rs

1pub mod human;
2pub mod json;
3pub mod progress;
4pub mod spinner;
5
6/// How to render output. Determined at startup from CLI flags and TTY detection.
7#[derive(Debug, Clone)]
8pub enum OutputMode {
9    Human {
10        /// Whether ANSI colors are enabled.
11        color: bool,
12        /// Whether stdout is an interactive terminal (enables prompts, spinners).
13        interactive: bool,
14    },
15    Json,
16}
17
18impl OutputMode {
19    /// True when output should be JSON, suitable for scripting.
20    #[must_use]
21    pub const fn is_json(&self) -> bool {
22        matches!(self, Self::Json)
23    }
24
25    /// True when output is meant for a human reader (color/spinner-friendly).
26    #[must_use]
27    pub const fn is_human(&self) -> bool {
28        matches!(self, Self::Human { .. })
29    }
30
31    /// True when ANSI color codes should be emitted.
32    #[must_use]
33    pub const fn color_enabled(&self) -> bool {
34        matches!(self, Self::Human { color: true, .. })
35    }
36
37    /// True when stdout is interactive (allows prompts and spinners).
38    #[must_use]
39    pub const fn interactive(&self) -> bool {
40        matches!(
41            self,
42            Self::Human {
43                interactive: true,
44                ..
45            }
46        )
47    }
48
49    /// True when OSC 8 hyperlinks should be emitted (interactive + color).
50    #[must_use]
51    pub const fn use_hyperlinks(&self) -> bool {
52        matches!(
53            self,
54            Self::Human {
55                interactive: true,
56                color: true
57            }
58        )
59    }
60}