diff --git a/src/fps.rs b/src/fps.rs index 9c02a5e..79e130a 100644 --- a/src/fps.rs +++ b/src/fps.rs @@ -36,7 +36,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) { let arrival = fp.arrival.clone(); let alternate = fp.alternate.clone(); - let MAIN_WRAP = 68; + let main_wrap = 68; let mut route = fp.route.clone(); @@ -45,7 +45,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) { } let route_chars: Vec = route.chars().collect(); - let mut route_split = &mut route_chars.chunks(MAIN_WRAP) + let route_split = &mut route_chars.chunks(main_wrap) .map(|chunk| chunk.iter().collect::()) .collect::>(); route_split.push("".to_string()); @@ -67,7 +67,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) { } let rem_chars: Vec = rem.chars().collect(); - let mut rem_split = &mut rem_chars.chunks(MAIN_WRAP) + let rem_split = &mut rem_chars.chunks(main_wrap) .map(|chunk| chunk.iter().collect::()) .collect::>(); @@ -109,11 +109,11 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) { println!("--- FLIGHT PROGRESS STRIP READOUT FOR {} ---", callsign); println!("┌{:─>leftmost_with_padding$}┬{:─>tnd_leftmost_with_padding$}┬──────┬──────────────────────────────────────────────────────────────────────┬──────┬──────┬──────┐", "", ""); - println!("│ {: >longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ {: >4} │ {: longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ │ {: 3}{: >ft_offset$} │ {: >longest_block_2nd_leftmost$} │ │ {: longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ {: >4} │ {: longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ │ {: 3}{: >ft_offset$} │ {: >longest_block_2nd_leftmost$} │ │ {: leftmost_with_padding$}┴{:─>tnd_leftmost_with_padding$}┴──────┴──────────────────────────────────────────────────────────────────────┴──────┴──────┴──────┘", "", ""); println!("--- END FLIGHT PROGRESS STRIP READOUT FOR {} ---", callsign); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 975da57..32b8ed1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,18 @@ use std::error::Error; -use std::{io, thread}; +use std::{io}; use std::io::Write; use std::sync::Arc; use std::time::Duration; - use log::{debug, error, info, Level, warn}; use tokio::select; use tokio::sync::mpsc::{Receiver, channel}; use tokio::sync::RwLock; -use tokio::time::{sleep, sleep_until}; +use tokio::time::{sleep}; use crate::fps::print_fps; - use crate::vatlink::{vatlink_init, VATLINK_STATUS_URL, VATLINK_VERSION}; use crate::vatlink::data_v3::VATLINK_DATAV3_UPDATE_INTERVAL; use crate::vatlink::data_v3_client::DataClientV3; - pub mod vatlink; pub mod fps; @@ -33,8 +30,8 @@ async fn main() -> Result<(), Box> { info!("Retrieved vatlink initialization data, connecting to servers..."); - let mut datav3_client = DataClientV3::new(vatlink_init_data.data.v3).await?; - let mut client = Arc::new(RwLock::new(datav3_client)); + let datav3_client = DataClientV3::new(vatlink_init_data.data.v3).await?; + let client = Arc::new(RwLock::new(datav3_client)); { debug!("connected: {} pilots online", client.read().await.last_saved_data().pilots.len()); @@ -45,8 +42,8 @@ async fn main() -> Result<(), Box> { let update_task = tokio::spawn(update_main(update_client, update_shutdown_rx)); - let sector_lat: f64 = 0.0; - let sector_long: f64 = 0.0; + let _sector_lat: f64 = 0.0; + let _sector_long: f64 = 0.0; let sector_loaded: bool = false; loop { @@ -66,6 +63,7 @@ async fn main() -> Result<(), Box> { c/lat/long/range/sector - Create and load a sector file l/ - List aircraft in sector h/ - Help + q/ - Quit */ let _ = io::stdin().read_line(&mut input).is_ok(); @@ -111,6 +109,9 @@ async fn main() -> Result<(), Box> { ":" => todo!(), "c" => todo!(), "l" => todo!(), + "q" => { + break; + } "h" => { info!("vfsm: Commands:"); info!("s/callsign - Show a flight strip (s/AF1)"); @@ -122,6 +123,7 @@ async fn main() -> Result<(), Box> { info!("c/lat/long/range/sector - Create and load a sector file"); info!("l/ - List aircraft in sector"); info!("h/ - Help"); + info!("q/ - Quit"); }, _unknown => { error!("unknown command '{}'", _unknown); @@ -135,6 +137,7 @@ async fn main() -> Result<(), Box> { info!("c/lat/long/range/sector - Create and load a sector file"); info!("l/ - List aircraft in sector"); info!("h/ - Help"); + info!("q/ - Quit"); } } } @@ -149,7 +152,7 @@ async fn update_main(datav3_client: Arc>, mut rx: Receiver< loop { select! { _ = sleep(Duration::from_secs(VATLINK_DATAV3_UPDATE_INTERVAL as u64)) => (), - x = rx.recv() => { + _ = rx.recv() => { return Ok(()); // if anything happens (channel closed OR we recv a shutdown) we should exit } } diff --git a/src/vatlink/data_v3_client.rs b/src/vatlink/data_v3_client.rs index 8c2bb22..b25d3dd 100644 --- a/src/vatlink/data_v3_client.rs +++ b/src/vatlink/data_v3_client.rs @@ -3,8 +3,6 @@ use std::fmt::{Display, Formatter}; use chrono::{DateTime, Duration, Utc}; use log::{debug, trace}; use reqwest::{Client, ClientBuilder, header}; -use tokio::sync::oneshot::channel; -use tokio::task::JoinHandle; use tokio::time::sleep; use url::Url; use crate::vatlink::data_v3::VatlinkDataV3; @@ -79,11 +77,6 @@ impl DataClientV3 { } } -enum DataClientUpdateThreadMsg { - Shutdown, - UpdateNow -} - #[derive(Debug)] pub enum DataClientV3Error { NoServerProvided { options: VatlinkServer }