Skip to content

Commit bc68119

Browse files
Merge pull request #454 from Bluemangoo/fix/438
w: truncate long username
2 parents 831878a + 89c55bb commit bc68119

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/uu/w/src/w.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ fn fetch_user_info() -> Result<Vec<UserInfo>, std::io::Error> {
255255
Ok(Vec::new())
256256
}
257257

258+
fn truncate_username(user: &str) -> String {
259+
user.chars().take(8).collect::<String>()
260+
}
261+
258262
#[uucore::main]
259263
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
260264
let matches = uu_app().try_get_matches_from(args)?;
@@ -281,15 +285,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
281285
if short {
282286
println!(
283287
"{:<9}{:<9}{:<7}{:<}",
284-
user.user,
288+
truncate_username(&user.user),
285289
user.terminal,
286290
format_time_elapsed(user.idle_time, old_style).unwrap_or_default(),
287291
user.command
288292
);
289293
} else {
290294
println!(
291295
"{:<9}{:<10}{:<9}{:<6} {:<7}{:<6}{:<}",
292-
user.user,
296+
truncate_username(&user.user),
293297
user.terminal,
294298
user.login_time,
295299
format_time_elapsed(user.idle_time, old_style).unwrap_or_default(),

0 commit comments

Comments
 (0)