1111// - implement -T, -u options
1212//
1313
14+ use std:: path:: PathBuf ;
15+
1416use clap:: Parser ;
1517use gettextrs:: { bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory } ;
16- use plib:: { platform , PROJECT_NAME } ;
17- use std :: path :: PathBuf ;
18+ use plib:: utmpx :: Utmpx ;
19+ use plib :: { curuser , platform , utmpx } ;
1820
1921/// who - display who is on the system
2022#[ derive( Parser ) ]
@@ -86,7 +88,7 @@ fn fmt_timestamp(ts: libc::time_t) -> String {
8688 dt. format ( "%b %e %H:%M" ) . to_string ( )
8789}
8890
89- fn print_fmt_short ( entry : & plib :: utmpx :: Utmpx , line : & str ) {
91+ fn print_fmt_short ( entry : & Utmpx , line : & str ) {
9092 println ! (
9193 "{:<16} {:<12} {}" ,
9294 entry. user,
@@ -95,7 +97,7 @@ fn print_fmt_short(entry: &plib::utmpx::Utmpx, line: &str) {
9597 ) ;
9698}
9799
98- fn print_fmt_term ( entry : & plib :: utmpx :: Utmpx , line : & str ) {
100+ fn print_fmt_term ( entry : & Utmpx , line : & str ) {
99101 let term_state = '?' ;
100102 println ! (
101103 "{:<16} {} {:<12} {}" ,
@@ -107,15 +109,15 @@ fn print_fmt_term(entry: &plib::utmpx::Utmpx, line: &str) {
107109}
108110
109111fn current_terminal ( ) -> String {
110- let s = plib :: curuser:: tty ( ) ;
112+ let s = curuser:: tty ( ) ;
111113 if let Some ( st) = s. strip_prefix ( "/dev/" ) {
112114 st. to_owned ( )
113115 } else {
114116 s
115117 }
116118}
117119
118- fn print_entry ( args : & Args , entry : & plib :: utmpx :: Utmpx ) {
120+ fn print_entry ( args : & Args , entry : & Utmpx ) {
119121 // Skip if current_terminal option is set and this entry is not for the current terminal
120122 if args. current_terminal {
121123 let current_tty = current_terminal ( ) ;
@@ -161,15 +163,15 @@ fn show_utmpx_entries(args: &Args) {
161163 ) ;
162164 }
163165
164- let entries = plib :: utmpx:: load ( ) ;
166+ let entries = utmpx:: load ( ) ;
165167 for entry in & entries {
166168 print_entry ( args, entry) ;
167169 }
168170}
169171
170172fn show_utmpx_summary ( ) {
171173 let mut count = 0 ;
172- let entries = plib :: utmpx:: load ( ) ;
174+ let entries = utmpx:: load ( ) ;
173175 for entry in & entries {
174176 if !entry. user . is_empty ( ) {
175177 println ! ( "{}" , entry. user) ;
@@ -181,7 +183,10 @@ fn show_utmpx_summary() {
181183}
182184
183185fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
184- // manual CLI parse for special "who am i" case
186+ setlocale ( LocaleCategory :: LcAll , "" ) ;
187+ textdomain ( env ! ( "PROJECT_NAME" ) ) ?;
188+ bind_textdomain_codeset ( env ! ( "PROJECT_NAME" ) , "UTF-8" ) ?;
189+
185190 let args: Vec < String > = std:: env:: args ( ) . skip ( 1 ) . collect ( ) ;
186191 let am_i = args. len ( ) == 2 && args[ 0 ] == "am" && ( args[ 1 ] == "i" || args[ 1 ] == "I" ) ;
187192
@@ -207,10 +212,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
207212 args. userproc = true ;
208213 }
209214
210- setlocale ( LocaleCategory :: LcAll , "" ) ;
211- textdomain ( PROJECT_NAME ) ?;
212- bind_textdomain_codeset ( PROJECT_NAME , "UTF-8" ) ?;
213-
214215 let mut exit_code = 0 ;
215216
216217 if args. file . is_some ( ) {
0 commit comments