diff --git a/src/cli.rs b/src/cli.rs index 0925980..0e82f74 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -54,4 +54,4 @@ pub struct GuiOptions { help = "add spacers between tile rows to simulate gaps in real display" )] pub spacers: bool, -} \ No newline at end of file +} diff --git a/src/cp437_font.rs b/src/cp437_font.rs index dbb99d7..d259c98 100644 --- a/src/cp437_font.rs +++ b/src/cp437_font.rs @@ -1,5 +1,5 @@ -use std::ops::Index; use servicepoint::{Bitmap, DataRef, TILE_SIZE}; +use std::ops::Index; const CHAR_COUNT: usize = u8::MAX as usize + 1; diff --git a/src/execute_command.rs b/src/execute_command.rs index 7a2bf45..4b74fcf 100644 --- a/src/execute_command.rs +++ b/src/execute_command.rs @@ -1,5 +1,5 @@ -use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success}; use crate::cp437_font::Cp437Font; +use crate::execute_command::ExecutionResult::{Failure, Shutdown, Success}; use crate::font_renderer::FontRenderer8x8; use log::{debug, error, info, trace, warn}; use servicepoint::{ diff --git a/src/font_renderer.rs b/src/font_renderer.rs index 64e966e..7ec20bb 100644 --- a/src/font_renderer.rs +++ b/src/font_renderer.rs @@ -60,7 +60,10 @@ impl FontRenderer8x8 { pub fn from_name(family_name: String) -> Self { let font = SystemSource::new() - .select_best_match(&[FamilyName::Title(family_name)], &Properties::new()) + .select_best_match( + &[FamilyName::Title(family_name)], + &Properties::new(), + ) .unwrap() .load() .unwrap(); diff --git a/src/gui.rs b/src/gui.rs index 562f7d6..424d128 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -12,7 +12,7 @@ use winit::event_loop::ActiveEventLoop; use winit::keyboard::KeyCode::KeyC; use winit::window::{Window, WindowId}; -use crate::cli::{GuiOptions}; +use crate::cli::GuiOptions; pub struct Gui<'t> { display: &'t RwLock, @@ -76,7 +76,8 @@ impl<'t> Gui<'t> { fn draw_frame(&self, frame: &mut ChunksExactMut) { let display = self.display.read().unwrap(); let luma = self.luma.read().unwrap(); - let brightness_scale = (u8::MAX as f32) / (u8::from(Brightness::MAX) as f32); + let brightness_scale = + (u8::MAX as f32) / (u8::from(Brightness::MAX) as f32); for tile_y in 0..TILE_HEIGHT { if self.options.spacers && tile_y != 0 { @@ -90,11 +91,16 @@ impl<'t> Gui<'t> { for y in start_y..start_y + TILE_SIZE { for tile_x in 0..TILE_WIDTH { let brightness = u8::from(luma.get(tile_x, tile_y)); - let brightness = (brightness_scale * brightness as f32) as u8; + let brightness = + (brightness_scale * brightness as f32) as u8; let on_color = self.get_on_color(brightness); let start_x = tile_x * TILE_SIZE; for x in start_x..start_x + TILE_SIZE { - let color = if display.get(x, y) { on_color } else { OFF_COLOR }; + let color = if display.get(x, y) { + on_color + } else { + OFF_COLOR + }; let pixel = frame.next().unwrap(); pixel.copy_from_slice(&color); } diff --git a/src/main.rs b/src/main.rs index 7832f9e..4ea5b7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,12 @@ #![deny(clippy::all)] +use crate::font_renderer::FontRenderer8x8; use crate::{ execute_command::{CommandExecutor, ExecutionResult}, gui::{AppEvents, Gui}, }; use clap::Parser; +use cli::Cli; use log::{error, info, warn, LevelFilter}; use servicepoint::*; use std::io::ErrorKind; @@ -12,14 +14,12 @@ use std::net::UdpSocket; use std::sync::{mpsc, RwLock}; use std::time::Duration; use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy}; -use cli::Cli; -use crate::font_renderer::FontRenderer8x8; -mod execute_command; +mod cli; mod cp437_font; +mod execute_command; mod font_renderer; mod gui; -mod cli; const BUF_SIZE: usize = 8985; @@ -49,7 +49,9 @@ fn main() { event_loop.set_control_flow(ControlFlow::Wait); let event_proxy = event_loop.create_proxy(); - let font_renderer = cli.font.map(move |font| FontRenderer8x8::from_name(font)) + let font_renderer = cli + .font + .map(move |font| FontRenderer8x8::from_name(font)) .unwrap_or_else(move || FontRenderer8x8::default()); let command_executor = CommandExecutor::new(&display, &luma, font_renderer); @@ -59,7 +61,9 @@ fn main() { while stop_udp_rx.try_recv().is_err() { receive_into_buf(&socket, &mut buf) .and_then(move |amount| command_from_slice(&buf[..amount])) - .map(|cmd| handle_command(&event_proxy, &command_executor, cmd)); + .map(|cmd| { + handle_command(&event_proxy, &command_executor, cmd) + }); } }); event_loop @@ -68,7 +72,11 @@ fn main() { }); } -fn handle_command(event_proxy: &EventLoopProxy, command_executor: &CommandExecutor, command: Command) { +fn handle_command( + event_proxy: &EventLoopProxy, + command_executor: &CommandExecutor, + command: Command, +) { match command_executor.execute(command) { ExecutionResult::Success => { event_proxy @@ -100,10 +108,14 @@ fn init_logging(debug: bool) { fn command_from_slice(slice: &[u8]) -> Option { let packet = servicepoint::Packet::try_from(slice) - .inspect_err(|_| warn!("could not load packet with length {}", slice.len())) + .inspect_err(|_| { + warn!("could not load packet with length {}", slice.len()) + }) .ok()?; Command::try_from(packet) - .inspect_err(move |err| warn!("could not read command for packet: {:?}", err)) + .inspect_err(move |err| { + warn!("could not read command for packet: {:?}", err) + }) .ok() }