@@ -12,6 +12,9 @@ use libc::{sysconf, _SC_CLK_TCK};
1212#[ cfg( target_os = "linux" ) ]
1313use std:: { collections:: HashMap , fs, path:: Path , time:: SystemTime } ;
1414use std:: { process, time:: Duration } ;
15+ use uucore:: uptime:: {
16+ get_formated_uptime, get_formatted_loadavg, get_formatted_nusers, get_formatted_time,
17+ } ;
1518#[ cfg( target_os = "linux" ) ]
1619use uucore:: utmpx:: Utmpx ;
1720use uucore:: { error:: UResult , format_usage, help_about, help_usage} ;
@@ -184,6 +187,23 @@ fn fetch_user_info() -> Result<Vec<UserInfo>, std::io::Error> {
184187 Ok ( user_info_list)
185188}
186189
190+ fn print_uptime ( ) {
191+ print ! ( " {} " , get_formatted_time( ) ) ;
192+ match get_formated_uptime ( None ) {
193+ Ok ( uptime) => {
194+ print ! ( "{}, " , uptime) ;
195+ }
196+ Err ( _) => {
197+ print ! ( "up ???? days ??:??, " ) ;
198+ }
199+ }
200+ print ! ( " {}" , get_formatted_nusers( ) ) ;
201+ if let Ok ( loadavg) = get_formatted_loadavg ( ) {
202+ print ! ( ", {}" , loadavg) ;
203+ }
204+ println ! ( ) ;
205+ }
206+
187207#[ cfg( any( target_os = "macos" , target_os = "windows" ) ) ]
188208fn fetch_user_info ( ) -> Result < Vec < UserInfo > , std:: io:: Error > {
189209 Ok ( Vec :: new ( ) )
@@ -200,6 +220,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
200220 match fetch_user_info ( ) {
201221 Ok ( user_info) => {
202222 if !no_header {
223+ print_uptime ( ) ;
203224 if short {
204225 println ! ( "{:<9}{:<9}{:<7}{:<}" , "USER" , "TTY" , "IDLE" , "WHAT" ) ;
205226 } else {
0 commit comments