From c50be03f3d29fca9086dc165f532d44531d36f97 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Mon, 5 Dec 2022 10:04:13 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Includes=20pony=20in=20f?= =?UTF-8?q?inal=20binary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/mod.rs | 3 ++- src/helpers/ponies.rs | 35 +++++++++++++++++++++++++++++++++++ src/helpers/print.rs | 12 ++++-------- src/main.rs | 15 +++++++-------- 4 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 src/helpers/ponies.rs diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index 9548138..2ad3c2f 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -2,4 +2,5 @@ pub mod arguments; pub mod file; pub mod colors; pub mod print; -pub mod paths; \ No newline at end of file +pub mod paths; +pub mod ponies; \ No newline at end of file diff --git a/src/helpers/ponies.rs b/src/helpers/ponies.rs new file mode 100644 index 0000000..a97a4f6 --- /dev/null +++ b/src/helpers/ponies.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; + +pub struct Pony { + pub text: String, + pub lines: u16 +} + +pub fn get_pony(name: String) -> Option { + let ponies: HashMap<&str, Vec> = HashMap::from([ + ("applejack_hat_large", include_bytes!("../../ponies/applejack_hat_large.txt").to_vec()), + ("applejack_hat_large", include_bytes!("../../ponies/applejack_large.txt").to_vec()), + ("celestia_large", include_bytes!("../../ponies/celestia_large.txt").to_vec()), + ("fluttershy_large", include_bytes!("../../ponies/fluttershy_large.txt").to_vec()), + ("fluttershy", include_bytes!("../../ponies/fluttershy.txt").to_vec()), + ("luna_large", include_bytes!("../../ponies/luna_large.txt").to_vec()), + ("mcintosh_large", include_bytes!("../../ponies/mcintosh_large.txt").to_vec()), + ("pinkiepie_large", include_bytes!("../../ponies/pinkiepie_large.txt").to_vec()), + ("rainbowdash_large", include_bytes!("../../ponies/rainbowdash_large.txt").to_vec()), + ("rainbowdash", include_bytes!("../../ponies/rainbowdash.txt").to_vec()), + ("rarity", include_bytes!("../../ponies/rarity.txt").to_vec()), + ("twilight_large", include_bytes!("../../ponies/twilight_large.txt").to_vec()), + ("twilight", include_bytes!("../../ponies/twilight.txt").to_vec()), + ]); + + let pony = String::from_utf8( + ponies.get( + name.as_str() + ).unwrap().to_vec() + ).unwrap(); + + Some(Pony { + text: pony.clone(), + lines: pony.split("\n").count() as u16 + }) +} \ No newline at end of file diff --git a/src/helpers/print.rs b/src/helpers/print.rs index 1d77bf6..125dbc8 100644 --- a/src/helpers/print.rs +++ b/src/helpers/print.rs @@ -33,7 +33,6 @@ pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str) }, ActionType::Colors => { - // Print the color blocks like neofetch print("████", true, "black"); print("████", true, "red"); print("████", true, "green"); @@ -45,11 +44,8 @@ pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str) } pub fn print_ponyline(line: u16, pony: &str, color: &str) { - file_open(&format!("{}{}.txt", helpers::paths::get_pony_path(), pony).to_string()) - .lines() - .skip(line as usize) - .take(1) - .for_each(|line| { - print(line, true, color); - }); + let mut lines = pony.split("\n"); + let line = lines.nth(line as usize).unwrap().to_string(); + + print(&line, true, color); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8a7f9da..6e46063 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ -use helpers::arguments::Arguments; +use std::collections::HashMap; + +use helpers::{arguments::Arguments, ponies::get_pony}; mod helpers; mod system; @@ -109,15 +111,12 @@ const ACTIONS: [Action; 13] = [ fn main() { let args = Arguments::parse(); + let pony = get_pony(args.pony).unwrap(); - let line_count = helpers::file::get_file_linecount( - &format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony) - ); + let to_skip = ((pony.lines / 2) as f32).floor() - 6.0; - let to_skip = ((line_count / 2) as f32).floor() - 6.0; - - for i in 0..line_count { - helpers::print::print_ponyline(i, &args.pony, &args.color); + for i in 0..pony.lines { + helpers::print::print_ponyline(i, &pony.text, &args.color); let pad_i = (i as f32 - to_skip).floor();