From ed2ff677f1977d2c163322ce9e7a55f0740d1f1a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 5 Jun 2022 17:19:53 +0200 Subject: thing --- src/main.rs | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d210aaf..482e20a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use anyhow::Result; use blubcat::{ color::Color, pattern::{Gradient, Rainbow, Sequence, Solid}, - transform::{Matrix, Polar, Translate}, + transform::{Matrix, Polar, Translate, Transpose}, Sample, }; use std::{ @@ -16,30 +16,36 @@ use std::{ }; static HELP: &str = " -Usage: blubcat [PATTERN] [FILE...] -Concatenate FILE(s) to standard output, colorizing the output according to PATTERN. +Usage: blubcat [OPTION...] [FILE...] +Concatenate FILE(s) to standard output, colorizing the output according to OPTION. With no FILE, or when FILE is -, the standard input is read. -If PATTERN is repeated only the last one will be used. +OPTION can be PATTERN, TRANSFORM or PRESET. +Patterns are stored on a stack. +, indicates the number of patters popped from the stack and how many are pushed back on. PATTERN: - -R --rainbow Sinebow - -S --sequence Sequences colors on the X-axis - -G --gradient Interpolates the colors on the X-axis - Push mulple patterns to a stack, then process them with transform - +0,1 -R --rainbow Sinebow +0,1 -K --const Solid color +0,1 -S --sequence Sequences colors on the X-axis +0,1 -G --gradient Interpolates the colors on the X-axis TRANSFORM: - -r --rotate - -s --scale - -m --matrix - -t --translate - --polar +1,1 -r --rotate +1,1 -s --scale +1,1 -m --matrix +1,1 -t --translate +1,1 -T --transpose +1,1 -p --polar +2,1 --mix +2,1 --add +2,1 --subtract +2,1 --multiply PRESET: - --zebra - --pride --trans - --ukraine ofc the this needed :) +0,1 --zebra +0,1 --pride --trans +0,1 --ukraine ofc this is needed COLOR: @@ -49,6 +55,7 @@ COLOR: fn main() -> Result<()> { let mut args = env::args().skip(1); + let mut arg_extra = None; let mut pat: Vec> = vec![]; @@ -61,9 +68,9 @@ fn main() -> Result<()> { .parse::() .expect("not a number") }; - if let Some(a) = a { if !a.starts_with("-") || a == "--" || a == "-" { + arg_extra = Some(a); break; } let mut push_queue: Vec> = vec![]; @@ -99,6 +106,10 @@ fn main() -> Result<()> { .map(|e| Color::parse(e).expect("color invalid")) .collect::>(), )), + "-K" | "--const" => pat.push(box Solid( + Color::parse(arg_next().expect("color expected").as_str()) + .expect("invalid color"), + )), /* TRANSFORMS */ "-s" | "--scale" => { @@ -119,7 +130,7 @@ fn main() -> Result<()> { inner: pat.pop().unwrap(), matrix: ((arg_num(), arg_num()), (arg_num(), arg_num())), }), - "--polar" => push_queue.push(box Polar(pat.pop().unwrap())), + "-p" | "--polar" => push_queue.push(box Polar(pat.pop().unwrap())), "-t" | "--translate" => { let (x, y) = (arg_num(), arg_num()); push_queue.push(box Translate { @@ -127,6 +138,7 @@ fn main() -> Result<()> { inner: pat.pop().unwrap(), }) } + "-T" | "--transpose" => push_queue.push(box Transpose(pat.pop().unwrap())), _ => panic!("unknown option {}", &a), } pat.extend(push_queue.drain(..)) @@ -135,9 +147,13 @@ fn main() -> Result<()> { } } - let inputs = args.collect::>(); + let mut inputs = args.collect::>(); let mut pat = pat.pop().unwrap_or_else(|| box Solid(Color::WHITE)); + if let Some(a) = arg_extra { + inputs.insert(0, a) + } + if inputs.len() == 0 { colorize(stdin(), &mut pat)? } else { -- cgit v1.2.3-70-g09d2