diff --git a/Cargo.toml b/Cargo.toml index b502112..98c1a52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "wipe" version = "2.0.0" edition = "2021" +description = "Wipe the content of your terminal." license = "MIT" repository = "https://github.com/ricoriedel/wipe" authors = ["Rico Riedel"] diff --git a/src/main.rs b/src/main.rs index 9c230f7..f970f18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,37 +33,51 @@ use std::time::Duration; about = env!("CARGO_PKG_DESCRIPTION"), )] struct Args { - #[clap(long, default_value_t = 1000)] + /// Set the duration of the animation [milliseconds] + #[clap(long, default_value_t = 2000)] duration: u64, + /// Set the frames per second #[clap(long, default_value_t = 60)] fps: u64, + /// Set the chars used to model the pattern #[clap(long, default_value = ".:+#")] chars: String, + /// Set the pattern #[clap(long, value_enum)] - char_pattern: Vec, + char_pattern: Option, + /// Revert the pattern [possible values: true, false] #[clap(long)] char_invert: Option, + /// Swap the x-axis and y-axis of the pattern #[clap(long)] char_swap: Option, + /// Set the count of units of the pattern [default: 1-4] #[clap(long)] char_units: Option, + /// Set the count of slices of the pattern [default: 1-4] #[clap(long)] char_slices: Option, + /// Set the colors used to fill the pattern #[clap(long, value_enum)] - colors: Vec, + colors: Option, + /// Set the fill pattern #[clap(long, value_enum)] - color_pattern: Vec, + color_pattern: Option, + /// Choose if the fill pattern should move [possible values: true, false] #[clap(long)] color_shift: Option, + /// Revert the fill pattern #[clap(long)] color_invert: Option, + /// Swap the x-axis and y-axis of the fill pattern #[clap(long)] color_swap: Option, + /// Set the count of slices of the fill pattern [default: 1-4] #[clap(long)] color_slices: Option, } -#[derive(ValueEnum, Clone)] +#[derive(ValueEnum, Copy, Clone)] enum PalletEnum { Red, Yellow, @@ -91,7 +105,7 @@ enum PalletEnum { Gray, } -#[derive(ValueEnum, Clone)] +#[derive(ValueEnum, Copy, Clone)] enum PatternEnum { Circle, Line, @@ -100,8 +114,8 @@ enum PatternEnum { } #[derive(derive_more::Constructor)] -struct PatternConfig<'a> { - patterns: &'a Vec, +struct PatternConfig { + patterns: Option, shift: Option, invert: Option, swap: Option, @@ -112,7 +126,7 @@ struct PatternConfig<'a> { impl Args { fn char_config(&self) -> PatternConfig { PatternConfig::new( - &self.char_pattern, + self.char_pattern, Some(true), self.char_invert, self.char_swap, @@ -123,7 +137,7 @@ impl Args { fn color_config(&self) -> PatternConfig { PatternConfig::new( - &self.color_pattern, + self.color_pattern, self.color_shift, self.color_invert, self.color_swap, @@ -133,7 +147,7 @@ impl Args { } fn pallet(&self, rand: &mut impl Rng) -> Vec { - match choose(&self.colors, rand) { + match choose(self.colors, rand) { PalletEnum::Red => vec![DarkRed, Red, White], PalletEnum::Yellow => vec![DarkYellow, Yellow, White], PalletEnum::Green => vec![DarkGreen, Green, White], @@ -169,7 +183,7 @@ impl Args { } } -impl<'a> PatternConfig<'a> { +impl PatternConfig { fn create_base(&self, rand: &mut impl Rng) -> Box { match choose(self.patterns, rand) { PatternEnum::Circle => Box::new(CircleFactory::default()), @@ -203,18 +217,14 @@ impl<'a> PatternConfig<'a> { } } -fn choose( - options: &Vec, - rand: &mut TRand, -) -> TValue { - if options.is_empty() { - TValue::value_variants() +fn choose(opt: Option, rand: &mut TRand) -> TValue { + match opt { + Some(value) => value.clone(), + None => TValue::value_variants() .iter() .choose(rand) .unwrap() - .clone() - } else { - options.iter().choose(rand).unwrap().clone() + .clone(), } }