diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 17:19:53 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-05 17:19:53 +0200 |
commit | ed2ff677f1977d2c163322ce9e7a55f0740d1f1a (patch) | |
tree | bad9701c11004f2faa05ce21d31a97cd4d874ef3 /src/main.rs | |
parent | 280cc84e641872564e35d801fbdc7990e013a0e7 (diff) | |
download | blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar.bz2 blubcat-ed2ff677f1977d2c163322ce9e7a55f0740d1f1a.tar.zst |
thing
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 56 |
1 files changed, 36 insertions, 20 deletions
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. +<pop>,<push> indicates the number of patters popped from the stack and how many are pushed back on. PATTERN: - -R --rainbow Sinebow - -S --sequence <c1,c2,c3,...> Sequences colors on the X-axis - -G --gradient <c1,c2,c3,...> Interpolates the colors on the X-axis - <PATTERN...> <TRANSFORM> Push mulple patterns to a stack, then process them with transform - <PRESET> +0,1 -R --rainbow Sinebow +0,1 -K --const <color> Solid color +0,1 -S --sequence <c1,c2,c3,...> Sequences colors on the X-axis +0,1 -G --gradient <c1,c2,c3,...> Interpolates the colors on the X-axis TRANSFORM: - -r --rotate <angle> - -s --scale <factor> - -m --matrix <x> <y> <z> <w> - -t --translate <x> <y> - --polar +1,1 -r --rotate <angle> +1,1 -s --scale <factor> +1,1 -m --matrix <x> <y> <z> <w> +1,1 -t --translate <x> <y> +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: <rrggbb> @@ -49,6 +55,7 @@ COLOR: fn main() -> Result<()> { let mut args = env::args().skip(1); + let mut arg_extra = None; let mut pat: Vec<Box<dyn Sample>> = vec![]; @@ -61,9 +68,9 @@ fn main() -> Result<()> { .parse::<f64>() .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<Box<dyn Sample>> = vec![]; @@ -99,6 +106,10 @@ fn main() -> Result<()> { .map(|e| Color::parse(e).expect("color invalid")) .collect::<Vec<_>>(), )), + "-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::<Vec<String>>(); + let mut inputs = args.collect::<Vec<String>>(); 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 { |