From 3c431ccac3fd801610f3b5dc1364a3e557d7eea2 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 17 Jun 2022 21:59:27 +0200 Subject: [PATCH] fix: cleanup main() --- src/main.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 53b00b7..dc97b79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,29 +181,20 @@ fn main() -> anyhow::Result<()> { first_strand_index: 8, }; - match args.action { + let image = match args.action { Action::Solid { color } => { - let image = RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into()); - let frame_num: u32 = rand::thread_rng().gen(); - send_frame(&socket, layout, frame_num, &image)?; - } - Action::Clear => { - let image = RgbImage::new(layout.width_px(), layout.height_px()); - let frame_num: u32 = rand::thread_rng().gen(); - send_frame(&socket, layout, frame_num, &image)?; - } - Action::Image { path } => { - let image = ImageReader::open(path)? - .decode()? - .resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian) - .into_rgb8(); - let frame_num: u32 = rand::thread_rng().gen(); - send_frame(&socket, layout, frame_num, &image)?; + RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into()) } + Action::Clear => RgbImage::new(layout.width_px(), layout.height_px()), + Action::Image { path } => ImageReader::open(path)? + .decode()? + .resize_to_fill(layout.width_px(), layout.height_px(), FilterType::Gaussian) + .into_rgb8(), Action::Rainbow => { print!("{}", termion::clear::All); - for frame in 0.. { + let mut frame = 0; + loop { let image = rainbow(layout, frame); print_image(&image); @@ -212,9 +203,13 @@ fn main() -> anyhow::Result<()> { send_frame(&socket, layout, frame_num, &image)?; sleep(Duration::from_millis(16)); + frame += 1; } } - } + }; + + let frame_num: u32 = rand::thread_rng().gen(); + send_frame(&socket, layout, frame_num, &image)?; Ok(()) }