Skip to content

Commit 1324091

Browse files
authored
Merge pull request #1519 from cgwalters/unbuffer-stdout
system-reinstall-bootc: Ensure stdout is flushed
2 parents c1b0a19 + 7d8229c commit 1324091

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/system-reinstall-bootc/src/prompt.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/// A variant of `println!` that flushes stdout.
2+
macro_rules! println_flush {
3+
($($arg:tt)*) => {
4+
{
5+
use std::io::Write;
6+
println!($($arg)*);
7+
std::io::stdout().flush().unwrap();
8+
}
9+
};
10+
}
11+
112
use crate::{btrfs, lvm, prompt, users::get_all_users_keys};
213
use anyhow::{ensure, Context, Result};
314

@@ -46,7 +57,7 @@ fn prompt_user_selection(
4657

4758
pub(crate) fn reboot() -> Result<()> {
4859
let delay_seconds = 10;
49-
println!(
60+
println_flush!(
5061
"Operation complete, rebooting in {delay_seconds} seconds. Press Ctrl-C to cancel reboot, or press enter to continue immediately.",
5162
);
5263

@@ -70,13 +81,13 @@ pub(crate) fn reboot() -> Result<()> {
7081
/// final prompting UX in https://github.com/bootc-dev/bootc/discussions/1060
7182
pub(crate) fn temporary_developer_protection_prompt() -> Result<()> {
7283
// Print an empty line so that the warning stands out from the rest of the output
73-
println!();
84+
println_flush!();
7485

7586
let prompt = "NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue?";
7687
let answer = ask_yes_no(prompt, false)?;
7788

7889
if !answer {
79-
println!("Exiting without reinstalling the system.");
90+
println_flush!("Exiting without reinstalling the system.");
8091
std::process::exit(0);
8192
}
8293

0 commit comments

Comments
 (0)