use chromaterm::ColorSupport;
use chromaterm::prelude::*;
use clap::{Parser, ValueEnum};
#[derive(Parser)]
struct Cli {
#[arg(long, short, default_value = "auto")]
color: ColorChoice,
}
#[derive(Clone, ValueEnum)]
enum ColorChoice {
Auto,
Always,
EightBit,
Ansi,
Never,
}
impl ColorChoice {
fn setup(&self) {
let support_level = match self {
Self::Auto => {
chromaterm::config::use_default_color_support();
return;
}
Self::Always => ColorSupport::True,
Self::EightBit => ColorSupport::EightBit,
Self::Ansi => ColorSupport::Simple,
Self::Never => ColorSupport::None,
};
chromaterm::config::use_color_support(support_level);
}
}
fn main() {
let cli = Cli::parse();
cli.color.setup();
chromaterm::config::convert_to_supported(true);
println!("Let's print a gradient!");
(0..=255).step_by(4).for_each(|c| {
let r = 255;
let g = c / 2;
let b = 255 - c;
print!("{}", "-".on_rgb(r, g, b));
});
println!();
println!("Run this example again and pass `-h` to see how to change color support.")
}