lock stdout

To help prevent race conditions, and ensuring safe output
This commit is contained in:
raf 2024-11-09 21:13:12 +03:00
parent 9de9222033
commit c301ce0feb
Signed by: NotAShelf
GPG key ID: AF26552424E53993

View file

@ -93,10 +93,11 @@ fn print_system_info(fields: &Fields) -> io::Result<()> {
.max() .max()
.unwrap_or(0); .unwrap_or(0);
writeln!(io::stdout(), "{:<27} {} ~{RESET}", LOGO[0], user_info)?; let mut handle = io::stdout().lock();
writeln!(handle, "{:<27} {} ~{RESET}", LOGO[0], user_info)?;
for (logo_line, (icon, label, value)) in LOGO[1..].iter().zip(system_info.iter()) { for (logo_line, (icon, label, value)) in LOGO[1..].iter().zip(system_info.iter()) {
writeln!( writeln!(
io::stdout(), handle,
"{:<27} {CYAN}{:<2} {BLUE}{:<width$}{RESET}  {value}{RESET}", "{:<27} {CYAN}{:<2} {BLUE}{:<width$}{RESET}  {value}{RESET}",
logo_line, logo_line,
icon, icon,