From bd0275dc9ed7b79e8fa305f18053f795fd0be29c Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 3 Feb 2022 16:35:44 +0000 Subject: [PATCH] Add 'unicode-only' option --- src/lib.rs | 32 ++++++++++++++++++++++++-------- src/main.rs | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0dd9059..fe2e9bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ use memmap::Mmap; use constants::{ ACTIONS, ACTIONS_SIZE, ASCII_FACES, ASCII_FACES_SIZE, MIXED_FACES, MIXED_FACES_SIZE, + UNICODE_FACES, UNICODE_FACES_SIZE, }; mod constants; @@ -60,12 +61,13 @@ pub struct UwUify<'a> { text: &'a str, input: &'a str, output: &'a str, + ascii: bool, + unicode: bool, + random: RandomState, words: f64, faces: f64, actions: f64, stutters: f64, - random: RandomState, - ascii: bool, is_runtime: bool, linkify: LinkFinder, } @@ -76,13 +78,14 @@ impl<'a> Default for UwUify<'a> { text: "", input: "", output: "", + ascii: false, + unicode: false, + random: RandomState::with_seeds(69, 420, 96, 84), words: 1.0, faces: 0.05, actions: 0.125, stutters: 0.225, - random: RandomState::with_seeds(69, 420, 96, 84), is_runtime: false, - ascii: false, linkify: LinkFinder::new(), } } @@ -93,12 +96,13 @@ impl<'a> UwUify<'a> { text: Option<&'a str>, infile: Option<&'a str>, outfile: Option<&'a str>, + ascii: bool, + unicode: bool, + random: bool, words: Option<&'a str>, faces: Option<&'a str>, actions: Option<&'a str>, stutters: Option<&'a str>, - ascii: bool, - random: bool, is_runtime: bool, ) -> UwUify<'a> { let mut linkify = LinkFinder::new(); @@ -110,6 +114,7 @@ impl<'a> UwUify<'a> { input: infile.unwrap_or_default(), output: outfile.unwrap_or_default(), ascii, + unicode, is_runtime, linkify, ..Default::default() @@ -191,6 +196,11 @@ impl<'a> UwUify<'a> { out, ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)] )?; + } else if self.unicode { + write!( + out, + UNICODE_FACES[random_int!(&mut seeder, 0..UNICODE_FACES_SIZE)] + )?; } else { write!( out, @@ -214,6 +224,11 @@ impl<'a> UwUify<'a> { out, ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)] )?; + } else if self.unicode { + write!( + out, + UNICODE_FACES[random_int!(&mut seeder, 0..UNICODE_FACES_SIZE)] + )?; } else { write!( out, @@ -274,13 +289,14 @@ mod tests { Some(include_str!("test.txt")), None, None, + false, + true, + false, None, None, None, None, false, - false, - false, ); b.iter(|| uwuify.uwuify()); } diff --git a/src/main.rs b/src/main.rs index 04e95dc..1cdae9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,12 +25,6 @@ macro_rules! app { .required_unless_present_all(["infile", "outfile"]) .display_order(1), ) - .arg( - Arg::new("ascii-only") - .help("The output file will not use UTF-8 charecters") - .long("ascii-only") - .display_order(2), - ) .arg( Arg::new("infile") .help("The file to uwu'ify") @@ -40,7 +34,7 @@ macro_rules! app { .requires("outfile") .value_name("FILE") .value_hint(clap::ValueHint::FilePath) - .display_order(3), + .display_order(2), ) .arg( Arg::new("outfile") @@ -49,8 +43,28 @@ macro_rules! app { .long("outfile") .value_name("FILE") .value_hint(clap::ValueHint::FilePath) + .display_order(3), + ) + .arg( + Arg::new("ascii-only") + .help("The output file will only include ASCII faces") + .long("ascii-only") + .conflicts_with("unicode-only") .display_order(4), ) + .arg( + Arg::new("unicode-only") + .help("The output file will only include UTF-8 faces") + .long("unicode-only") + .display_order(5), + ) + .arg( + Arg::new("random") + .help("Flag to enable/disable random uwu'ifying") + .short('r') + .long("random") + .display_order(6), + ) .arg( Arg::new("words") .help("The modifier to determine how many words to be uwu'ified") @@ -59,7 +73,7 @@ macro_rules! app { .value_name("VALUE") .default_value("1") .validator(is_between_zero_and_one) - .display_order(5), + .display_order(7), ) .arg( Arg::new("faces") @@ -69,7 +83,7 @@ macro_rules! app { .value_name("VALUE") .default_value("0.05") .validator(is_between_zero_and_one) - .display_order(6), + .display_order(8), ) .arg( Arg::new("actions") @@ -79,7 +93,7 @@ macro_rules! app { .value_name("VALUE") .default_value("0.125") .validator(is_between_zero_and_one) - .display_order(7), + .display_order(9), ) .arg( Arg::new("stutters") @@ -89,14 +103,7 @@ macro_rules! app { .value_name("VALUE") .default_value("0.225") .validator(is_between_zero_and_one) - .display_order(8), - ) - .arg( - Arg::new("random") - .help("Flag to enable/disable random uwu'ifying") - .short('r') - .long("random") - .display_order(9), + .display_order(10), ) }; } @@ -121,12 +128,13 @@ fn main() { matches.value_of("text"), matches.value_of("infile"), matches.value_of("outfile"), + matches.is_present("ascii-only"), + matches.is_present("unicode-only"), + matches.is_present("random"), matches.value_of("words"), matches.value_of("faces"), matches.value_of("actions"), matches.value_of("stutters"), - matches.is_present("ascii-only"), - matches.is_present("random"), is_runtime!( matches.occurrences_of("faces"), matches.occurrences_of("actions"), @@ -149,4 +157,4 @@ fn is_between_zero_and_one(input: &str) -> Result<(), &'static str> { return Ok(()); } Err("The value must be between 0.0 and 1.0") -} +} \ No newline at end of file