Add 'unicode-only' option

pull/6/head
sgoudham 3 years ago
parent cf1ff5455e
commit bd0275dc9e
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -11,6 +11,7 @@ use memmap::Mmap;
use constants::{ use constants::{
ACTIONS, ACTIONS_SIZE, ASCII_FACES, ASCII_FACES_SIZE, MIXED_FACES, MIXED_FACES_SIZE, ACTIONS, ACTIONS_SIZE, ASCII_FACES, ASCII_FACES_SIZE, MIXED_FACES, MIXED_FACES_SIZE,
UNICODE_FACES, UNICODE_FACES_SIZE,
}; };
mod constants; mod constants;
@ -60,12 +61,13 @@ pub struct UwUify<'a> {
text: &'a str, text: &'a str,
input: &'a str, input: &'a str,
output: &'a str, output: &'a str,
ascii: bool,
unicode: bool,
random: RandomState,
words: f64, words: f64,
faces: f64, faces: f64,
actions: f64, actions: f64,
stutters: f64, stutters: f64,
random: RandomState,
ascii: bool,
is_runtime: bool, is_runtime: bool,
linkify: LinkFinder, linkify: LinkFinder,
} }
@ -76,13 +78,14 @@ impl<'a> Default for UwUify<'a> {
text: "", text: "",
input: "", input: "",
output: "", output: "",
ascii: false,
unicode: false,
random: RandomState::with_seeds(69, 420, 96, 84),
words: 1.0, words: 1.0,
faces: 0.05, faces: 0.05,
actions: 0.125, actions: 0.125,
stutters: 0.225, stutters: 0.225,
random: RandomState::with_seeds(69, 420, 96, 84),
is_runtime: false, is_runtime: false,
ascii: false,
linkify: LinkFinder::new(), linkify: LinkFinder::new(),
} }
} }
@ -93,12 +96,13 @@ impl<'a> UwUify<'a> {
text: Option<&'a str>, text: Option<&'a str>,
infile: Option<&'a str>, infile: Option<&'a str>,
outfile: Option<&'a str>, outfile: Option<&'a str>,
ascii: bool,
unicode: bool,
random: bool,
words: Option<&'a str>, words: Option<&'a str>,
faces: Option<&'a str>, faces: Option<&'a str>,
actions: Option<&'a str>, actions: Option<&'a str>,
stutters: Option<&'a str>, stutters: Option<&'a str>,
ascii: bool,
random: bool,
is_runtime: bool, is_runtime: bool,
) -> UwUify<'a> { ) -> UwUify<'a> {
let mut linkify = LinkFinder::new(); let mut linkify = LinkFinder::new();
@ -110,6 +114,7 @@ impl<'a> UwUify<'a> {
input: infile.unwrap_or_default(), input: infile.unwrap_or_default(),
output: outfile.unwrap_or_default(), output: outfile.unwrap_or_default(),
ascii, ascii,
unicode,
is_runtime, is_runtime,
linkify, linkify,
..Default::default() ..Default::default()
@ -191,6 +196,11 @@ impl<'a> UwUify<'a> {
out, out,
ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)] 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 { } else {
write!( write!(
out, out,
@ -214,6 +224,11 @@ impl<'a> UwUify<'a> {
out, out,
ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)] 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 { } else {
write!( write!(
out, out,
@ -274,13 +289,14 @@ mod tests {
Some(include_str!("test.txt")), Some(include_str!("test.txt")),
None, None,
None, None,
false,
true,
false,
None, None,
None, None,
None, None,
None, None,
false, false,
false,
false,
); );
b.iter(|| uwuify.uwuify()); b.iter(|| uwuify.uwuify());
} }

@ -25,12 +25,6 @@ macro_rules! app {
.required_unless_present_all(["infile", "outfile"]) .required_unless_present_all(["infile", "outfile"])
.display_order(1), .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(
Arg::new("infile") Arg::new("infile")
.help("The file to uwu'ify") .help("The file to uwu'ify")
@ -40,7 +34,7 @@ macro_rules! app {
.requires("outfile") .requires("outfile")
.value_name("FILE") .value_name("FILE")
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.display_order(3), .display_order(2),
) )
.arg( .arg(
Arg::new("outfile") Arg::new("outfile")
@ -49,8 +43,28 @@ macro_rules! app {
.long("outfile") .long("outfile")
.value_name("FILE") .value_name("FILE")
.value_hint(clap::ValueHint::FilePath) .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), .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(
Arg::new("words") Arg::new("words")
.help("The modifier to determine how many words to be uwu'ified") .help("The modifier to determine how many words to be uwu'ified")
@ -59,7 +73,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("1") .default_value("1")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(5), .display_order(7),
) )
.arg( .arg(
Arg::new("faces") Arg::new("faces")
@ -69,7 +83,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.05") .default_value("0.05")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(6), .display_order(8),
) )
.arg( .arg(
Arg::new("actions") Arg::new("actions")
@ -79,7 +93,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.125") .default_value("0.125")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(7), .display_order(9),
) )
.arg( .arg(
Arg::new("stutters") Arg::new("stutters")
@ -89,14 +103,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.225") .default_value("0.225")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(8), .display_order(10),
)
.arg(
Arg::new("random")
.help("Flag to enable/disable random uwu'ifying")
.short('r')
.long("random")
.display_order(9),
) )
}; };
} }
@ -121,12 +128,13 @@ fn main() {
matches.value_of("text"), matches.value_of("text"),
matches.value_of("infile"), matches.value_of("infile"),
matches.value_of("outfile"), 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("words"),
matches.value_of("faces"), matches.value_of("faces"),
matches.value_of("actions"), matches.value_of("actions"),
matches.value_of("stutters"), matches.value_of("stutters"),
matches.is_present("ascii-only"),
matches.is_present("random"),
is_runtime!( is_runtime!(
matches.occurrences_of("faces"), matches.occurrences_of("faces"),
matches.occurrences_of("actions"), matches.occurrences_of("actions"),

Loading…
Cancel
Save