1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Auto-detection of whether `haz run` should emit ANSI colour
//! escape sequences.
//!
//! Two signals combine into the [`ColorChoice`] decision:
//!
//! - The two writable streams the run touches (`stdout`, `stderr`)
//! MUST both be terminals. A pipe / redirected file on either side
//! silences colours: writing escapes into log files or into
//! pagers that lack `-R` produces noise no consumer can read.
//! - The `NO_COLOR` environment variable
//! (<https://no-color.org/>) MUST be unset or empty. A non-empty
//! value (any non-empty value, per the convention) disables
//! colours unconditionally; accessibility tools, screen readers,
//! and colour-blind users rely on this knob.
//!
//! The detection is read-only and pure: it inspects file
//! descriptors and the process environment, never mutates either.
use IsTerminal;
/// Whether `haz run`'s presenter renders ANSI colour sequences.
///
/// The decision is binary: colour-render bytes go out, or they
/// don't. The mid-state ("auto") is resolved at construction time
/// by [`Self::detect`], which probes the live process environment
/// and the live stdout / stderr handles. Once a `ColorChoice` is
/// built it is a fixed runtime value the presenter consults on
/// every byte.
/// Read `NO_COLOR` per the spec at <https://no-color.org/>: any
/// non-empty value disables colours; absence or the empty string
/// leaves them on.