From ede134d8516cdcbf0c5dbb40c8a72ddeb6f46c11 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 23:04:04 +1000 Subject: [PATCH] Fix locking of `stdou` in `UIThreadInner` which blocks the printing in main thread and prevents it from exiting. Signed-off-by: Jiahao XU --- src/helpers/ui_thread.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/helpers/ui_thread.rs b/src/helpers/ui_thread.rs index 8cc42a6e..64a20c55 100644 --- a/src/helpers/ui_thread.rs +++ b/src/helpers/ui_thread.rs @@ -32,14 +32,14 @@ impl UIThreadInner { break; } - // Lock stdout so that nobody can interfere - // with confirmation. - let mut stdout = io::stdout().lock(); - let res = loop { - writeln!(&mut stdout, "Do you wish to continue? yes/[no]").unwrap(); - write!(&mut stdout, "? ").unwrap(); - stdout.flush().unwrap(); + { + let mut stdout = io::stdout().lock(); + + writeln!(&mut stdout, "Do you wish to continue? yes/[no]").unwrap(); + write!(&mut stdout, "? ").unwrap(); + stdout.flush().unwrap(); + } input.clear(); stdin.read_line(&mut input).unwrap();