1#![warn(missing_docs)]
33#![doc(
34 html_logo_url = "https://libcala.github.io/whoami/icon.svg",
35 html_favicon_url = "https://libcala.github.io/whoami/icon.svg"
36)]
37
38#[allow(missing_docs)]
40pub enum DesktopEnv {
41 Gnome,
42 Windows,
43 Lxde,
44 Openbox,
45 Mate,
46 Xfce,
47 Kde,
48 Cinnamon,
49 I3,
50 Mac,
51 Ios,
52 Android,
53 Wasm,
54 Console,
55 Ubuntu,
56 Dive,
57 Fuchsia,
58 Redox,
59 Unknown(String),
60}
61
62impl std::fmt::Display for DesktopEnv {
63 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
64 use self::DesktopEnv::*;
65
66 write!(
67 f,
68 "{}",
69 match self {
70 Gnome => "Gnome".to_string(),
71 Windows => "Windows".to_string(),
72 Lxde => "LXDE".to_string(),
73 Openbox => "Openbox".to_string(),
74 Mate => "Mate".to_string(),
75 Xfce => "XFCE".to_string(),
76 Kde => "KDE".to_string(),
77 Cinnamon => "Cinnamon".to_string(),
78 I3 => "I3".to_string(),
79 Mac => "Mac OS".to_string(),
80 Ios => "IOS".to_string(),
81 Android => "Android".to_string(),
82 Wasm => "Wasm".to_string(),
83 Console => "Console".to_string(),
84 Ubuntu => "Ubuntu".to_string(),
85 Dive => "Dive".to_string(),
86 Fuchsia => "Fuchsia".to_string(),
87 Redox => "Redox".to_string(),
88 Unknown(a) => format!("Unknown: \"{}\"", a),
89 }
90 )
91 }
92}
93
94#[allow(missing_docs)]
96pub enum Platform {
97 Linux,
98 FreeBsd,
99 Windows,
100 MacOS,
101 Ios,
102 Android,
103 Nintendo,
104 Xbox,
105 PlayStation,
106 Dive,
107 Fuchsia,
108 Redox,
109 Unknown(String),
110}
111
112impl std::fmt::Display for Platform {
113 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
114 use self::Platform::*;
115
116 write!(
117 f,
118 "{}",
119 match self {
120 Linux => "Linux".to_string(),
121 FreeBsd => "Free BSD".to_string(),
122 Windows => "Windows".to_string(),
123 MacOS => "Mac OS".to_string(),
124 Ios => "iOS".to_string(),
125 Android => "Android".to_string(),
126 Nintendo => "Nintendo".to_string(),
127 Xbox => "XBox".to_string(),
128 PlayStation => "PlayStation".to_string(),
129 Dive => "Dive".to_string(),
130 Fuchsia => "Fuchsia".to_string(),
131 Redox => "Redox".to_string(),
132 Unknown(a) => format!("Unknown: \"{}\"", a),
133 }
134 )
135 }
136}
137
138#[cfg(target_os = "windows")]
139mod windows;
140#[cfg(target_os = "windows")]
141use self::windows as native;
142#[cfg(target_arch = "wasm32")]
143mod wasm;
144#[cfg(target_arch = "wasm32")]
145use self::wasm as native;
146#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
147mod unix;
148#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
149use self::unix as native;
150
151#[inline(always)]
153pub fn username() -> String {
154 native::username()
155}
156
157#[inline(always)]
159pub fn user() -> String {
160 native::realname()
161}
162
163#[inline(always)]
165pub fn host() -> String {
166 native::computer()
167}
168
169#[inline(always)]
171pub fn hostname() -> String {
172 native::hostname()
173}
174
175#[inline(always)]
179pub fn os() -> String {
180 native::os()
181}
182
183#[inline(always)]
187pub fn env() -> DesktopEnv {
188 native::env()
189}
190
191#[inline(always)]
193pub fn platform() -> Platform {
194 native::platform()
195}