From 8fd7c9b1a2a29e7ff949e54369c204968f475f14 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Fri, 2 Dec 2022 15:47:52 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Padding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/file.rs | 9 +++++++++ src/main.rs | 23 ++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/helpers/file.rs b/src/helpers/file.rs index a9059c2..76b537c 100644 --- a/src/helpers/file.rs +++ b/src/helpers/file.rs @@ -7,4 +7,13 @@ pub fn file_open(path: &str) -> String { file.read_to_string(&mut temp_buf).unwrap(); temp_buf +} + +pub fn get_file_linecount(path: &str) -> u16 { + let mut temp_buf: String = String::new(); + + let mut file = File::open(path).unwrap(); + file.read_to_string(&mut temp_buf).unwrap(); + + temp_buf.lines().count() as u16 } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9a9e209..9d9663b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ mod helpers; mod system; mod args; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub enum ActionType { HostInfo, Delimiter, @@ -13,6 +13,7 @@ pub enum ActionType { Colors } +#[derive(Debug)] pub struct Action<'a> { action_type: ActionType, name: Option<&'a str>, @@ -85,15 +86,23 @@ const ACTIONS: [Action; 12] = [ fn main() { let args: Args = Args::parse(); - for i in 0..50 { + let line_count = helpers::file::get_file_linecount( + &format!("ponies/{}.txt", &args.pony) + ); + + 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); - if ACTIONS.get(i as usize).is_none() { + let pad_i = (i as f32 - to_skip).floor(); + + if ACTIONS.get(pad_i as usize).is_none() || pad_i < 0.0 { println!(); continue; } - match ACTIONS[i as usize].action_type { + match ACTIONS[pad_i as usize].action_type { ActionType::HostInfo => { helpers::print::print_detail( &system::host::get_user(), @@ -114,9 +123,9 @@ fn main() { ActionType::Details => { helpers::print::print_detail( - ACTIONS[i as usize].name.unwrap(), - ACTIONS[i as usize].func.unwrap()(), - ACTIONS[i as usize].action_type, + ACTIONS[pad_i as usize].name.unwrap(), + ACTIONS[pad_i as usize].func.unwrap()(), + ACTIONS[pad_i as usize].action_type, args.color.as_str() ); },