#![warn(missing_docs)]
#![doc(
html_logo_url = "https://libcala.github.io/whoami/icon.svg",
html_favicon_url = "https://libcala.github.io/whoami/icon.svg"
)]
#[allow(missing_docs)]
#[derive(Debug)]
#[non_exhaustive]
pub enum DesktopEnv {
Gnome,
Windows,
Lxde,
Openbox,
Mate,
Xfce,
Kde,
Cinnamon,
I3,
Mac,
Ios,
Android,
Wasm,
Console,
Ubuntu,
Dive,
Fuchsia,
Redox,
Unknown(String),
}
impl std::fmt::Display for DesktopEnv {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use self::DesktopEnv::*;
if let Unknown(_) = self {
write!(f, "Unknown: ")?;
}
write!(
f,
"{}",
match self {
Gnome => "Gnome",
Windows => "Windows",
Lxde => "LXDE",
Openbox => "Openbox",
Mate => "Mate",
Xfce => "XFCE",
Kde => "KDE",
Cinnamon => "Cinnamon",
I3 => "I3",
Mac => "Mac OS",
Ios => "IOS",
Android => "Android",
Wasm => "Wasm",
Console => "Console",
Ubuntu => "Ubuntu",
Dive => "Dive",
Fuchsia => "Fuchsia",
Redox => "Redox",
Unknown(a) => &a,
}
)
}
}
#[allow(missing_docs)]
#[derive(Debug)]
#[non_exhaustive]
pub enum Platform {
Linux,
FreeBsd,
Windows,
MacOS,
Ios,
Android,
Nintendo,
Xbox,
PlayStation,
Dive,
Fuchsia,
Redox,
Unknown(String),
}
impl std::fmt::Display for Platform {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use self::Platform::*;
if let Unknown(_) = self {
write!(f, "Unknown: ")?;
}
write!(
f,
"{}",
match self {
Linux => "Linux",
FreeBsd => "Free BSD",
Windows => "Windows",
MacOS => "Mac OS",
Ios => "iOS",
Android => "Android",
Nintendo => "Nintendo",
Xbox => "XBox",
PlayStation => "PlayStation",
Dive => "Dive",
Fuchsia => "Fuchsia",
Redox => "Redox",
Unknown(a) => a,
}
)
}
}
#[cfg(all(target_os = "windows", not(target_arch = "wasm32")))]
mod windows;
#[cfg(all(target_os = "windows", not(target_arch = "wasm32")))]
use self::windows as native;
#[cfg(target_arch = "wasm32")]
mod wasm;
#[cfg(target_arch = "wasm32")]
use self::wasm as native;
#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
mod unix;
#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
use self::unix as native;
#[inline(always)]
pub fn username() -> String {
native::username()
}
#[inline(always)]
pub fn user() -> String {
native::realname()
}
#[inline(always)]
pub fn host() -> String {
native::computer()
}
#[inline(always)]
pub fn hostname() -> String {
native::hostname()
}
#[inline(always)]
pub fn os() -> String {
native::os().unwrap_or_else(|| "Unknown".to_string())
}
#[inline(always)]
pub fn env() -> DesktopEnv {
native::env()
}
#[inline(always)]
pub fn platform() -> Platform {
native::platform()
}