stellui 0.2.1

Terminal UI for stargazing — displays a live star chart with sun/moon positions and weather-based seeing quality forecasts
Documentation
use serde::Deserialize;

#[derive(Debug, Default, Deserialize)]
pub struct Config {
    pub lat: Option<f64>,
    pub lon: Option<f64>,
    pub height: Option<f64>,
    pub timezone: Option<String>,
    pub max_mag: Option<f64>,
}

fn config_path() -> Option<std::path::PathBuf> {
    let mut p = config_base_dir()?;
    p.push("stellui");
    p.push("config.toml");
    Some(p)
}

fn config_base_dir() -> Option<std::path::PathBuf> {
    #[cfg(target_os = "windows")]
    return std::env::var_os("APPDATA").map(std::path::PathBuf::from);

    #[cfg(not(target_os = "windows"))]
    {
        let home = std::env::var_os("HOME")?;
        let mut p = std::path::PathBuf::from(home);
        p.push(".config");
        Some(p)
    }
}

impl Config {
    pub fn load() -> Self {
        let Some(path) = config_path() else { return Self::default() };
        let Ok(text) = std::fs::read_to_string(&path) else { return Self::default() };
        toml::from_str(&text).unwrap_or_default()
    }

}