Skip to content

Commit

Permalink
fix packet inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Jun 20, 2024
1 parent 7514da0 commit 1ee95a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tools/packet_inspector/src/app/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{SharedState, Tab, View};
use crate::shared_state::Event;

pub(crate) struct Connection {}
pub(crate) struct Connection;

impl Tab for Connection {
fn new() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions tools/packet_inspector/src/app/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ fn draw_packet_list(ui: &mut Ui, state: &mut SharedState, packet_state: PacketSt
}

fn int_to_hex(i: i32) -> String {
format!("0x{:0>2X}", i)
format!("0x{i:0>2X}")
}

fn int_to_hex_lower(i: i32) -> String {
format!("0x{:0>2x}", i)
format!("0x{i:0>2x}")
}
8 changes: 4 additions & 4 deletions tools/packet_inspector/src/app/hex_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Tab for HexView {

impl View for HexView {
fn ui(&mut self, ui: &mut egui::Ui, state: &mut SharedState) {
let mut buf = [0u8; 16];
let mut buf = [0_u8; 16];
let mut count = 0;

let packets = state.packets.read().unwrap();
Expand All @@ -34,7 +34,7 @@ impl View for HexView {
.show(ui, |ui| {
ui.label(" ");
for i in 0..16 {
ui.label(format!("{:02X}", i));
ui.label(format!("{i:02X}"));
}
ui.end_row();
loop {
Expand All @@ -43,14 +43,14 @@ impl View for HexView {
break;
}

ui.label(format!("{:08X}", count));
ui.label(format!("{count:08X}"));
let text_color = if ui.style().visuals.dark_mode {
egui::Color32::from_gray(255)
} else {
egui::Color32::from_gray(0)
};
for b in buf.iter().take(bytes_read) {
ui.colored_label(text_color, format!("{:02X}", b));
ui.colored_label(text_color, format!("{b:02X}"));
}
for _ in 0..16 - bytes_read {
ui.label(" ");
Expand Down
16 changes: 9 additions & 7 deletions tools/packet_inspector/src/app/packet_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn draw_packet_counter(state: &SharedState, ui: &mut Ui) {
.filter(|p| state.packet_filter.get(p).unwrap_or(true))
.count();

ui.label(format!("({}/{})", filtered_packets, length));
ui.label(format!("({filtered_packets}/{length})", ));
}

fn draw_clear_button(state: &mut SharedState, ui: &mut Ui) {
Expand Down Expand Up @@ -135,14 +135,16 @@ fn draw_packet_widget(ui: &mut Ui, packet: &Packet, selected: bool) -> Response
Sense::click(),
); // this should give me a new rect inside the scroll area... no?

let fill = match selected /*packet.selected*/ {
true => Rgba::from_rgba_premultiplied(0.1, 0.1, 0.1, 0.5),
false => Rgba::from_rgba_premultiplied(0.0, 0.0, 0.0, 0.0),
let fill = if selected {
Rgba::from_rgba_premultiplied(0.1, 0.1, 0.1, 0.5)
} else {
Rgba::from_rgba_premultiplied(0.0, 0.0, 0.0, 0.0)
};

let text_color: Color32 = match selected /*packet.selected*/ {
true => Rgba::from_rgba_premultiplied(0.0, 0.0, 0.0, 1.0).into(),
false => ui.visuals().strong_text_color(),
let text_color: Color32 = if selected {
Rgba::from_rgba_premultiplied(0.0, 0.0, 0.0, 1.0).into()
} else {
ui.visuals().strong_text_color()
};

if ui.is_rect_visible(rect) {
Expand Down
12 changes: 6 additions & 6 deletions tools/packet_inspector/src/app/text_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Tab for TextView {
fn new() -> Self {
Self {
last_packet_id: None,
packet_str: "".to_string(),
packet_str: String::new(),
}
}

Expand All @@ -34,7 +34,7 @@ impl View for TextView {
let packets = state.packets.read().unwrap();
let Some(packet_index) = state.selected_packet else {
self.last_packet_id = None;
self.packet_str = "".to_string();
self.packet_str = String::new();
return;
};

Expand All @@ -43,7 +43,7 @@ impl View for TextView {

self.packet_str = match utils::packet_to_string(&packets[packet_index]) {
Ok(str) => str,
Err(err) => format!("Error: {}", err),
Err(err) => format!("Error: {err}"),
};
}

Expand Down Expand Up @@ -123,7 +123,7 @@ impl SyntectTheme {
.copied()
}

fn name(&self) -> &'static str {
fn name(self) -> &'static str {
match self {
Self::Base16EightiesDark => "Base16 Eighties (dark)",
Self::Base16MochaDark => "Base16 Mocha (dark)",
Expand All @@ -135,7 +135,7 @@ impl SyntectTheme {
}
}

fn syntect_key_name(&self) -> &'static str {
fn syntect_key_name(self) -> &'static str {
match self {
Self::Base16EightiesDark => "base16-eighties.dark",
Self::Base16MochaDark => "base16-mocha.dark",
Expand All @@ -147,7 +147,7 @@ impl SyntectTheme {
}
}

pub(crate) fn is_dark(&self) -> bool {
pub(crate) fn is_dark(self) -> bool {
match self {
Self::Base16EightiesDark
| Self::Base16MochaDark
Expand Down

0 comments on commit 1ee95a7

Please sign in to comment.