From 37b3d1fb11e1862d9c79136d53d440062e12c7e0 Mon Sep 17 00:00:00 2001 From: spiders Date: Fri, 29 Apr 2022 13:40:48 -0700 Subject: [PATCH] added classic cowsay options, as well as soweli --- src/critters.rs | 54 +++++++++++++++++------ src/main.rs | 115 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 125 insertions(+), 44 deletions(-) diff --git a/src/critters.rs b/src/critters.rs index 1da6d62..7d790ec 100644 --- a/src/critters.rs +++ b/src/critters.rs @@ -23,17 +23,20 @@ pub struct CritterConfig { pub up_line: String, pub left_line: String, + pub object: String, + pub template: CritterTemplate, } impl CritterConfig { pub fn config_from_string( - eyes: Option, - tongue: Option, - line: Option, - name: Option, + eyes: &Option, + tongue: &Option, + line: &Option, + object: &Option, + name: &Option, ) -> CritterConfig { - let kijetesantakalu: CritterTemplate = CritterTemplate { + let kijetesantakalu = CritterTemplate { anchor: 14, critter: r" $6 @@ -41,24 +44,32 @@ impl CritterConfig { / $1$2\ $5 | |$3$4 | | - (III|\||" + (III|\|| $0" .to_string(), }; - - let kijetesantakalu_little: CritterTemplate = CritterTemplate { + let kijetesantakalu_little = CritterTemplate { anchor: 13, critter: r" $6 /__ $6 / $1$2\ $5 | |$3$4 - (I|\||" + (I|\|| $0" + .to_string(), + }; + let soweli = CritterTemplate { + anchor: 10, + critter: r" + $6 + ___ $6 + $1$2) $5 + |||| $0" .to_string(), }; let default_config: CritterConfig = CritterConfig { - left_eye: String::from("."), - right_eye: String::from("."), + left_eye: String::from("o"), + right_eye: String::from("o"), left_tongue: String::from(" "), right_tongue: String::from(" "), @@ -67,6 +78,8 @@ impl CritterConfig { up_line: String::from("|"), left_line: String::from("\\"), + object: String::from(" "), + template: kijetesantakalu, }; @@ -100,7 +113,13 @@ impl CritterConfig { if let Some(line) = line { match count::count_graphemes(&line) { 0 => (), - 1 => config.right_line = chop::grapheme_at(&line, 0), + 1 => { + (config.right_line, config.up_line, config.left_line) = ( + chop::grapheme_at(&line, 0), + chop::grapheme_at(&line, 0), + chop::grapheme_at(&line, 0), + ) + } 2 => { (config.right_line, config.up_line) = (chop::grapheme_at(&line, 0), chop::grapheme_at(&line, 1)) @@ -114,11 +133,17 @@ impl CritterConfig { } } } - + if let Some(object) = object { + match count::count_graphemes(&object) { + 0 => (), + _ => config.object = object.clone(), + } + } if let Some(name) = name { match name.as_str() { "kijetesantakalu" => (), "lili" => config.template = kijetesantakalu_little, + "soweli" => config.template = soweli, _ => (), } } @@ -136,6 +161,7 @@ impl CritterConfig { .replace("$4", &self.right_tongue) .replace("$5", &self.right_line) .replace("$6", &self.up_line) - .replace("$7", &self.left_line); + .replace("$7", &self.left_line) + .replace("$0", &self.object); } } diff --git a/src/main.rs b/src/main.rs index 7eead65..76e5e95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ /* TO DO -- options - kijefiles +- color - other aminals */ @@ -12,35 +12,6 @@ use clap::Parser; use std::io; use std::io::Read; -#[derive(Parser, Debug)] -#[clap(author, version, about, long_about = None)] -struct Args { - #[clap(short, long)] - lukin: Option, - - #[clap(short, long)] - uta: Option, - - #[clap(short, long)] - palisa: Option, - - #[clap(short, long)] - nimi: Option, - - text: Vec, -} - -impl Args { - fn config_from_arguments(&self) -> critters::CritterConfig { - critters::CritterConfig::config_from_string( - self.lukin.clone(), - self.uta.clone(), - self.palisa.clone(), - self.nimi.clone(), - ) - } -} - fn main() { let cli = Args::parse(); let mut text = String::new(); @@ -56,6 +27,90 @@ fn main() { output(&text, config) } +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +struct Args { + #[clap(short = 'e', long)] + lukin: Option, + + #[clap(short = 'T', long)] + uta: Option, + + #[clap(short = 'o', long)] + ijo: Option, + + #[clap(long)] + palisa: Option, + + #[clap(short = 'f', long)] + nimi: Option, + + #[clap(short = 'W', long)] + pakala: Option, + + // implementation of classic cowsay flags + #[clap(short = 'b', long)] + ilo: bool, + + #[clap(short = 'd', long)] + moli: bool, + + #[clap(short = 'g', long)] + wile_mani: bool, + + #[clap(short = 'p', long)] + monsuta: bool, + + #[clap(short = 's', long)] + kasi_nasa: bool, + + #[clap(short = 't', long)] + lape: bool, + + #[clap(short = 'w', long)] + wawa: bool, + + #[clap(short = 'y', long)] + lili: bool, + + #[clap(long)] + pilin: bool, + + // optional text input + text: Vec, +} + +impl Args { + fn config_from_arguments(&self) -> critters::CritterConfig { + let mut eyes = self.lukin.clone(); + let mut tongue = self.uta.clone(); + let mut line = self.palisa.clone(); + let mut object = self.ijo.clone(); + let mut name = self.nimi.clone(); + + if self.ilo { + eyes = Some("==".to_string()); + } else if self.moli { + eyes = Some("xx".to_string()); + tongue = Some("U".to_string()); + } else if self.wile_mani { + eyes = Some("$$".to_string()); + } else if self.monsuta { + eyes = Some("@@".to_string()); + } else if self.kasi_nasa { + eyes = Some("**".to_string()); + tongue = Some("U".to_string()); + } else if self.lape { + eyes = Some("--".to_string()); + } else if self.wawa { + eyes = Some("OO".to_string()); + } else if self.lili { + eyes = Some("..".to_string()); + } + critters::CritterConfig::config_from_string(&eyes, &tongue, &line, &object, &name) + } +} + fn output(text: &str, config: critters::CritterConfig) -> () { print!( "{}",