diff --git a/Cargo.toml b/Cargo.toml index 150f11d..035eaf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,6 @@ description = "Wipe your terminal with a random animation." repository = "https://github.com/ricoriedel/wipe" [dependencies] +clap = { version = "3.1", features = ["derive"]} +crossterm = "0.23" +rand = "0.8" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..f06f20d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,20 @@ -fn main() { - println!("Hello, world!"); +use clap::Parser; +use rand::rngs::OsRng; +use crate::pallet::{choose_pallet, create_pallet, PalletEnum}; + +mod pallet; + +#[derive(Parser)] +#[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")] +struct Args { + #[clap(short, long, help = "Add color pallet", arg_enum)] + pallet: Vec, +} + +fn main() { + let args = Args::parse(); + let rng = &mut OsRng::default(); + + let pallet_key = choose_pallet(args.pallet, rng); + let pallet = create_pallet(pallet_key); } diff --git a/src/pallet.rs b/src/pallet.rs new file mode 100644 index 0000000..b7b10e3 --- /dev/null +++ b/src/pallet.rs @@ -0,0 +1,93 @@ +use crossterm::style::Color; +use crossterm::style::Color::*; +use rand::prelude::IteratorRandom; +use rand::Rng; +use clap::ArgEnum; + +pub struct Pallet { + values: Vec +} + +impl Pallet { + pub fn new(values: Vec) -> Self { + Self { values } + } + + pub fn red() -> Pallet { + Pallet::new(vec![Yellow, DarkYellow, Red]) + } + + pub fn red_light() -> Pallet { + Pallet::new(vec![White, Yellow, Red]) + } + + pub fn green() -> Pallet { + Pallet::new(vec![Cyan, DarkGreen, Green]) + } + + pub fn green_light() -> Pallet { + Pallet::new(vec![White, Cyan, Green]) + } + + pub fn blue() -> Pallet { + Pallet::new(vec![Magenta, DarkBlue, Blue]) + } + + pub fn blue_light() -> Pallet { + Pallet::new(vec![White, Magenta, Blue]) + } + + pub fn white() -> Pallet { + Pallet::new(vec![Black, Grey, White]) + } + + pub fn rainbow() -> Pallet { + Pallet::new(vec![Magenta, Blue, Green, Yellow, Red]) + } + + pub fn sample(&self, fill: f32) -> Color { + let pos = self.values.len() as f32 * fill; + let index = pos as usize; + + self.values[index] + } +} + +#[derive(Copy, Clone, ArgEnum)] +pub enum PalletEnum { + Red, + RedLight, + Green, + GreenLight, + Blue, + BlueLight, + White, + Rainbow +} + +pub fn choose_pallet(mut options: Vec, rng: &mut impl Rng) -> PalletEnum { + if options.is_empty() { + options.push(PalletEnum::Red); + options.push(PalletEnum::RedLight); + options.push(PalletEnum::Green); + options.push(PalletEnum::GreenLight); + options.push(PalletEnum::Blue); + options.push(PalletEnum::BlueLight); + options.push(PalletEnum::White); + options.push(PalletEnum::Rainbow); + } + options.into_iter().choose(rng).unwrap() +} + +pub fn create_pallet(pallet: PalletEnum) -> Pallet { + match pallet { + PalletEnum::Red => Pallet::red(), + PalletEnum::RedLight => Pallet::red_light(), + PalletEnum::Green => Pallet::green(), + PalletEnum::GreenLight => Pallet::green_light(), + PalletEnum::Blue => Pallet::blue(), + PalletEnum::BlueLight => Pallet::blue_light(), + PalletEnum::White => Pallet::white(), + PalletEnum::Rainbow => Pallet::rainbow() + } +} \ No newline at end of file