@@ -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,21 @@ 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+ if let Ok ( uptime) = get_formated_uptime ( None ) {
193+ print ! ( "{}, " , uptime) ;
194+ } else {
195+ print ! ( "up ???? days ??:??, " ) ;
196+ }
197+
198+ print ! ( " {}" , get_formatted_nusers( ) ) ;
199+ if let Ok ( loadavg) = get_formatted_loadavg ( ) {
200+ print ! ( ", {}" , loadavg) ;
201+ }
202+ println ! ( ) ;
203+ }
204+
187205#[ cfg( any( target_os = "macos" , target_os = "windows" ) ) ]
188206fn fetch_user_info ( ) -> Result < Vec < UserInfo > , std:: io:: Error > {
189207 Ok ( Vec :: new ( ) )
@@ -200,6 +218,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
200218 match fetch_user_info ( ) {
201219 Ok ( user_info) => {
202220 if !no_header {
221+ print_uptime ( ) ;
203222 if short {
204223 println ! ( "{:<9}{:<9}{:<7}{:<}" , "USER" , "TTY" , "IDLE" , "WHAT" ) ;
205224 } else {
0 commit comments