From 0791b658941f7dfc785bc67ccbfdedae520a5dce Mon Sep 17 00:00:00 2001 From: Anton Sidorov Date: Fri, 7 Feb 2025 05:34:03 +0000 Subject: [PATCH 1/2] cleanup: --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- src/reader.rs | 33 ++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bfbfae..c94849e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,9 +90,9 @@ checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "cc" -version = "1.2.11" +version = "1.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4730490333d58093109dc02c23174c3f4d490998c3fed3cc8e82d57afedb9cf" +checksum = "755717a7de9ec452bf7f3f1a3099085deabd7f2962b861dae91ecd7a365903d2" dependencies = [ "shlex", ] @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" [[package]] name = "proc-macro2" diff --git a/Cargo.toml b/Cargo.toml index 44a6121..930c33b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,10 @@ edition = "2021" [dependencies] chrono = "0.4.39" -clap = { version = "4.5.23", features = ["derive"] } +clap = { version = "4.5.28", features = ["derive"] } env_logger = "0.11.6" lazy_static = "1.5.0" -log = "0.4.22" +log = "0.4.25" [profile.release] panic = "abort" diff --git a/src/reader.rs b/src/reader.rs index d61f49d..de6ebdb 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -73,23 +73,34 @@ fn read_lines(reader: R, args: &Args, planes: &mut Planes) -> Result } if !display_flags.quiet() && app_state.is_time_to_refresh(&now, args.update) { - clear_screen(); + display_planes(args, planes, &display_flags, &headers, &mut app_state, now); + } + } + Ok(()) +} - headers.print_header(); - headers.print_separator(); +fn display_planes( + args: &Args, + planes: &mut Planes, + display_flags: &DisplayFlags, + headers: &LegendHeaders, + app_state: &mut AppCounters, + now: chrono::DateTime, +) { + clear_screen(); - planes.print(args, &display_flags); + headers.print_header(); + headers.print_separator(); - headers.print_separator(); + planes.print(args, display_flags); - if args.count_df { - app_state.print_df_count_line(); - } + headers.print_separator(); - app_state.reset_timestamp(now); - } + if args.count_df { + app_state.print_df_count_line(); } - Ok(()) + + app_state.reset_timestamp(now); } pub fn spawn_reader_thread(args: Arc, mut planes: Planes) -> thread::JoinHandle> { From 90e6eaab69822dd4f0f0308286e287465d3af928 Mon Sep 17 00:00:00 2001 From: Anton Sidorov Date: Fri, 7 Feb 2025 05:43:20 +0000 Subject: [PATCH 2/2] cleanup: --- src/decoder/planes.rs | 112 ++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/src/decoder/planes.rs b/src/decoder/planes.rs index 8e200cb..2b2d46f 100644 --- a/src/decoder/planes.rs +++ b/src/decoder/planes.rs @@ -73,60 +73,7 @@ impl Planes { .expect("Failed to acquire read lock on planes."); let mut planes_vector: Vec<(&u32, &Plane)> = planes.iter().collect(); planes_vector.sort_by_cached_key(|&(k, _)| k); - for order_by in &args.order_by { - for c in order_by.chars() { - match c { - 'a' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.altitude); - } - 'A' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.altitude); - planes_vector.reverse(); - } - 'c' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.category); - } - 'C' => { - planes_vector.sort_by_cached_key(|&(_, p)| { - -(((p.category.0 << 1) | p.category.1) as i32) - }); - } - 'd' => { - planes_vector.sort_by_cached_key(|&(_, p)| { - p.distance_from_observer.unwrap_or(0.0) as i32 - }); - } - 'D' => { - planes_vector.sort_by_cached_key(|&(_, p)| { - p.distance_from_observer.unwrap_or(0.0) as i32 - }); - planes_vector.reverse(); - } - 'N' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.lat as i32); - } - 'S' => { - planes_vector.sort_by_cached_key(|&(_, p)| -(p.lat as i32)); - } - 'W' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.lon as i32); - } - 'E' => { - planes_vector.sort_by_cached_key(|&(_, p)| -(p.lon as i32)); - } - 's' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.squawk); - } - 'V' => { - planes_vector.sort_by_cached_key(|&(_, p)| -(p.vrate.unwrap_or(0))); - } - 'v' => { - planes_vector.sort_by_cached_key(|&(_, p)| p.vrate.unwrap_or(0)); - } - _ => {} - } - } - } + sort_printed_planes(args, &mut planes_vector); print!( "{}", @@ -137,6 +84,63 @@ impl Planes { } } +fn sort_printed_planes(args: &Args, planes_vector: &mut Vec<(&u32, &Plane)>) { + for order_by in &args.order_by { + for c in order_by.chars() { + match c { + 'a' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.altitude); + } + 'A' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.altitude); + planes_vector.reverse(); + } + 'c' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.category); + } + 'C' => { + planes_vector.sort_by_cached_key(|&(_, p)| { + -(((p.category.0 << 1) | p.category.1) as i32) + }); + } + 'd' => { + planes_vector.sort_by_cached_key(|&(_, p)| { + p.distance_from_observer.unwrap_or(0.0) as i32 + }); + } + 'D' => { + planes_vector.sort_by_cached_key(|&(_, p)| { + p.distance_from_observer.unwrap_or(0.0) as i32 + }); + planes_vector.reverse(); + } + 'N' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.lat as i32); + } + 'S' => { + planes_vector.sort_by_cached_key(|&(_, p)| -(p.lat as i32)); + } + 'W' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.lon as i32); + } + 'E' => { + planes_vector.sort_by_cached_key(|&(_, p)| -(p.lon as i32)); + } + 's' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.squawk); + } + 'V' => { + planes_vector.sort_by_cached_key(|&(_, p)| -(p.vrate.unwrap_or(0))); + } + 'v' => { + planes_vector.sort_by_cached_key(|&(_, p)| p.vrate.unwrap_or(0)); + } + _ => {} + } + } + } +} + impl Default for Planes { fn default() -> Self { Self::new()