]>
git.proxmox.com Git - rustc.git/blob - vendor/clap_builder/src/util/color.rs
1 use crate::builder
::PossibleValue
;
2 use crate::derive
::ValueEnum
;
4 /// Represents the color preferences for program output
5 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
7 /// Enables colored output only when the output is going to a terminal or TTY.
9 /// **NOTE:** This is the default behavior of `clap`.
11 /// # Platform Specific
13 /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms).
18 /// # #[cfg(feature = "color")] {
19 /// # use clap_builder as clap;
20 /// # use clap::{Command, ColorChoice};
21 /// Command::new("myprog")
22 /// .color(ColorChoice::Auto)
28 /// Enables colored output regardless of whether or not the output is going to a terminal/TTY.
30 /// # Platform Specific
32 /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms).
37 /// # #[cfg(feature = "color")] {
38 /// # use clap_builder as clap;
39 /// # use clap::{Command, ColorChoice};
40 /// Command::new("myprog")
41 /// .color(ColorChoice::Always)
47 /// Disables colored output no matter if the output is going to a terminal/TTY, or not.
49 /// # Platform Specific
51 /// This setting only applies to Unix, Linux, and macOS (i.e. non-Windows platforms)
56 /// # #[cfg(feature = "color")] {
57 /// # use clap_builder as clap;
58 /// # use clap::{Command, ColorChoice};
59 /// Command::new("myprog")
60 /// .color(ColorChoice::Never)
67 impl Default
for ColorChoice
{
68 fn default() -> Self {
73 impl std
::fmt
::Display
for ColorChoice
{
74 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
75 self.to_possible_value()
76 .expect("no values are skipped")
82 impl std
::str::FromStr
for ColorChoice
{
85 fn from_str(s
: &str) -> Result
<Self, Self::Err
> {
86 for variant
in Self::value_variants() {
87 if variant
.to_possible_value().unwrap().matches(s
, false) {
91 Err(format
!("invalid variant: {s}"))
95 impl ValueEnum
for ColorChoice
{
96 fn value_variants
<'a
>() -> &'a
[Self] {
97 &[Self::Auto
, Self::Always
, Self::Never
]
100 fn to_possible_value(&self) -> Option
<PossibleValue
> {
103 PossibleValue
::new("auto").help("Use colored output if writing to a terminal/TTY")
105 Self::Always
=> PossibleValue
::new("always").help("Always use colored output"),
106 Self::Never
=> PossibleValue
::new("never").help("Never use colored output"),