1010use chrono:: Local ;
1111use clap:: Parser ;
1212use gettextrs:: { bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory } ;
13- use plib:: { platform, PROJECT_NAME } ;
14- use std:: fs;
15- use std:: fs:: OpenOptions ;
13+ use plib:: { curuser, platform, utmpx} ;
14+ use std:: fs:: { self , OpenOptions } ;
1615use std:: io:: { self , BufRead , Write } ;
1716use std:: os:: unix:: fs:: MetadataExt ;
1817use std:: os:: unix:: fs:: PermissionsExt ;
@@ -38,7 +37,7 @@ struct Args {
3837// Select terminal in an implementation-defined manner and return terminal
3938// Print an informational message about the chosen terminal
4039fn select_terminal ( user_name : & str ) -> String {
41- let entries = plib :: utmpx:: load ( ) ;
40+ let entries = utmpx:: load ( ) ;
4241
4342 // Filter the entries to find terminals for the specified user
4443 let user_entries: Vec < _ > = entries
@@ -106,15 +105,6 @@ fn check_write_permission(terminal: &str) -> bool {
106105 }
107106}
108107
109- // Retrieve the sender's login ID
110- fn get_login_id ( ) -> String {
111- plib:: curuser:: login_name ( )
112- }
113-
114- fn get_terminal ( ) -> String {
115- plib:: curuser:: tty ( )
116- }
117-
118108fn get_current_date ( ) -> String {
119109 // Retrieve the current date and time in a human-readable format
120110 let now = Local :: now ( ) ;
@@ -213,12 +203,11 @@ fn process_non_printable(line: &str) -> String {
213203}
214204
215205fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
216- // parse command line arguments
217- let args = Args :: parse ( ) ;
218-
219206 setlocale ( LocaleCategory :: LcAll , "" ) ;
220- textdomain ( PROJECT_NAME ) ?;
221- bind_textdomain_codeset ( PROJECT_NAME , "UTF-8" ) ?;
207+ textdomain ( env ! ( "PROJECT_NAME" ) ) ?;
208+ bind_textdomain_codeset ( env ! ( "PROJECT_NAME" ) , "UTF-8" ) ?;
209+
210+ let args = Args :: parse ( ) ;
222211
223212 let user_name = args. username ;
224213 let terminal = match args. terminal {
@@ -237,8 +226,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
237226 exit ( 1 ) ;
238227 }
239228
240- let sender_login_id = get_login_id ( ) ;
241- let sending_terminal = get_terminal ( ) ;
229+ let sender_login_id = curuser :: login_name ( ) ;
230+ let sending_terminal = curuser :: tty ( ) ;
242231 let date = get_current_date ( ) ;
243232
244233 let message = format ! (
0 commit comments