#![warn(missing_docs)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/libcala/whoami/main/res/icon.svg",
html_favicon_url = "https://raw.githubusercontent.com/libcala/whoami/main/res/icon.svg"
)]
use std::ffi::OsString;
#[allow(missing_docs)]
#[derive(Debug)]
#[non_exhaustive]
pub enum DesktopEnv {
Gnome,
Windows,
Lxde,
Openbox,
Mate,
Xfce,
Kde,
Cinnamon,
I3,
Aqua,
Ios,
Android,
WebBrowser,
Console,
Ubuntu,
Ermine,
Orbital,
Unknown(String),
}
impl std::fmt::Display for DesktopEnv {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let DesktopEnv::Unknown(_) = self {
write!(f, "Unknown: ")?;
}
write!(
f,
"{}",
match self {
DesktopEnv::Gnome => "Gnome",
DesktopEnv::Windows => "Windows",
DesktopEnv::Lxde => "LXDE",
DesktopEnv::Openbox => "Openbox",
DesktopEnv::Mate => "Mate",
DesktopEnv::Xfce => "XFCE",
DesktopEnv::Kde => "KDE",
DesktopEnv::Cinnamon => "Cinnamon",
DesktopEnv::I3 => "I3",
DesktopEnv::Aqua => "Aqua",
DesktopEnv::Ios => "IOS",
DesktopEnv::Android => "Android",
DesktopEnv::WebBrowser => "Web Browser",
DesktopEnv::Console => "Console",
DesktopEnv::Ubuntu => "Ubuntu",
DesktopEnv::Ermine => "Ermine",
DesktopEnv::Orbital => "Orbital",
DesktopEnv::Unknown(a) => &a,
}
)
}
}
#[allow(missing_docs)]
#[derive(Debug)]
#[non_exhaustive]
pub enum Platform {
Linux,
Bsd,
Windows,
MacOS,
Ios,
Android,
Nintendo,
Xbox,
PlayStation,
Fuchsia,
Redox,
Unknown(String),
}
impl std::fmt::Display for Platform {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Platform::Unknown(_) = self {
write!(f, "Unknown: ")?;
}
write!(
f,
"{}",
match self {
Platform::Linux => "Linux",
Platform::Bsd => "BSD",
Platform::Windows => "Windows",
Platform::MacOS => "Mac OS",
Platform::Ios => "iOS",
Platform::Android => "Android",
Platform::Nintendo => "Nintendo",
Platform::Xbox => "XBox",
Platform::PlayStation => "PlayStation",
Platform::Fuchsia => "Fuchsia",
Platform::Redox => "Redox",
Platform::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 username_os() -> OsString {
native::username_os()
}
#[inline(always)]
pub fn realname() -> String {
native::realname()
}
#[inline(always)]
pub fn realname_os() -> OsString {
native::realname_os()
}
#[inline(always)]
pub fn devicename() -> String {
native::devicename()
}
#[inline(always)]
pub fn devicename_os() -> OsString {
native::devicename_os()
}
#[inline(always)]
pub fn hostname() -> String {
native::hostname()
}
#[inline(always)]
pub fn hostname_os() -> OsString {
native::hostname_os()
}
#[inline(always)]
pub fn distro() -> String {
native::distro().unwrap_or_else(|| "Unknown".to_string())
}
#[inline(always)]
pub fn distro_os() -> OsString {
native::distro_os().unwrap_or_else(|| "Unknown".to_string().into())
}
#[inline(always)]
pub fn desktop_env() -> DesktopEnv {
native::desktop_env()
}
#[inline(always)]
pub fn platform() -> Platform {
native::platform()
}
#[inline(always)]
pub fn lang() -> impl Iterator<Item = String> {
native::lang()
}