Merge pull request #4 from sgoudham/v0.2.0

pull/8/head
Hamothy 3 years ago committed by GitHub
commit 782705852a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,8 +47,11 @@ jobs:
7z a "${{ env.BIN }}.zip" "${{ env.BIN }}.exe"
mv "${{ env.BIN }}.zip" $GITHUB_WORKSPACE
shell: bash
# We're using a fork of `actions/create-release` that detects
# whether a release is already available or not first.
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@{latest-release}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: XAMPPRocky/create-release@v1.0.2
id: create_release
env:
@ -56,8 +59,7 @@ jobs:
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
# Draft should **always** be false. GitHub doesn't provide a way to
# get draft releases from its API, so there's no point using it.
body: ${{steps.github_release.outputs.changelog}}
draft: false
prerelease: false
- uses: actions/upload-release-asset@v1
@ -88,6 +90,11 @@ jobs:
- run: scripts/set_rust_version.bash stable ${{ matrix.target }}
- run: scripts/build.bash cross ${{ matrix.target }} RELEASE
- run: tar -czvf ${{ env.BIN }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.BIN }}
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@{latest-release}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: XAMPPRocky/create-release@v1.0.2
id: create_release
env:
@ -95,6 +102,7 @@ jobs:
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{steps.github_release.outputs.changelog}}
draft: false
prerelease: false
- uses: actions/upload-release-asset@v1
@ -106,6 +114,18 @@ jobs:
asset_path: ${{ env.BIN }}.tar.gz
asset_name: ${{ env.BIN }}-${{ matrix.target }}.tar.gz
asset_content_type: application/gzip
- uses: mislav/bump-homebrew-formula-action@v1
if: "!contains(github.ref, '-')" # skip prereleases
with:
formula-name: ${{ env.BIN }}
homebrew-tap: sgoudham/tap
download-url: https://github.com/sgoudham/${{ env.BIN }}/releases/download/${{ github.ref }}/${{ env.BIN }}-${{ matrix.target }}.tar.gz
commit-message: |
{{formulaName}} {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW }}
linux:
runs-on: ubuntu-latest
@ -126,6 +146,11 @@ jobs:
- run: scripts/set_rust_version.bash stable ${{ matrix.target }}
- run: scripts/build.bash /tmp/cross ${{ matrix.target }} RELEASE
- run: tar -czvf ${{ env.BIN }}.tar.gz --directory=target/${{ matrix.target }}/release ${{ env.BIN }}
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@{latest-release}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: XAMPPRocky/create-release@v1.0.2
id: create_release
env:
@ -133,6 +158,7 @@ jobs:
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{steps.github_release.outputs.changelog}}
draft: false
prerelease: false
- name: Upload Release Asset
@ -144,4 +170,26 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.BIN }}.tar.gz
asset_name: ${{ env.BIN }}-${{ matrix.target }}.tar.gz
asset_content_type: application/gzip
asset_content_type: application/gzip
homebrew:
name: Bump Homebrew formula
needs: macos
runs-on: ubuntu-latest
steps:
- name: Extract version
id: extract-version
run: |
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
- uses: mislav/bump-homebrew-formula-action@v1
if: "!contains(github.ref, '-')" # skip prereleases
with:
formula-name: ${{ env.BIN }}
formula-path: Formula/${{ env.BIN }}.rb
homebrew-tap: sgoudham/tap
download-url: https://github.com/sgoudham/${{ env.BIN }}/releases/download/${{ github.ref }}/${{ env.BIN }}-${{ matrix.target }}.tar.gz
commit-message: |
{{formulaName}} {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW }}

