wipe/src/main.rs

109 lines
3.4 KiB
Rust
Raw Normal View History

2022-04-09 11:01:36 +00:00
use std::io::stdout;
2022-04-09 10:56:57 +00:00
use anyhow::Error;
2022-04-02 15:19:48 +00:00
use clap::Parser;
2022-04-09 10:56:57 +00:00
use clap::ArgEnum;
use crossterm::style::Color::*;
use crate::animation::Animation;
use crate::animation::circle::CircleAnimation;
2022-04-09 11:01:36 +00:00
use crate::char::SimpleCharSampler;
2022-04-09 10:56:57 +00:00
use crate::color::{ColorSampler, SimpleColorSampler};
use crate::fill::circle::CircleFillMode;
use crate::fill::FillMode;
use crate::fill::level::LevelFillMode;
2022-04-09 11:01:36 +00:00
use crate::sampler::ComposedSampler;
use crate::surface::WriteSurface;
2022-04-09 10:56:57 +00:00
use crate::vec::Vector;
2022-04-02 15:19:48 +00:00
2022-04-03 12:44:26 +00:00
mod color;
2022-04-02 15:20:52 +00:00
mod char;
2022-04-02 15:25:35 +00:00
mod fill;
mod vec;
2022-04-03 14:03:28 +00:00
mod array;
2022-04-06 16:39:20 +00:00
mod surface;
2022-04-08 16:59:52 +00:00
mod animation;
2022-04-08 18:05:00 +00:00
mod sampler;
2022-04-02 15:19:48 +00:00
2022-04-09 10:56:57 +00:00
#[derive(Copy, Clone, ArgEnum)]
enum AnimationType {
Circle
}
#[derive(Copy, Clone, ArgEnum)]
enum ColorType {
Red,
Green,
Blue,
LightRed,
LightGreen,
LightBlue,
Grey,
Rainbow,
}
#[derive(Copy, Clone, ArgEnum)]
enum FillModeType {
Circle,
Level
}
2022-04-02 15:19:48 +00:00
#[derive(Parser)]
#[clap(author = "Rico Riedel", version = "0.1.0", about = "Wipe your terminal with a random animation.")]
struct Args {
2022-04-09 10:56:57 +00:00
#[clap(short, long, help = "Add animation", arg_enum)]
animation: Vec<AnimationType>,
#[clap(short, long, help = "Add fill mode", arg_enum)]
fill: Vec<FillModeType>,
#[clap(short, long, help = "Add color pallet", arg_enum)]
color: Vec<ColorType>,
2022-04-02 15:20:52 +00:00
#[clap(long, default_value = ".-+%#", help = "Set chars")]
2022-04-09 10:56:57 +00:00
chars: String,
#[clap(long, help = "Set width [default: terminal width]")]
width: Option<usize>,
#[clap(long, help = "Set height [default: terminal height]")]
height: Option<usize>,
}
fn main() -> Result<(), Error> {
let args = Args::parse();
let terminal = crossterm::terminal::size()?;
let width = args.width.unwrap_or(terminal.0 as usize);
let height = args.width.unwrap_or(terminal.1 as usize);
let size = Vector::from_terminal(width, height);
let animation = create_animation(args.animation[0], size);
let fill = create_fill(args.fill[0], size);
let color = create_color(args.color[0]);
2022-04-09 11:01:36 +00:00
let char = Box::new(SimpleCharSampler::new(args.chars));
let _ = Box::new(ComposedSampler::new(animation, fill, color, char));
let _ = Box::new(WriteSurface::new(stdout(), width, height));
2022-04-09 10:56:57 +00:00
Ok(())
2022-04-02 15:19:48 +00:00
}
2022-04-09 10:56:57 +00:00
fn create_animation(animation: AnimationType, size: Vector) -> Box<dyn Animation> {
match animation {
AnimationType::Circle => Box::new(CircleAnimation::new(size))
}
2022-04-02 15:05:49 +00:00
}
2022-04-09 10:56:57 +00:00
fn create_fill(fill: FillModeType, size: Vector) -> Box<dyn FillMode> {
match fill {
FillModeType::Circle => Box::new(CircleFillMode::new(size)),
FillModeType::Level => Box::new(LevelFillMode::new()),
}
}
fn create_color(color: ColorType) -> Box<dyn ColorSampler> {
match color {
ColorType::Red => Box::new(SimpleColorSampler::new(vec![Yellow, DarkYellow, Red])),
ColorType::Green => Box::new(SimpleColorSampler::new(vec![Cyan, DarkGreen, Green])),
ColorType::Blue => Box::new(SimpleColorSampler::new(vec![Magenta, DarkBlue, Blue])),
ColorType::LightRed => Box::new(SimpleColorSampler::new(vec![White, Yellow, Red])),
ColorType::LightGreen => Box::new(SimpleColorSampler::new(vec![White, Cyan, Green])),
ColorType::LightBlue => Box::new(SimpleColorSampler::new(vec![White, Blue, Magenta])),
ColorType::Grey => Box::new(SimpleColorSampler::new(vec![Black, Grey, White])),
ColorType::Rainbow => Box::new(SimpleColorSampler::new(vec![Magenta, Blue, Green, Yellow, Red]))
}
}