Satellite tracking TUI using ratatui
at main 2.1 kB view raw
1use chrono::{DateTime, Utc}; 2use crate::location::FLocation; 3use ratatui::{style::Color, text::Line, widgets::{ListItem, ListState}}; 4 5#[derive(Clone,Debug)] 6pub enum CurrentScreen { 7 Map, 8 CityChoice, 9 Exiting 10} 11 12 13#[derive(Debug,Clone,PartialEq)] 14pub struct City { 15 pub name: String, 16 pub long: f32, 17 pub lat: f32, 18} 19 20impl From<&City> for ListItem<'_> { 21 fn from(value: &City) -> Self { 22 let line = Line::styled( 23 format!("{} : {} W/E , {} N/S",value.name,value.long,value.lat), 24 Color::Gray); 25 ListItem::new(line) 26 } 27 28} 29 30/// uuuhhh future feature. 31/// checking if the currently chosen city is within the ISS's visibility (https://tangled.sh/@technoduck.me/iss_locator.rs) 32pub const CITIES:[(&str,f32,f32);9] = [ 33 ("Montreal",-72.2,45.5), 34 ("Tokyo",139.766,35.66), 35 ("Delhi",77.216,28.6), 36 ("Shanghai",121.45,31.22), 37 ("São Paulo",-46.65,-23.55), 38 ("Mexico City",-99.12,19.45), 39 ("Cairo",31.233,30.03), 40 ("New York",-74.0,40.7), 41 ("London",0.03,51.55) 42]; 43 44impl From<&(&str,f32,f32)> for City { 45 fn from(value: &(&str,f32,f32)) -> Self { 46 City { name: value.0.to_string(), long: value.1, lat: value.2 } 47 } 48} 49 50#[derive(Clone,Debug)] 51pub struct CityList { 52 pub cities: Vec<City>, 53 pub state: ListState 54} 55 56 57 58 59#[derive(Clone,Debug)] 60pub struct App { 61 pub current_screen: CurrentScreen, 62 pub cities: CityList, 63 pub iss_location: Option<FLocation>, 64 pub getting_location: bool, 65 pub iss_constant: Option<sgp4::Constants>, 66 pub iss_constant_epoch: Option<DateTime<Utc>> 67} 68 69 70impl App { 71 pub fn new() -> App { 72 73 let cities_vec:Vec<City> = CITIES.iter() 74 .map(|f| City::from(f)) 75 .collect(); 76 let cities:CityList = CityList { cities: cities_vec, state: ListState::default() }; 77 78 App { 79 current_screen:CurrentScreen::Map, 80 cities, 81 iss_location: None, 82 getting_location: false, 83 iss_constant: None, 84 iss_constant_epoch: None 85 } 86 } 87 88}