mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-26 01:46:36 +00:00
Remove factories temporarily
This commit is contained in:
parent
0ae10b2927
commit
ac1c839648
@ -1,123 +0,0 @@
|
||||
use clap::ArgEnum;
|
||||
use crossterm::style::Color::*;
|
||||
use rand::Rng;
|
||||
use rand::prelude::IteratorRandom;
|
||||
use crate::color::{ColorSampler, SimpleColorSampler};
|
||||
|
||||
#[derive(Copy, Clone, ArgEnum)]
|
||||
pub enum ColorEnum {
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
LightRed,
|
||||
LightGreen,
|
||||
LightBlue,
|
||||
White,
|
||||
Rainbow
|
||||
}
|
||||
|
||||
pub trait ColorSamplerFactory {
|
||||
/// Creates the requested color.
|
||||
/// # Arguments
|
||||
/// * `color`: The color type.
|
||||
fn create(&self, colors: ColorEnum) -> Box<dyn ColorSampler>;
|
||||
|
||||
/// Chooses a random color color.
|
||||
/// If none is provided, a random one of all available is chosen.
|
||||
/// # Arguments
|
||||
/// * `options`: A list of all options.
|
||||
/// * `rng`: The number generator.
|
||||
fn choose(&self, options: Vec<ColorEnum>, rng: &mut impl Rng) -> ColorEnum;
|
||||
}
|
||||
|
||||
pub struct SimpleColorSamplerFactory;
|
||||
|
||||
impl SimpleColorSamplerFactory {
|
||||
pub fn new() -> Self {
|
||||
Self { }
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorSamplerFactory for SimpleColorSamplerFactory {
|
||||
fn create(&self, colors: ColorEnum) -> Box<dyn ColorSampler> {
|
||||
match colors {
|
||||
ColorEnum::Red => Box::new(SimpleColorSampler::new(vec![Yellow, DarkYellow, Red])),
|
||||
ColorEnum::Green => Box::new(SimpleColorSampler::new(vec![Cyan, DarkGreen, Green])),
|
||||
ColorEnum::Blue => Box::new(SimpleColorSampler::new(vec![Magenta, DarkBlue, Blue])),
|
||||
ColorEnum::LightRed => Box::new(SimpleColorSampler::new(vec![White, Yellow, Red])),
|
||||
ColorEnum::LightGreen => Box::new(SimpleColorSampler::new(vec![White, Cyan, Green])),
|
||||
ColorEnum::LightBlue => Box::new(SimpleColorSampler::new(vec![White, Blue, Magenta])),
|
||||
ColorEnum::White => Box::new(SimpleColorSampler::new(vec![Black, Grey, White])),
|
||||
ColorEnum::Rainbow => Box::new(SimpleColorSampler::new(vec![Magenta, Blue, Green, Yellow, Red]))
|
||||
}
|
||||
}
|
||||
|
||||
fn choose(&self, mut options: Vec<ColorEnum>, rng: &mut impl Rng) -> ColorEnum {
|
||||
if options.is_empty() {
|
||||
options.push(ColorEnum::Red);
|
||||
options.push(ColorEnum::Green);
|
||||
options.push(ColorEnum::Blue);
|
||||
options.push(ColorEnum::LightRed);
|
||||
options.push(ColorEnum::LightGreen);
|
||||
options.push(ColorEnum::LightBlue);
|
||||
options.push(ColorEnum::White);
|
||||
options.push(ColorEnum::Rainbow);
|
||||
}
|
||||
options.into_iter().choose_stable(rng).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use rand::rngs::mock::StepRng;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
let factory = SimpleColorSamplerFactory::new();
|
||||
|
||||
factory.create(ColorEnum::Red);
|
||||
factory.create(ColorEnum::Green);
|
||||
factory.create(ColorEnum::Blue);
|
||||
factory.create(ColorEnum::LightRed);
|
||||
factory.create(ColorEnum::LightGreen);
|
||||
factory.create(ColorEnum::LightBlue);
|
||||
factory.create(ColorEnum::White);
|
||||
factory.create(ColorEnum::Rainbow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_from_all() {
|
||||
let rng = &mut StepRng::new(0, 1);
|
||||
|
||||
let factory = SimpleColorSamplerFactory::new();
|
||||
|
||||
assert!(matches!(factory.choose(Vec::new(), rng), ColorEnum::Rainbow));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_from_options() {
|
||||
let rng = &mut StepRng::new(0, 1);
|
||||
let options = vec![ColorEnum::Blue];
|
||||
|
||||
let factory = SimpleColorSamplerFactory::new();
|
||||
|
||||
assert!(matches!(factory.choose(options, rng), ColorEnum::Blue));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_copy() {
|
||||
let color = ColorEnum::Green;
|
||||
let copy = color;
|
||||
|
||||
assert!(matches!(copy, ColorEnum::Green))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_clone() {
|
||||
let color = ColorEnum::Green;
|
||||
let copy = color.clone();
|
||||
|
||||
assert!(matches!(copy, ColorEnum::Green))
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
pub mod factory;
|
||||
|
||||
use crossterm::style::Color;
|
||||
use crossterm::style::Color::*;
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
use clap::ArgEnum;
|
||||
use rand::prelude::IteratorRandom;
|
||||
use rand::Rng;
|
||||
use crate::fill::FillMode;
|
||||
use crate::fill::level::LevelFillMode;
|
||||
use crate::vec::Vector;
|
||||
|
||||
#[derive(Copy, Clone, ArgEnum)]
|
||||
pub enum FillModeEnum {
|
||||
Circle,
|
||||
Level,
|
||||
Stripe
|
||||
}
|
||||
|
||||
pub trait FillModeFactory {
|
||||
fn create(&self, mode: FillModeEnum, size: Vector) -> Box<dyn FillMode>;
|
||||
|
||||
fn choose(&self, options: Vec<FillModeEnum>, rng: &mut impl Rng) -> FillModeEnum;
|
||||
}
|
||||
|
||||
pub struct SimpleFillModeFactory;
|
||||
|
||||
impl SimpleFillModeFactory {
|
||||
pub fn new() -> Self {
|
||||
Self { }
|
||||
}
|
||||
}
|
||||
|
||||
impl FillModeFactory for SimpleFillModeFactory {
|
||||
fn create(&self, mode: FillModeEnum, _: Vector) -> Box<dyn FillMode> {
|
||||
match mode {
|
||||
FillModeEnum::Circle => todo!(),
|
||||
FillModeEnum::Level => Box::new(LevelFillMode::new()),
|
||||
FillModeEnum::Stripe => todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn choose(&self, mut options: Vec<FillModeEnum>, rng: &mut impl Rng) -> FillModeEnum {
|
||||
if options.is_empty() {
|
||||
options.push(FillModeEnum::Circle);
|
||||
options.push(FillModeEnum::Level);
|
||||
options.push(FillModeEnum::Stripe);
|
||||
}
|
||||
options.into_iter().choose_stable(rng).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use rand::rngs::mock::StepRng;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
let factory = SimpleFillModeFactory::new();
|
||||
let size = Vector::ZERO;
|
||||
|
||||
factory.create(FillModeEnum::Circle, size);
|
||||
factory.create(FillModeEnum::Level, size);
|
||||
factory.create(FillModeEnum::Stripe, size);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_from_all() {
|
||||
let rng = &mut StepRng::new(0, 1);
|
||||
|
||||
let factory = SimpleFillModeFactory::new();
|
||||
|
||||
assert!(matches!(factory.choose(Vec::new(), rng), FillModeEnum::Stripe));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choose_from_options() {
|
||||
let rng = &mut StepRng::new(0, 1);
|
||||
let options = vec![FillModeEnum::Circle];
|
||||
|
||||
let factory = SimpleFillModeFactory::new();
|
||||
|
||||
assert!(matches!(factory.choose(options, rng), FillModeEnum::Circle));
|
||||
}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
mod level;
|
||||
|
||||
pub mod factory;
|
||||
|
||||
use crate::vec::Vector;
|
||||
|
||||
/// Used to choose the colors of characters.
|
||||
|
@ -1,6 +1,4 @@
|
||||
use clap::Parser;
|
||||
use crate::color::factory::ColorEnum;
|
||||
use crate::fill::factory::FillModeEnum;
|
||||
|
||||
mod color;
|
||||
mod char;
|
||||
@ -13,10 +11,6 @@ mod animation;
|
||||
#[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 fill mode", arg_enum)]
|
||||
fill: Vec<FillModeEnum>,
|
||||
#[clap(short, long, help = "Add color color", arg_enum)]
|
||||
pallet: Vec<ColorEnum>,
|
||||
#[clap(long, default_value = ".-+%#", help = "Set chars")]
|
||||
chars: String
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user