Add user feedback loop and header comments

This commit is contained in:
James Musselman 2024-02-13 11:52:44 -06:00
parent e59ea4851f
commit 7e7e2d10e4
Signed by: Musselman
GPG key ID: 1DAEFF35ECB5D6DB

View file

@ -1,3 +1,7 @@
// James Musselman
// Released under AGPL-v3.0-or-later
// This program generates a version name using a random alliterative animal and adjective from their respective files.
use std::fs::File; use std::fs::File;
use std::io::{self, BufRead}; use std::io::{self, BufRead};
use inflector::Inflector; use inflector::Inflector;
@ -30,6 +34,7 @@ fn main() -> io::Result<()> {
let mut rng = thread_rng(); let mut rng = thread_rng();
loop { loop {
// Generate random lines // Generate random lines
let animal = animal_lines.choose(&mut rng).unwrap(); let animal = animal_lines.choose(&mut rng).unwrap();
@ -38,8 +43,25 @@ fn main() -> io::Result<()> {
// Check if the first character of adjective and animal match // Check if the first character of adjective and animal match
if animal.chars().next() == adjective.chars().next() { if animal.chars().next() == adjective.chars().next() {
// Print the matched version name // Print the matched version name
println!("Your new Version Name:\n{} {}", adjective, animal); println!("\n{} {}\n", adjective, animal);
break;
println!("Are you satisfied? (y/n)");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
// Trim leading/trailing whitespaces
let input = input.trim();
if input.eq_ignore_ascii_case("y") {
break;
} else if input.eq_ignore_ascii_case("n") {
println!("Generating new output...")
} else {
println!("Invalid input. Please enter 'y' or 'n'.");
continue;
}
} }
} }