From 850c629eca7471d20191e2ea088b744c7be61b20 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Wed, 8 Nov 2023 18:56:30 -0800 Subject: [PATCH] added moonphase to output --- ewwtilities/src/calendar_background.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ewwtilities/src/calendar_background.rs b/ewwtilities/src/calendar_background.rs index 6bab721..28c5afa 100644 --- a/ewwtilities/src/calendar_background.rs +++ b/ewwtilities/src/calendar_background.rs @@ -22,7 +22,7 @@ pub fn run_calendar(args: &CliArgs) { Option, Option, ) = (None, None, None, None, None); - let moonphase: Option = None; + let mut moonphase: Option = None; let mut false_empty_count = 0; loop { @@ -42,13 +42,13 @@ pub fn run_calendar(args: &CliArgs) { let value = buffer[21..].to_string(); if value.starts_with("Moonrise") { - moonrise = parse_time(value[8..].trim(), args.debug); + moonrise = parse_time(value[8..].trim()); } else if value.starts_with("Moonset") { - moonset = parse_time(value[7..].trim(), args.debug); + moonset = parse_time(value[7..].trim()); } else if value.starts_with("Moonday") { - moonday = parse_time(value[7..].trim(), args.debug); + moonday = parse_time(value[7..].trim()); } else if value.starts_with("Moonphase") { - let moonphase = match value[9..].trim()[0..2].parse::() { + moonphase = match value[9..].trim()[0..2].parse::() { Ok(val) => Some(val), Err(e) => { if args.debug { @@ -58,9 +58,9 @@ pub fn run_calendar(args: &CliArgs) { } }; } else if value.starts_with("Sunrise") { - sunrise = parse_time(value[7..].trim(), args.debug); + sunrise = parse_time(value[7..].trim()); } else if value.starts_with("Sunset") { - sunset = parse_time(value[6..].trim(), args.debug); + sunset = parse_time(value[6..].trim()); } else { continue; } @@ -80,8 +80,13 @@ pub fn run_calendar(args: &CliArgs) { has_bg: false, is_sun: false, gradient_angle_percentage: 0.0, + moonphase: 0, }; + if moonphase.is_some() { + output_state.moonphase = moonphase.unwrap(); + } + let now_mins = (Local::now().hour() * 60 +Local::now().minute()) as i32; if sunrise.is_none() { @@ -155,7 +160,7 @@ pub fn run_calendar(args: &CliArgs) { println!("{}", serde_json::to_string(&output_state).unwrap()); } -fn parse_time(i: &str, do_debug: bool) -> Option { +fn parse_time(i: &str) -> Option { debug!("parsing: {}", i); let hr = match i[0..2].parse::() { Ok(val) => val as i32, @@ -179,4 +184,5 @@ struct CalandarState { pub has_bg: bool, pub is_sun: bool, pub gradient_angle_percentage: f32, + pub moonphase: u32, }