start major rewrite
This commit is contained in:
parent
b28d221bcf
commit
0df646844a
1250
Cargo.lock
generated
1250
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,8 +4,12 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
|
||||
clap = "2.0.0"
|
||||
# clap = "2.0.0"
|
||||
rand = { version = "0.8.4", features = ["small_rng"] }
|
||||
serde_json = "1.0"
|
||||
rust-embed = "8.3.0"
|
||||
ctrlc = "3.4.4"
|
||||
reqwest = { version = "0.11", features = ["json", "blocking"] }
|
||||
zip = "0.5"
|
||||
|
|
BIN
pokesprite.zip
Normal file
BIN
pokesprite.zip
Normal file
Binary file not shown.
41
src/bin/clap.rs
Normal file
41
src/bin/clap.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use clap::Parser;
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Name of the person to greet
|
||||
#[arg(short = 'a', long, default_value_t = String::from(""))]
|
||||
name: String,
|
||||
|
||||
// big
|
||||
/// Show a larger version of the sprite
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
big: bool,
|
||||
|
||||
// list
|
||||
/// Show a list of all pokemon names
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
list: bool,
|
||||
|
||||
// no-title
|
||||
// NOTE: clap will convert the kebab-case to snake_case
|
||||
// very smart!
|
||||
// ...but very annoying for beginners
|
||||
/// Do not display pokemon name
|
||||
#[arg(long, default_value_t = false)]
|
||||
no_title: bool,
|
||||
|
||||
// shiny
|
||||
/// Show the shiny version of the sprite
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
shiny: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
println!("no-title: {}", args.no_title);
|
||||
|
||||
println!("name: {}", args.name);
|
||||
}
|
90
src/bin/fetch.rs
Normal file
90
src/bin/fetch.rs
Normal file
|
@ -0,0 +1,90 @@
|
|||
// this fetches the sprites and downloads to the user's local machine
|
||||
// https://github.com/Vomitblood/pokesprite/archive/refs/heads/master.zip
|
||||
|
||||
// TODO: pass in url as argument and use it
|
||||
// for now, we use this as default
|
||||
const TARGET_URL: &str = "https://github.com/Vomitblood/pokesprite/archive/refs/heads/master.zip";
|
||||
const WORKING_DIRECTORY: &str = "/tmp/rustmon/";
|
||||
|
||||
fn main() {
|
||||
// // create a working directory for the program to use
|
||||
// match create_working_directory() {
|
||||
// Ok(_) => (),
|
||||
// Err(e) => eprintln!("Error creating working directory: {}", e),
|
||||
// }
|
||||
|
||||
// match download_colorscripts_archive(TARGET_URL) {
|
||||
// Ok(_) => (),
|
||||
// Err(e) => eprintln!("Error downloading file: {}", e),
|
||||
// }
|
||||
|
||||
// TODO: extract here as default unless specified in flags
|
||||
extract_colorscripts_archive(std::path::Path::new(WORKING_DIRECTORY)).unwrap();
|
||||
}
|
||||
|
||||
fn create_working_directory() -> std::io::Result<()> {
|
||||
println!("Creating working directory at {}...", WORKING_DIRECTORY);
|
||||
std::fs::create_dir(WORKING_DIRECTORY)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn download_colorscripts_archive(target_url: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Fetching colorscripts archive...");
|
||||
|
||||
let response = reqwest::blocking::get(target_url)?;
|
||||
|
||||
let mut dest = std::fs::File::create(format!("{}colorscripts.zip", WORKING_DIRECTORY))?;
|
||||
|
||||
let response_body = response.error_for_status()?.bytes()?;
|
||||
std::io::copy(&mut response_body.as_ref(), &mut dest)?;
|
||||
|
||||
println!("Downloaded pokesprite.zip");
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn extract_colorscripts_archive(extract_location: &std::path::Path) -> zip::result::ZipResult<()> {
|
||||
// let archive_file = std::fs::File::open(&archive_path)?;
|
||||
let archive_file = std::fs::File::open(std::path::Path::new(
|
||||
format!("{}colorscripts.zip", WORKING_DIRECTORY).as_str(),
|
||||
))?;
|
||||
let mut archive = zip::read::ZipArchive::new(std::io::BufReader::new(archive_file))?;
|
||||
|
||||
for i in 0..archive.len() {
|
||||
let mut file = archive.by_index(i)?;
|
||||
let file_path = std::path::Path::new(file.name());
|
||||
let parent_dir = file_path
|
||||
.parent()
|
||||
.and_then(std::path::Path::file_name)
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.unwrap_or("");
|
||||
|
||||
if (file
|
||||
.name()
|
||||
.starts_with("pokesprite-master/pokemon-gen8/regular/")
|
||||
&& parent_dir == "regular")
|
||||
|| (file
|
||||
.name()
|
||||
.starts_with("pokesprite-master/pokemon-gen8/shiny/")
|
||||
&& parent_dir == "shiny")
|
||||
{
|
||||
let file_name = file_path
|
||||
.file_name()
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.unwrap_or("");
|
||||
|
||||
let outpath = extract_location.join(parent_dir).join(file_name);
|
||||
|
||||
if !file.name().ends_with('/') {
|
||||
if let Some(p) = outpath.parent() {
|
||||
if !p.exists() {
|
||||
std::fs::create_dir_all(&p)?;
|
||||
}
|
||||
}
|
||||
let mut outfile = std::fs::File::create(&outpath)?;
|
||||
std::io::copy(&mut file, &mut outfile)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
x = 0
|
||||
|
||||
while x < 100000000:
|
||||
x += 1
|
||||
|
||||
print(x)
|
|
@ -1,12 +1,282 @@
|
|||
// fn main() {
|
||||
// let mut numbers = [1, 2, 3, 4, 5];
|
||||
use std::fs;
|
||||
|
||||
// for i in numbers.iter_mut() {
|
||||
// *i += 1;
|
||||
// println!("{}", &*i + 1);
|
||||
fn main() {
|
||||
let contents = fs::read_to_string("testing/testing.fuck").unwrap();
|
||||
let mut found: bool = false;
|
||||
|
||||
for line in contents.lines() {
|
||||
match line {
|
||||
"1" | "2" => {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// if not found
|
||||
_ => found = false,
|
||||
}
|
||||
}
|
||||
|
||||
if found == true {
|
||||
println!("Gotcha bitch");
|
||||
} else {
|
||||
println!("Never mind")
|
||||
}
|
||||
}
|
||||
|
||||
// use rand::{thread_rng, Rng};
|
||||
// use std::io::{self, stdout, Write};
|
||||
// use std::num::ParseIntError;
|
||||
|
||||
// #[derive(Debug)]
|
||||
// enum Error {
|
||||
// InvalidNumber(ParseIntError),
|
||||
// OutOfRange,
|
||||
// }
|
||||
|
||||
// fn main() {
|
||||
// loop {
|
||||
// let random_number: u8 = generate_random_number();
|
||||
// loop {
|
||||
// match get_user_number() {
|
||||
// Ok(user_number) => {
|
||||
// if user_number < random_number {
|
||||
// println!("Too low!");
|
||||
// } else if user_number > random_number {
|
||||
// println!("Too high!");
|
||||
// } else {
|
||||
// println!("You guessed the correct number!");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// Err(e) => println!("{:?}", e),
|
||||
// }
|
||||
// }
|
||||
// let user_choice = get_user_choice();
|
||||
// if user_choice != "y" {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn generate_random_number() -> u8 {
|
||||
// let mut rng = thread_rng();
|
||||
// rng.gen_range(1..101)
|
||||
// }
|
||||
|
||||
// fn get_user_number() -> Result<u8, Error> {
|
||||
// let string_input = read_user_input("Guess an integer between 1 and 100: ").unwrap();
|
||||
// match string_input.trim().parse::<u8>() {
|
||||
// Ok(value) if value >= 1 && value <= 100 => Ok(value),
|
||||
// Ok(_) => Err(Error::OutOfRange),
|
||||
// Err(e) => Err(Error::InvalidNumber(e)),
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn get_user_choice() -> String {
|
||||
// loop {
|
||||
// let choice = read_user_input("Would you like to play again? (y/n): ").unwrap();
|
||||
// if choice == "y" || choice == "n" {
|
||||
// return choice;
|
||||
// } else {
|
||||
// println!("Invalid input. Please enter 'y' or 'n'.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn read_user_input(prompt: &str) -> io::Result<String> {
|
||||
// let mut string_input = String::new();
|
||||
// print!("{}", prompt);
|
||||
// stdout().flush()?;
|
||||
// io::stdin().read_line(&mut string_input)?;
|
||||
// Ok(string_input.trim().to_string())
|
||||
// }
|
||||
|
||||
// use rand::{thread_rng, Rng};
|
||||
// use std::io::stdin;
|
||||
// use std::io::{stdout, Write};
|
||||
|
||||
// fn main() {
|
||||
// loop {
|
||||
// // generate a random number
|
||||
// let random_number: u8 = generate_random_number();
|
||||
|
||||
// // loop until they get it correct
|
||||
// loop {
|
||||
// // get the user input
|
||||
// match get_user_number() {
|
||||
// Ok(user_number) => {
|
||||
// if user_number < random_number {
|
||||
// println!("Too low!");
|
||||
// } else if user_number > random_number {
|
||||
// println!("Too high!");
|
||||
// } else {
|
||||
// println!("You guessed the correct number!");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// Err(e) => println!("{}", e),
|
||||
// }
|
||||
// }
|
||||
// let user_choice = get_user_choice();
|
||||
// if user_choice != "y" {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn generate_random_number() -> u8 {
|
||||
// let mut rng = thread_rng();
|
||||
// return rng.gen_range(1..101);
|
||||
// }
|
||||
|
||||
// fn get_user_number() -> Result<u8, String> {
|
||||
// let mut string_input = String::new();
|
||||
// print!("Guess an integer between 1 and 100: ");
|
||||
// stdout().flush().unwrap();
|
||||
// std::io::stdin().read_line(&mut string_input).unwrap();
|
||||
// let parsed_input = string_input.trim().parse::<u8>();
|
||||
// // check if the input is a valid number
|
||||
// // this is validation
|
||||
// match parsed_input {
|
||||
// Ok(value) => {
|
||||
// if value < 1 || value > 100 {
|
||||
// return Err("Please enter an integer between 1 and 100.".to_string());
|
||||
// } else {
|
||||
// return Ok(value);
|
||||
// }
|
||||
// }
|
||||
// Err(_) => {
|
||||
// return Err("Please enter an integer between 1 and 100.".to_string());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn get_user_choice() -> String {
|
||||
// loop {
|
||||
// let mut string_input = String::new();
|
||||
// print!("Would you like to play again? (y/n): ");
|
||||
// stdout().flush().unwrap();
|
||||
// stdin().read_line(&mut string_input).unwrap();
|
||||
// let choice = string_input.trim().to_string();
|
||||
// if choice == "y" || choice == "n" {
|
||||
// return choice;
|
||||
// } else {
|
||||
// println!("Invalid input. Please enter 'y' or 'n'.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// use ctrlc;
|
||||
// use rand::{thread_rng, Rng};
|
||||
// use std::io::stdin;
|
||||
// use std::io::{stdout, Write};
|
||||
// use std::sync::atomic::{AtomicBool, Ordering};
|
||||
// use std::sync::Arc;
|
||||
|
||||
// fn main() {
|
||||
// let running = Arc::new(AtomicBool::new(true));
|
||||
// let r = running.clone();
|
||||
// ctrlc::set_handler(move || {
|
||||
// r.store(false, Ordering::SeqCst);
|
||||
// println!("You cannot escape. Play the fucking game."); // Print message when Ctrl-C is pressed
|
||||
// })
|
||||
// .expect("Error setting Ctrl-C handler");
|
||||
|
||||
// while running.load(Ordering::SeqCst) {
|
||||
// // generate a random number
|
||||
// let random_number: u8 = generate_random_number();
|
||||
|
||||
// // loop until they get it correct
|
||||
// loop {
|
||||
// // get the user input
|
||||
// match get_user_number() {
|
||||
// Ok(user_number) => {
|
||||
// if user_number < random_number {
|
||||
// println!("Too low!");
|
||||
// } else if user_number > random_number {
|
||||
// println!("Too high!");
|
||||
// } else {
|
||||
// println!("You guessed the correct number!");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// Err(e) => println!("{}", e),
|
||||
// }
|
||||
// }
|
||||
// let user_choice = get_user_choice();
|
||||
// if user_choice != "y" {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn generate_random_number() -> u8 {
|
||||
// let mut rng = thread_rng();
|
||||
// return rng.gen_range(1..101);
|
||||
// }
|
||||
|
||||
// fn get_user_number() -> Result<u8, String> {
|
||||
// let mut string_input = String::new();
|
||||
// print!("Guess an integer between 1 and 100: ");
|
||||
// stdout().flush().unwrap();
|
||||
// std::io::stdin().read_line(&mut string_input).unwrap();
|
||||
// let parsed_input = string_input.trim().parse::<u8>();
|
||||
// // check if the input is a valid number
|
||||
// // this is validation
|
||||
// match parsed_input {
|
||||
// Ok(value) => {
|
||||
// if value < 1 || value > 100 {
|
||||
// return Err("Please enter an integer between 1 and 100.".to_string());
|
||||
// } else {
|
||||
// return Ok(value);
|
||||
// }
|
||||
// }
|
||||
// Err(_) => {
|
||||
// return Err("Please enter an integer between 1 and 100.".to_string());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn get_user_choice() -> String {
|
||||
// loop {
|
||||
// let mut string_input = String::new();
|
||||
// print!("Would you like to play again? (y/n): ");
|
||||
// stdout().flush().unwrap();
|
||||
// stdin().read_line(&mut string_input).unwrap();
|
||||
// let choice = string_input.trim().to_string();
|
||||
// if choice == "y" || choice == "n" {
|
||||
// return choice;
|
||||
// } else {
|
||||
// println!("Invalid input. Please enter 'y' or 'n'.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// use std::io::Write;
|
||||
|
||||
// fn main() {
|
||||
// let mut string_input = String::new();
|
||||
// print!("Enter a string: ");
|
||||
// std::io::stdout().flush().unwrap();
|
||||
// std::io::stdin().read_line(&mut string_input).unwrap();
|
||||
// let mut trimmed_string = string_input.trim().to_string().push_str("hello");
|
||||
// println!("You entered: {}", trimmed_string);
|
||||
// }
|
||||
|
||||
// fn main() {
|
||||
// let numbers = [1, 9, -2, 0, 23, 20, -7, 13, 37, 20, 56, -18, 20, 3];
|
||||
|
||||
// let max = *numbers.iter().max().unwrap();
|
||||
// let min = *numbers.iter().min().unwrap();
|
||||
|
||||
// let sum: i32 = numbers.iter().sum();
|
||||
// let mean = sum as f64 / numbers.len() as f64;
|
||||
|
||||
// assert_eq!(max, 56);
|
||||
// assert_eq!(min, -18);
|
||||
// assert_eq!(mean, 12.5);
|
||||
// }
|
||||
|
||||
// fn main() {
|
||||
// let numbers = [1, 9, -2, 0, 23, 20, -7, 13, 37, 20, 56, -18, 20, 3];
|
||||
// let mut max: i32;
|
||||
|
@ -40,26 +310,10 @@
|
|||
// }
|
||||
|
||||
// fn main() {
|
||||
// let numbers = [1, 9, -2, 0, 23, 20, -7, 13, 37, 20, 56, -18, 20, 3];
|
||||
// let mut numbers = [1, 2, 3, 4, 5];
|
||||
|
||||
// let max = *numbers.iter().max().unwrap();
|
||||
// let min = *numbers.iter().min().unwrap();
|
||||
|
||||
// let sum: i32 = numbers.iter().sum();
|
||||
// let mean = sum as f64 / numbers.len() as f64;
|
||||
|
||||
// assert_eq!(max, 56);
|
||||
// assert_eq!(min, -18);
|
||||
// assert_eq!(mean, 12.5);
|
||||
// for i in numbers.iter_mut() {
|
||||
// *i += 1;
|
||||
// println!("{}", &*i + 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let mut string_input = String::new();
|
||||
print!("Enter a string: ");
|
||||
std::io::stdout().flush().unwrap();
|
||||
std::io::stdin().read_line(&mut string_input).unwrap();
|
||||
let mut trimmed_string = string_input.trim().to_string().push_str("hello");
|
||||
println!("You entered: {}", trimmed_string);
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -38,8 +38,8 @@ fn print_file(filepath: &str) -> std::io::Result<()> {
|
|||
));
|
||||
}
|
||||
|
||||
fn list_pokemon_names() -> std::io::Result<()> {
|
||||
let pokemon_json: serde_json::Value = serde_json::from_str(POKEMON_JSON)?;
|
||||
fn list_pokemon_names() {
|
||||
let pokemon_json: serde_json::Value = serde_json::from_str(POKEMON_JSON).unwrap();
|
||||
|
||||
let mut count = 0;
|
||||
|
||||
|
@ -58,8 +58,6 @@ fn list_pokemon_names() -> std::io::Result<()> {
|
|||
println!("Total: {} Pokémons", count);
|
||||
println!("Use the --name flag to view a specific Pokémon");
|
||||
println!("Tip: Use `grep` to search for a specific Pokémon");
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn show_pokemon_by_name(
|
||||
|
@ -200,7 +198,7 @@ fn pause() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let matches = clap::App::new("pokemon-colorscripts")
|
||||
let matches = clap::App::new("rustmon")
|
||||
.about("CLI utility to print out unicode image of a pokemon in your shell")
|
||||
.arg(
|
||||
clap::Arg::with_name("list")
|
||||
|
@ -250,7 +248,7 @@ fn main() {
|
|||
.get_matches();
|
||||
|
||||
if matches.is_present("list") {
|
||||
list_pokemon_names().unwrap();
|
||||
list_pokemon_names();
|
||||
} else if matches.is_present("name") {
|
||||
let name = matches.value_of("name").unwrap();
|
||||
let no_title = matches.is_present("no-title");
|
||||
|
|
22
testing.py
Normal file
22
testing.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import random
|
||||
|
||||
# generate a random integer between 1 and 100
|
||||
random_number = random.randint(1, 100)
|
||||
|
||||
user_input = input("Guess an integer between 1 and 100: ")
|
||||
|
||||
# convert the user input to an integer
|
||||
try:
|
||||
user_input = int(user_input)
|
||||
except ValueError:
|
||||
print("Please enter a valid number")
|
||||
exit()
|
||||
|
||||
if user_input < 1 or user_input > 100:
|
||||
print("Please enter a number between 1 and 100")
|
||||
exit()
|
||||
elif random_number == user_input:
|
||||
print("You guessed correctly!")
|
||||
else:
|
||||
# use f strings to format the string
|
||||
print(f"Sorry, the number was {random_number}. Try again next time!")
|
0
testing.ts
Normal file
0
testing.ts
Normal file
8
testing/testing.fuck
Normal file
8
testing/testing.fuck
Normal file
|
@ -0,0 +1,8 @@
|
|||
asdf
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
1
|
||||
7
|
||||
69
|
Loading…
Reference in a new issue