added moonphase to output

This commit is contained in:
Nickiel12 2023-11-08 18:56:30 -08:00
parent ca4b5ffcda
commit 850c629eca

View file

@ -22,7 +22,7 @@ pub fn run_calendar(args: &CliArgs) {
Option<i32>, Option<i32>,
Option<i32>, Option<i32>,
) = (None, None, None, None, None); ) = (None, None, None, None, None);
let moonphase: Option<u32> = None; let mut moonphase: Option<u32> = None;
let mut false_empty_count = 0; let mut false_empty_count = 0;
loop { loop {
@ -42,13 +42,13 @@ pub fn run_calendar(args: &CliArgs) {
let value = buffer[21..].to_string(); let value = buffer[21..].to_string();
if value.starts_with("Moonrise") { 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") { } 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") { } 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") { } else if value.starts_with("Moonphase") {
let moonphase = match value[9..].trim()[0..2].parse::<u32>() { moonphase = match value[9..].trim()[0..2].parse::<u32>() {
Ok(val) => Some(val), Ok(val) => Some(val),
Err(e) => { Err(e) => {
if args.debug { if args.debug {
@ -58,9 +58,9 @@ pub fn run_calendar(args: &CliArgs) {
} }
}; };
} else if value.starts_with("Sunrise") { } 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") { } else if value.starts_with("Sunset") {
sunset = parse_time(value[6..].trim(), args.debug); sunset = parse_time(value[6..].trim());
} else { } else {
continue; continue;
} }
@ -80,8 +80,13 @@ pub fn run_calendar(args: &CliArgs) {
has_bg: false, has_bg: false,
is_sun: false, is_sun: false,
gradient_angle_percentage: 0.0, 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; let now_mins = (Local::now().hour() * 60 +Local::now().minute()) as i32;
if sunrise.is_none() { if sunrise.is_none() {
@ -155,7 +160,7 @@ pub fn run_calendar(args: &CliArgs) {
println!("{}", serde_json::to_string(&output_state).unwrap()); println!("{}", serde_json::to_string(&output_state).unwrap());
} }
fn parse_time(i: &str, do_debug: bool) -> Option<i32> { fn parse_time(i: &str) -> Option<i32> {
debug!("parsing: {}", i); debug!("parsing: {}", i);
let hr = match i[0..2].parse::<u32>() { let hr = match i[0..2].parse::<u32>() {
Ok(val) => val as i32, Ok(val) => val as i32,
@ -179,4 +184,5 @@ struct CalandarState {
pub has_bg: bool, pub has_bg: bool,
pub is_sun: bool, pub is_sun: bool,
pub gradient_angle_percentage: f32, pub gradient_angle_percentage: f32,
pub moonphase: u32,
} }