pub struct Terminal { /* private fields */ }Expand description
What is known about one output stream: whether it is a terminal, whether to write colour, at what depth, and how wide the output is.
A terminal is decided once, for the stream the output goes to, before anything renders. The decision reads an environment lookup passed by the caller, so a test hands it a map and touches no process state.
§Colour
The Colour section of the crate docs states the order and the depth rules.
Implementations§
Source§impl Terminal
impl Terminal
Sourcepub fn detect(
stream: Stream,
mode: ColorMode,
options: DetectOptions,
env: &dyn Fn(&str) -> Option<String>,
) -> Self
Available on crate feature detect only.
pub fn detect( stream: Stream, mode: ColorMode, options: DetectOptions, env: &dyn Fn(&str) -> Option<String>, ) -> Self
detect only.What stream is, reading variables through env.
env returns a variable’s value, or None when it is unset. This
method asks the stream each time it is called, so two calls can differ
after a resize or a redirect.
Use from_probe to state the stream. Needs the
detect feature.
Sourcepub fn from_process(
stream: Stream,
mode: ColorMode,
options: DetectOptions,
) -> Self
Available on crate feature detect only.
pub fn from_process( stream: Stream, mode: ColorMode, options: DetectOptions, ) -> Self
detect only.detect reading the process environment. A value that
is not valid UTF-8 counts as set, with its invalid bytes replaced.
Needs the detect feature.
Sourcepub fn from_probe(
probe: Probe,
mode: ColorMode,
options: DetectOptions,
env: &dyn Fn(&str) -> Option<String>,
) -> Self
pub fn from_probe( probe: Probe, mode: ColorMode, options: DetectOptions, env: &dyn Fn(&str) -> Option<String>, ) -> Self
The decision for a stream that probe describes.
This is the whole decision as a function of its arguments. The other constructors call it after they probe a stream.
Sourcepub fn at_depth(self, depth: ColorDepth) -> Self
pub fn at_depth(self, depth: ColorDepth) -> Self
This terminal at depth, when colour is on.
The depth otherwise follows COLORTERM, TERM, and FORCE_COLOR.
A terminal with colour off stays off: the mode decides whether to write
colour, and this only decides how many colours.
Sourcepub fn is_attached(self) -> bool
pub fn is_attached(self) -> bool
Whether the stream is attached to a terminal, as opposed to a pipe or a file.
Sourcepub fn color(self) -> Option<ColorDepth>
pub fn color(self) -> Option<ColorDepth>
The colour depth, or None when no colour is written.