From f818ae23e18ff8e87f5005b314e17e83a08adea4 Mon Sep 17 00:00:00 2001
From: Silas Bartha <silas@soaos.dev>
Date: Tue, 1 Apr 2025 21:04:56 -0400
Subject: [PATCH] Apply clippy suggestions

---
 src/display/components.rs |  5 ++-
 src/display/resources.rs  |  4 +--
 src/input/systems.rs      |  8 ++---
 src/lib.rs                | 74 +++++++++++++++++++++++----------------
 src/widgets/commands.rs   |  4 +--
 src/widgets/systems.rs    |  2 +-
 6 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/src/display/components.rs b/src/display/components.rs
index 132c2e6..8cc4bfa 100644
--- a/src/display/components.rs
+++ b/src/display/components.rs
@@ -24,7 +24,6 @@ use ratatui::style::Style;
 // #[derive(Component, Debug)]
 // pub struct TerminalWindow;
 
-
 /// Marker component for terminal display
 #[derive(Component, Debug)]
 #[component(on_add = on_add_terminal_display)]
@@ -69,8 +68,8 @@ fn on_add_terminal_display(mut world: DeferredWorld, entity: Entity, _id: Compon
     image.resize(size);
     let image_handle = asset_server.add(image);
 
-    let headless_render_source = HeadlessRenderSource::new(&asset_server, image_handle.clone());
-    let post_process_settings = DitherPostProcessSettings::new(dither_level, &asset_server);
+    let headless_render_source = HeadlessRenderSource::new(asset_server, image_handle.clone());
+    let post_process_settings = DitherPostProcessSettings::new(dither_level, asset_server);
     world
         .commands()
         .entity(entity)
diff --git a/src/display/resources.rs b/src/display/resources.rs
index 5651d85..99d8364 100644
--- a/src/display/resources.rs
+++ b/src/display/resources.rs
@@ -20,9 +20,7 @@ impl Default for Terminal {
         stdout().execute(EnterAlternateScreen).unwrap();
         stdout().execute(EnableMouseCapture).unwrap();
         stdout()
-            .execute(PushKeyboardEnhancementFlags(
-                KeyboardEnhancementFlags::all(),
-            ))
+            .execute(PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::all()))
             .unwrap();
         enable_raw_mode().unwrap();
         let mut terminal = ratatui::Terminal::new(CrosstermBackend::new(stdout()))
diff --git a/src/input/systems.rs b/src/input/systems.rs
index 8add8b2..9a85ac8 100644
--- a/src/input/systems.rs
+++ b/src/input/systems.rs
@@ -7,11 +7,7 @@ use bevy::{
 use crossterm::event::{read, Event, KeyEvent, KeyEventKind, MediaKeyCode, ModifierKeyCode};
 use smol_str::SmolStr;
 
-use super::{
-    components::DummyWindow,
-    events::TerminalInputEvent,
-    resources::EventQueue,
-};
+use super::{components::DummyWindow, events::TerminalInputEvent, resources::EventQueue};
 
 /// Initializes event queue and thread
 pub fn setup_input(mut commands: Commands, event_queue: Res<EventQueue>) {
@@ -294,7 +290,7 @@ fn crossterm_keycode_to_bevy_key(
             35 => Some(BKey::F35),
             _ => None,
         },
-        CKey::Char(c) => Some(BKey::Character(SmolStr::from(c.encode_utf8(&mut [0;4])))),
+        CKey::Char(c) => Some(BKey::Character(SmolStr::from(c.encode_utf8(&mut [0; 4])))),
         CKey::Null => None,
         CKey::Esc => Some(BKey::Escape),
         CKey::CapsLock => Some(BKey::CapsLock),
diff --git a/src/lib.rs b/src/lib.rs
index fd7686c..e1b2e47 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,21 +3,29 @@
 //! Bevy plugin which allows a camera to render to a terminal window.
 
 use std::{
-    fs::OpenOptions, io::{stdout, Write}, path::PathBuf,
+    fs::OpenOptions,
+    io::{stdout, Write},
+    path::PathBuf,
 };
 
 use bevy::{
     log::{
         tracing_subscriber::{self, layer::SubscriberExt, EnvFilter, Layer, Registry},
         Level,
-    }, prelude::*, utils::tracing::subscriber,
+    },
+    prelude::*,
+    utils::tracing::subscriber,
 };
 use bevy_dither_post_process::DitherPostProcessPlugin;
 
 use bevy_headless_render::HeadlessRenderPlugin;
 use color_eyre::config::HookBuilder;
 pub use crossterm;
-use crossterm::{event::{DisableMouseCapture, PopKeyboardEnhancementFlags}, terminal::{disable_raw_mode, LeaveAlternateScreen}, ExecutableCommand};
+use crossterm::{
+    event::{DisableMouseCapture, PopKeyboardEnhancementFlags},
+    terminal::{disable_raw_mode, LeaveAlternateScreen},
+    ExecutableCommand,
+};
 pub use ratatui;
 
 /// Functions and types related to capture and display of world to terminal
@@ -54,7 +62,11 @@ impl Plugin for TerminalDisplayPlugin {
             .unwrap();
         let file_layer = tracing_subscriber::fmt::Layer::new()
             .with_writer(log_file)
-            .with_filter(EnvFilter::builder().parse_lossy(format!("{},{}", Level::INFO, "wgpu=error,naga=warn")));
+            .with_filter(EnvFilter::builder().parse_lossy(format!(
+                "{},{}",
+                Level::INFO,
+                "wgpu=error,naga=warn"
+            )));
         let subscriber = Registry::default().with(file_layer);
         subscriber::set_global_default(subscriber).unwrap();
 
@@ -63,43 +75,45 @@ impl Plugin for TerminalDisplayPlugin {
         let error = error.into_eyre_hook();
 
         color_eyre::eyre::set_hook(Box::new(move |e| {
-            let _ = restore_terminal();
+            restore_terminal();
             error(e)
-        })).unwrap();
+        }))
+        .unwrap();
 
         std::panic::set_hook(Box::new(move |info| {
-            let _ = restore_terminal();
+            restore_terminal();
             error!("{info}");
             panic(info);
         }));
-        
-        app.add_plugins((
-            DitherPostProcessPlugin,
-            HeadlessRenderPlugin,
-        ))
-        .add_systems(Startup, input::systems::setup_input)
-        .add_systems(
-            Update,
-            (
-                input::systems::input_handling,
-                display::systems::resize_handling,
-                display::systems::print_to_terminal,
-                widgets::systems::widget_input_handling,
-                widgets::systems::update_widgets,
-            ),
-        )
-        .insert_resource(display::resources::Terminal::default())
-        .insert_resource(input::resources::EventQueue::default())
-        .init_resource::<widgets::resources::FocusedWidget>()
-        .add_event::<input::events::TerminalInputEvent>();
+
+        app.add_plugins((DitherPostProcessPlugin, HeadlessRenderPlugin))
+            .add_systems(Startup, input::systems::setup_input)
+            .add_systems(
+                Update,
+                (
+                    input::systems::input_handling,
+                    display::systems::resize_handling,
+                    display::systems::print_to_terminal,
+                    widgets::systems::widget_input_handling,
+                    widgets::systems::update_widgets,
+                ),
+            )
+            .insert_resource(display::resources::Terminal::default())
+            .insert_resource(input::resources::EventQueue::default())
+            .init_resource::<widgets::resources::FocusedWidget>()
+            .add_event::<input::events::TerminalInputEvent>();
     }
 }
 
 fn restore_terminal() {
     let _ = disable_raw_mode();
     let mut stdout = stdout();
-    let _ = stdout.execute(PopKeyboardEnhancementFlags).unwrap()
-        .execute(DisableMouseCapture).unwrap()
-        .execute(LeaveAlternateScreen).unwrap()
+    let _ = stdout
+        .execute(PopKeyboardEnhancementFlags)
+        .unwrap()
+        .execute(DisableMouseCapture)
+        .unwrap()
+        .execute(LeaveAlternateScreen)
+        .unwrap()
         .flush();
 }
diff --git a/src/widgets/commands.rs b/src/widgets/commands.rs
index e5ee614..0727cbc 100644
--- a/src/widgets/commands.rs
+++ b/src/widgets/commands.rs
@@ -16,8 +16,8 @@ pub trait TerminalWidgetCommands {
     fn focus_widget(&mut self, widget: Entity);
 }
 
-impl<'w, 's> TerminalWidgetCommands for Commands<'w,'s> {
+impl TerminalWidgetCommands for Commands<'_, '_> {
     fn focus_widget(&mut self, widget: Entity) {
         self.queue(FocusWidgetCommand(widget));
     }
-}
\ No newline at end of file
+}
diff --git a/src/widgets/systems.rs b/src/widgets/systems.rs
index c911b0b..f95e9b5 100644
--- a/src/widgets/systems.rs
+++ b/src/widgets/systems.rs
@@ -13,7 +13,7 @@ pub fn widget_input_handling(
 ) {
     if let Some(entity) = **focused_widget {
         if let Ok(mut widget) = widgets.get_mut(entity) {
-            if widget.enabled == true {
+            if widget.enabled {
                 for event in event_reader.read() {
                     widget.widget.handle_events(event, &mut commands);
                 }