Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
112 changes: 58 additions & 54 deletions src/decoder/planes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{}",
Expand All @@ -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()
Expand Down
33 changes: 22 additions & 11 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,34 @@ fn read_lines<R: BufRead>(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<chrono::Utc>,
) {
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<Args>, mut planes: Planes) -> thread::JoinHandle<Result<()>> {
Expand Down