Skip to main content

harmont_cli/output/
mod.rs

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