mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(runtime): fix Windows permission prompt (#23212)
Followup to https://github.com/denoland/deno/pull/23184
This commit is contained in:
parent
e01bc09573
commit
945eb5eba6
1 changed files with 5 additions and 7 deletions
|
@ -335,7 +335,8 @@ impl PermissionPrompter for TtyPrompter {
|
|||
let value = loop {
|
||||
// Clear stdin each time we loop around in case the user accidentally pasted
|
||||
// multiple lines or otherwise did something silly to generate a torrent of
|
||||
// input.
|
||||
// input. This doesn't work on Windows because `clear_stdin` has other side-effects.
|
||||
#[cfg(unix)]
|
||||
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
|
||||
eprintln!("Error clearing stdin for permission prompt. {err:#}");
|
||||
return PromptResponse::Deny; // don't grant permission if this fails
|
||||
|
@ -343,14 +344,11 @@ impl PermissionPrompter for TtyPrompter {
|
|||
|
||||
let mut input = String::new();
|
||||
let result = stdin_lock.read_line(&mut input);
|
||||
if result.is_err() || input.len() > 2 {
|
||||
let input = input.trim_end_matches(|c| c == '\r' || c == '\n');
|
||||
if result.is_err() || input.len() != 1 {
|
||||
break PromptResponse::Deny;
|
||||
};
|
||||
let ch = match input.chars().next() {
|
||||
None => break PromptResponse::Deny,
|
||||
Some(v) => v,
|
||||
};
|
||||
match ch {
|
||||
match input.as_bytes()[0] as char {
|
||||
'y' | 'Y' => {
|
||||
clear_n_lines(
|
||||
&mut stderr_lock,
|
||||
|
|
Loading…
Reference in a new issue