@ -1,19 +1,21 @@
[package]
name = "uwuifyy"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
authors = ["Goudham <sgoudham@gmail.com>"]
description = "A robust, customizable, efficient and easy-to-use command line application to uwu'ify your text!"
description = "A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!"
license = "MIT"
readme = "README.md"
repository = "https://github.com/sgoudham/uwuifyy"
keywords = ["cli", "uwu", "owo", "uwuify", "anime"]
categories = ["command-line-utilities"]
exclude = [
"examples/the-complete-works-of-william-shakespeare.txt",
"examples/tiktok_app_reviews.csv",
"examples/tokyo-2020-olympics-tweets.csv",
"examples/uwu/**",
"examples/the-complete-works-of-william-shakespeare.txt",
"examples/tiktok_app_reviews.csv",
"examples/tokyo-2020-olympics-tweets.csv",
"examples/uwu/**",
".github/**",
"scripts/**"
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -27,6 +29,7 @@ rand = "0.8.4"
indicatif = "0.16.2"
linkify = "0.8.0"
rand_xoshiro = "0.6.0"
ahash = "0.7.6"
memmap = "0.7.0"
[profile.release]
@ -35,4 +38,4 @@ codegen-units = 1
panic = "abort"
[features]
bench = []
bench = []

@ -5,9 +5,9 @@
[![downloads](https://img.shields.io/crates/d/uwuifyy)](https://crates.io/crates/uwuifyy)
[![license](https://img.shields.io/github/license/sgoudham/uwuifyy)](LICENSE)
> A robust, customizable, efficient and easy-to-use command line application to uwu'ify your text!
> A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!
>
![](logo/UwUifyy-Transparent-Small.png)
![](logo/uwuifyy-logo.png)
>
> Logo Credits: Jade Nelson
@ -17,9 +17,11 @@
* [About](#about)
* [Features](#features)
* [Installation](#installation)
+ [Windows](#windows)
+ [Linux \ macOS](#Linux-\-macOS)
+ [Rust \ Cargo](#Rust-\-Cargo)
* [Homebrew](#homebrew)
* [Binaries](#binaries)
+ [Windows](#windows)
+ [Linux \ macOS](#Linux-\-macOS)
+ [Rust \ Cargo](#Rust-\-Cargo)
* [Usage](#usage)
+ [Text Input to Text Output](#text-input-to-text-output)
+ [Text Input to File Output](#text-input-to-file-output)
@ -40,6 +42,7 @@ allows you to _uwu'ify_ text and files from within your own terminal in an _extr
## Features
- [x] _**BLAZINGLY FAST**_ (Check out -> [Benchmarks](#benchmarks))
- [x] Seeded by default to allow for reproducible results
- [x] Excludes URL's & Emails
- [x] UwU'ify files available locally on disk
@ -47,6 +50,17 @@ allows you to _uwu'ify_ text and files from within your own terminal in an _extr
## Installation
### Homebrew
For `macOS` users, installation through [Homebrew](https://brew.sh/) is recommended.
```shell
$ brew tap sgoudham/tap
$ brew install uwuifyy
```
### Binaries
Binaries for **Windows**, **macOS** & **Linux** are available with every
single [release](https://github.com/sgoudham/uwuifyy/releases)
@ -69,13 +83,13 @@ C:
3. Set `uwuifyy.exe` in your path to access it globally
```shell
setx path "%path%;C:\your\path\here\bin"
$ setx path "%path%;C:\your\path\here\bin"
```
4. Refresh command line and verify installation
```shell
uwuifyy --help
$ uwuifyy --help
```
### Linux \ macOS
@ -88,43 +102,44 @@ uwuifyy --help
```shell
# Linux
tar -xf uwuifyy-x86_64-unknown-linux-gnu.tar.gz
tar -xf uwuifyy-x86_64-unknown-linux-musl.tar.gz
$ tar -xf uwuifyy-x86_64-unknown-linux-gnu.tar.gz
$ tar -xf uwuifyy-x86_64-unknown-linux-musl.tar.gz
# macOS
tar -xf uwuifyy-x86_64-apple-darwin.tar.gz
$ tar -xf uwuifyy-x86_64-apple-darwin.tar.gz
```
3. Move into `~/bin`
```shell
# Create ~/bin if it does not exist
mkdir -p ~/bin
mv uwuifyy ~/bin
$ mkdir -p ~/bin
$ mv uwuifyy ~/bin
```
4. Set permissions for executable
```shell
chmod 755 ~/bin/uwuifyy
$ chmod 755 ~/bin/uwuifyy
```
5. Update `PATH` to use globally
```shell
# Linux
echo 'export PATH=~/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
$ echo 'export PATH=~/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
# macOS
echo 'export PATH=~/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
$ echo 'export PATH=~/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile
```
6. Verify installation
```shell
uwuifyy --help
$ uwuifyy --help
uwuifyy 0.2.0
```
### Rust \ Cargo
@ -132,7 +147,7 @@ uwuifyy --help
Alternatively, if using Rust's package manager, `Cargo`, all that is needed is
```shell
cargo install uwuifyy
$ cargo install uwuifyy
```
If you do not have `Cargo` available on your machine, you can download it as part of
@ -141,6 +156,8 @@ Rust [here](https://www.rust-lang.org/tools/install)
## Usage
```commandline
$ uwuifyy --help
USAGE:
uwuifyy.exe [OPTIONS] <--text <TEXT>|--infile <FILE>>
@ -159,42 +176,15 @@ OPTIONS:
### Text Input to Text Output
```shell
uwuifyy --text "According to all known laws of aviation, there is no way a bee should be able to fly."
Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd be abwe to *screams* fwy.
```
![](examples/gifs/text-input-to-text-output.gif)
### Text Input to File Output
```shell
uwuifyy --text "According to all known laws of aviation, there is no way a bee should be able to fly." --outfile your/path/here/outfile.txt
[00:00:00] [############################################################] 104B/104B (0s) UwU'ifying Complete!
```
```text
your/path/here/outfile.txt
-------------------------------------
Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd be abwe to *screams* fwy.
```
![](examples/gifs/text-input-to-file-output.gif)
### File Input to File Output
```text
your/path/here/infile.txt
-------------------------------------
According to all known laws of aviation, there is no way a bee should be able to fly.
```
```shell
uwuifyy --infile your/path/here/infile.txt --outfile your/path/here/outfile.txt
[00:00:00] [############################################################] 85B/85B (0s) UwU'ifying Complete!
```
```text
your/path/here/outfile.txt
-------------------------------------
Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd be abwe to *screams* fwy.
```
![](examples/gifs/text-file-to-file-output.gif)
## Benchmarks
@ -206,7 +196,7 @@ Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd b
- [Dataset](https://www.kaggle.com/kewagbln/shakespeareonline)
- Size: `5.46 MiB`
- Time Taken: `1s`
- Time Taken: `< 1s`
![](examples/gifs/william-shakespeare.gif)
@ -214,7 +204,7 @@ Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd b
- [Dataset](https://www.kaggle.com/amritpal333/tokyo-olympics-2021-tweets)
- Size: `98.54 MiB`
- Time Taken: `8s`
- Time Taken: `1s`
![](examples/gifs/tokyo-2020-olympics-tweets.gif)
@ -222,7 +212,7 @@ Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd b
- [Dataset](https://www.kaggle.com/shivamb/35-million-tiktok-mobile-app-reviews)
- Size: `543.02 MiB`
- TIme Taken: `38s`
- TIme Taken: `4s`
![](examples/gifs/tiktok_app_reviews.gif)
@ -230,8 +220,8 @@ Accowding to aww knyown waws of aviation, thewe xDD is nyo way :3 a bee shouwd b
- [Dataset](https://www.kaggle.com/bittlingmayer/amazonreviews?select=train.ft.txt.bz2)
- Size: `1.6 GiB`
- Time Taken: `2:16m`
- **DISCLAIMER:** The input is a 1.6GB file and the output is a 2GB file. They are not included in the repo.
- Time Taken: `21s`
- **DISCLAIMER:** The input is a 1.6GB file and the output is a 2.2GB file. They are not included in the repo.
![](examples/gifs/amazon-ratings-reviews.gif)

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e7e4a7aef84ea7b6372a6f8843a34920859fe16d6bd0b1515cb42a050fbe8a8d
size 5075736
oid sha256:fc99a3c03cc99b715f4bb7a598c3a15eb0bdf58e40a383b9ec5084c5186897a1
size 43789

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 474 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

@ -1,38 +1,38 @@
pub const FACES_SIZE: usize = 14;
pub const FACES: [&[u8]; FACES_SIZE] = [
b"OwO",
b"UwU",
b">w<",
b"^w^",
b"^-^",
b":3",
b"x3",
b"xDD",
b";;w;;",
b">_<",
b">_>",
b"^.^",
b":33",
b"uWu",
b"OwO ",
b"UwU ",
b">w< ",
b"^w^ ",
b"^-^ ",
b":3 ",
b"x3 ",
b"xDD ",
b";;w;; ",
b">_< ",
b">_> ",
b"^.^ ",
b":33 ",
b"uWu ",
];
pub const ACTIONS_SIZE: usize = 17;
pub const ACTIONS: [&[u8]; ACTIONS_SIZE] = [
b"*notices bulge*",
b"*cries*",
b"*hugs tightly*",
b"*screams*",
b"*looks away*",
b"*blushes*",
b"*sweats*",
b"*cuddles you*",
b"*moans*",
b"*giggles shyly*",
b"*looks at you*",
b"*twerks*",
b"*sighs*",
b"*leans over*",
b"*pokes you*",
b"*teleports behind you*",
b"*shuffles closer*",
];
b"*notices bulge* ",
b"*cries* ",
b"*hugs tightly* ",
b"*screams* ",
b"*looks away* ",
b"*blushes* ",
b"*sweats* ",
b"*cuddles you* ",
b"*moans* ",
b"*giggles shyly* ",
b"*looks at you* ",
b"*twerks* ",
b"*sighs* ",
b"*leans over* ",
b"*pokes you* ",
b"*teleports behind you* ",
b"*shuffles closer* ",
];

@ -1,25 +1,30 @@
use indicatif::{ProgressBar, ProgressStyle};
use linkify::{LinkFinder, LinkKind};
use rand::{Rng, RngCore, SeedableRng};
use rand_xoshiro::{Xoshiro256Plus, Xoshiro256PlusPlus};
use std::fs::File;
use std::io::{BufWriter, Error, Write};
use std::io::{stdout, BufWriter, Error, ErrorKind, Write};
use std::path::Path;
use std::str::from_utf8_unchecked;
use indicatif::{ProgressBar, ProgressStyle};
use linkify::{LinkFinder, LinkKind};
use memmap::Mmap;
use constants::ACTIONS;
use constants::ACTIONS_SIZE;
use constants::FACES;
use constants::FACES_SIZE;
use seeder::UwUSeeder;
mod constants;
mod seeder;
macro_rules! progress_bar {
() => {{
let progress_bar = ProgressBar::new_spinner();
($bytes:expr) => {{
let progress_bar = ProgressBar::new($bytes);
progress_bar.set_style(
ProgressStyle::default_spinner().template("{spinner:.green} [{elapsed_precise}] {msg}"),
ProgressStyle::default_spinner()
.template("{spinner:.magenta} [{elapsed_precise:.bold}] {msg:.green.bold}"),
);
progress_bar.enable_steady_tick(100);
progress_bar.set_message("UwU'ifying In Progress...");
progress_bar.enable_steady_tick(30);
progress_bar
}};
@ -34,8 +39,8 @@ pub struct UwUify<'a> {
faces: f64,
actions: f64,
stutters: f64,
floating_rng: Xoshiro256Plus,
int_rng: Xoshiro256PlusPlus,
random: bool,
is_runtime: bool,
linkify: LinkFinder,
}
@ -49,8 +54,8 @@ impl<'a> Default for UwUify<'a> {
faces: 0.05,
actions: 0.125,
stutters: 0.225,
floating_rng: Xoshiro256Plus::seed_from_u64(69),
int_rng: Xoshiro256PlusPlus::seed_from_u64(420),
random: false,
is_runtime: false,
linkify: LinkFinder::new(),
}
}
@ -66,25 +71,22 @@ impl<'a> UwUify<'a> {
actions: Option<&'a str>,
stutters: Option<&'a str>,
random: bool,
is_runtime: bool,
) -> UwUify<'a> {
// I dislike this
let mut linkify = LinkFinder::new();
linkify.kinds(&[LinkKind::Email, LinkKind::Url]);
linkify.url_must_have_scheme(false);
let mut uwuify = UwUify {
text: text.unwrap_or_default(),
input: infile.unwrap_or_default(),
output: outfile.unwrap_or_default(),
random,
is_runtime,
linkify,
..Default::default()
};
if random {
uwuify.floating_rng = Xoshiro256Plus::seed_from_u64(rand::rngs::OsRng.next_u64());
uwuify.int_rng = Xoshiro256PlusPlus::seed_from_u64(rand::rngs::OsRng.next_u64());
}
if let Some(words) = words {
uwuify.words = words.parse::<f64>().unwrap();
}
@ -97,6 +99,7 @@ impl<'a> UwUify<'a> {
if let Some(stutters) = stutters {
uwuify.stutters = stutters.parse::<f64>().unwrap();
}
uwuify
}
@ -107,85 +110,79 @@ impl<'a> UwUify<'a> {
if !self.output.is_empty() {
if Path::new(&self.output).exists() {
return Err(Error::new(
std::io::ErrorKind::AlreadyExists,
ErrorKind::AlreadyExists,
format!("File '{}' already exists, aborting operation", &self.output),
));
}
let mut uwu_out_file = BufWriter::new(File::create(&self.output)?);
let uwu_progress_bar = progress_bar!();
self.uwuify_sentence(self.text, &mut uwu_out_file)?;
let uwu_progress_bar = progress_bar!(self.text.len() as u64);
self.uwuify_sentence(self.text, &mut BufWriter::new(File::create(&self.output)?))?;
uwu_progress_bar.finish_with_message("UwU'ifying Complete!");
Ok(())
} else {
#[cfg(not(test))]
let stdout = std::io::stdout();
#[cfg(not(test))]
let mut out = BufWriter::new(stdout.lock());
#[cfg(test)]
let mut out = std::io::sink();
self.uwuify_sentence(self.text, &mut out)?;
#[cfg(not(test))]
out.write_all(b"\n")?;
Ok(())
self.uwuify_sentence(self.text, &mut BufWriter::new(stdout().lock()))?;
}
} else {
// Handle File I/O
if Path::new(&self.output).exists() {
return Err(Error::new(
std::io::ErrorKind::AlreadyExists,
ErrorKind::AlreadyExists,
format!("File '{}' already exists, aborting operation", &self.output),
));
}
let uwu_progress_bar = progress_bar!();
let infile = File::open(&self.input)?;
let uwu_progress_bar = progress_bar!(infile.metadata()?.len());
self.uwuify_sentence(
unsafe {
std::str::from_utf8_unchecked(
memmap::Mmap::map(&File::open(&self.input)?)?.as_ref(),
)
},
unsafe { from_utf8_unchecked(Mmap::map(&infile)?.as_ref()) },
&mut BufWriter::new(File::create(&self.output)?),
)?;
uwu_progress_bar.finish_with_message("UwU'ifying Complete!");
Ok(())
}
Ok(())
}
pub fn uwuify_sentence<T: Write>(
&mut self,
text: &str,
out: &mut T,
) -> Result<(), std::io::Error> {
pub fn uwuify_sentence<T: Write>(&mut self, text: &str, out: &mut T) -> Result<(), Error> {
text.lines().try_for_each(|line| {
line.split_whitespace()
.map(|f| f.as_bytes())
.map(|word_str| word_str.as_bytes())
.try_for_each(|word| {
let random_value = self.floating_rng.gen_range(0.0..1.0);
if random_value <= self.faces {
out.write_all(FACES[self.int_rng.gen_range(0..FACES_SIZE)])?;
out.write_all(b" ")?;
} else if random_value <= self.actions {
out.write_all(ACTIONS[self.int_rng.gen_range(0..ACTIONS_SIZE)])?;
out.write_all(b" ")?;
} else if random_value <= self.stutters {
(0..self.int_rng.gen_range(1..2))
.into_iter()
.try_for_each(|_| {
match word[0] {
b'L' | b'R' => out.write_all(b"W"),
b'l' | b'r' => out.write_all(b"w"),
b => out.write_all(&[b]),
}?;
out.write_all(b"-")
})?;
let mut seeder = UwUSeeder::new(word, self.random);
let random_value = seeder.random_float();
if !self.is_runtime {
if random_value <= self.faces {
out.write_all(FACES[seeder.random_int(0..FACES_SIZE)])?;
} else if random_value <= self.actions {
out.write_all(ACTIONS[seeder.random_int(0..ACTIONS_SIZE)])?;
} else if random_value <= self.stutters {
match word[0] {
b'L' | b'R' => out.write_all(b"W"),
b'l' | b'r' => out.write_all(b"w"),
byte => out.write_all(&[byte]),
}?;
out.write_all(b"-")?;
}
} else {
if random_value <= self.faces {
out.write_all(FACES[seeder.random_int(0..FACES_SIZE)])?;
}
if random_value <= self.actions {
out.write_all(ACTIONS[seeder.random_int(0..ACTIONS_SIZE)])?;
}
if random_value <= self.stutters {
match word[0] {
b'L' | b'R' => out.write_all(b"W"),
b'l' | b'r' => out.write_all(b"w"),
byte => out.write_all(&[byte]),
}?;
out.write_all(b"-")?;
}
}
if self
.linkify
.links(unsafe { std::str::from_utf8_unchecked(word) })
.links(unsafe { from_utf8_unchecked(word) })
.count()
> 0
|| random_value > self.words
@ -195,13 +192,13 @@ impl<'a> UwUify<'a> {
(0..word.len()).try_for_each(|index| match word[index] {
b'L' | b'R' => out.write_all(b"W"),
b'l' | b'r' => out.write_all(b"w"),
b'E' | b'e' | b'A' | b'I' | b'O' | b'U' | b'a' | b'i' | b'o' | b'u' => {
b'A' | b'E' | b'I' | b'O' | b'U' | b'a' | b'e' | b'i' | b'o' | b'u' => {
match word.get(index - 1).unwrap_or(&word[0]) {
b'N' | b'n' => out.write_all(&[b'y', word[index]]),
_ => out.write_all(&[word[index]]),
}
}
b => out.write_all(&[b]),
byte => out.write_all(&[byte]),
})?;
}
out.write_all(b" ")
@ -209,4 +206,4 @@ impl<'a> UwUify<'a> {
out.write_all(b"\n")
})
}
}
}

@ -1,3 +1,5 @@
use std::panic::set_hook;
use clap::{Arg, ArgGroup, ErrorKind};
use uwuifyy::UwUify;
@ -99,14 +101,17 @@ macro_rules! clap_panic {
};
}
macro_rules! is_runtime {
($faces:expr, $actions:expr, $stutters:expr) => {
$faces > 0 || $actions > 0 || $stutters > 0
};
}
fn main() {
std::panic::set_hook(Box::new(|info| {
clap_panic!(info);
}));
let matches = app!().get_matches();
set_hook(Box::new(|info| clap_panic!(info)));
// panicing here ensures that the error is passed to the hook above instead of to stdout.
match UwUify::new(
let matches = app!().get_matches();
if let Err(err) = UwUify::new(
matches.value_of("text"),
matches.value_of("infile"),
matches.value_of("outfile"),
@ -115,12 +120,16 @@ fn main() {
matches.value_of("actions"),
matches.value_of("stutters"),
matches.is_present("random"),
is_runtime!(
matches.occurrences_of("faces"),
matches.occurrences_of("actions"),
matches.occurrences_of("stutters")
),
)
.uwuify()
{
Err(e) => clap_panic!(e),
_ => {}
};
clap_panic!(err);
}
}
fn is_between_zero_and_one(input: &str) -> Result<(), &'static str> {
@ -133,4 +142,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")
}
}

@ -0,0 +1,34 @@
use std::hash::Hasher;
use ahash::AHasher;
use rand::distributions::uniform::{SampleRange, SampleUniform};
use rand::{Rng, RngCore, SeedableRng};
use rand_xoshiro::Xoshiro256Plus;
pub struct UwUSeeder {
rng: Xoshiro256Plus,
}
impl UwUSeeder {
pub fn new(word: &[u8], random: bool) -> UwUSeeder {
let rand_u64 = if !random {
let mut hasher = AHasher::new_with_keys(0, 0);
hasher.write(word);
hasher.finish()
} else {
rand::rngs::OsRng::default().next_u64()
};
UwUSeeder {
rng: Xoshiro256Plus::seed_from_u64(rand_u64),
}
}
pub fn random_float(&mut self) -> f64 {
self.rng.gen_range(0.0..1.0)
}
pub fn random_int<T: SampleUniform, R: SampleRange<T>>(&mut self, range: R) -> T {
self.rng.gen_range(range)
}
}
Loading…
Cancel
Save