diff options
author | Bartek Iwańczuk <biwanczuk@gmail.com> | 2023-01-13 16:05:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 10:05:07 -0500 |
commit | 1b17985c5a438858b4cbe4e1e57cf000aeea0772 (patch) | |
tree | 3aa61fbb1019a0dad359ca9d4e26e915f7dd8fbb /runtime/permissions/prompter.rs | |
parent | 9644220df2f03efa75fcd63a7d37fb5903b5ff08 (diff) |
fix(permissions): lock stdio streams when prompt is shown (#17392)
This commit changes permission prompt to lock stdio streams when prompt
is shown.
Diffstat (limited to 'runtime/permissions/prompter.rs')
-rw-r--r-- | runtime/permissions/prompter.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index a73898835..ae07e004c 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -192,6 +192,11 @@ impl PermissionPrompter for TtyPrompter { return PromptResponse::Deny; // don't grant permission if this fails } + // Lock stdio streams, so no other output is written while the prompt is + // displayed. + let _stdout_guard = std::io::stdout().lock(); + let _stderr_guard = std::io::stderr().lock(); + // print to stderr so that if stdout is piped this is still displayed. const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)"; eprint!("{} ┌ ", PERMISSION_EMOJI); @@ -238,6 +243,9 @@ impl PermissionPrompter for TtyPrompter { }; }; + drop(_stdout_guard); + drop(_stderr_guard); + value } } |