#include #include #include #include #include "config/config.h" #include "os/os.h" struct BytesToGiB { u64 value; }; constexpr u64 GIB = 1'073'741'824; template <> struct fmt::formatter : formatter { template fn format(const BytesToGiB BTG, FmtCtx& ctx) -> typename FmtCtx::iterator { typename FmtCtx::iterator out = formatter::format(static_cast(BTG.value) / GIB, ctx); *out++ = 'G'; *out++ = 'i'; *out++ = 'B'; return out; } }; fn GetDate() -> string { const std::tm localTime = fmt::localtime(time(nullptr)); string date = fmt::format("{:%e}", localTime); if (!date.empty() && std::isspace(date.front())) date.erase(date.begin()); if (date == "1" || date == "21" || date == "31") date += "st"; else if (date == "2" || date == "22") date += "nd"; else if (date == "3" || date == "23") date += "rd"; else date += "th"; return fmt::format("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime); } fn main() -> i32 { using std::future; const Config& config = Config::getInstance(); auto weatherFuture = std::async(std::launch::async, [&config]() { return config.weather.get().getWeatherInfo(); }); auto osVersionFuture = std::async(std::launch::async, GetOSVersion); auto nowPlayingEnabledFuture = std::async(std::launch::async, [&config]() { return config.now_playing.get().enabled; }); future dateFuture = std::async(std::launch::async, GetDate); future memInfoFuture = std::async(std::launch::async, GetMemInfo); const WeatherOutput json = weatherFuture.get(); const i64 temp = std::lround(json.main.temp); const string townName = json.name; const bool nowPlayingEnabled = nowPlayingEnabledFuture.get(); const char* version = osVersionFuture.get(); const string date = dateFuture.get(); const string name = config.general.get().name.get(); const u64 mem = memInfoFuture.get(); fmt::println("Hello {}!", name); fmt::println("Today is: {}", date); fmt::println("It is {}°F in {}", temp, townName); fmt::println("Installed RAM: {:.2f}", BytesToGiB(mem)); fmt::println("{}", version); if (nowPlayingEnabled) fmt::println("{}", GetNowPlaying()); delete[] version; delete &config; }