New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: permission prompt stuffing on Windows #11969
Conversation
I think it'd be something like this: let mut input_record = INPUT_RECORD { EventType: KEY_EVENT, ..Default::default() };
input_record.Event.KeyEvent_mut().wRepeatCount = 1;
input_record.Event.KeyEvent_mut().uChar.UnicodeChar_mut() = 'y' as WCHAR; |
@piscisaureus oh, nice! Thanks for that. I will look into adding a test tomorrow. Edit: Oh, I could probably also just do |
What makes it difficult in particular? Afaik |
@piscisaureus calling By the way, here is my test script from Ryan's tests: const buf = new Uint8Array(1);
console.log("Enter 'yy':");
await Deno.stdin.read(buf);
await Deno.permissions.request({ "name": "env" });
console.log("\n\nOwned", Deno.env.get("SOMETHING")); |
I would be very surprised if this was case... |
@piscisaureus in the code in this PR if you try adding: assert_eq!(
FlushConsoleInputBuffer(stdin),
winapi::shared::minwindef::TRUE
);
// add this after the existing `FlushConsoleInputBuffer` (shown above for reference)
let mut buffer = [0u16; 1024];
let mut chars_read = 0;
assert_eq!(winapi::um::consoleapi::ReadConsoleW(stdin, buffer.as_mut_ptr() as _, buffer.len() as _, &mut chars_read, std::ptr::null_mut()), 1);
println!("Chars read: {}", chars_read);
let text = std::ffi::OsString::from_wide(&buffer[0..chars_read as usize]).to_string_lossy().to_string();
println!("Text: {:?}", text); ...then running this JS code if you type Maybe I'm doing something wrong? Again, I'm not super familiar with the winapi. Hopefully there is a way to do this that I'm not seeing. |
I’ll take a look and try to figure this out tomorrow. |
I wrote a simple standalone test: https://gist.github.com/piscisaureus/42fd7536b075f447682977083c7ff678 |
@piscisaureus try my fork https://gist.github.com/dsherret/72991b395d68ac6aff912199e5e44ac5 By the way, from these tests it's clear that |
…ear any line buffered console characters
This unfortunately makes Windows act differently in that pressing the "y" or "n" key immediately confirms or denies the prompt. It would take a lot more code to make this work otherwise.
Also, I looked into using https://docs.microsoft.com/en-us/windows/console/writeconsoleinput to create unit tests, but I couldn't figure out a way to construct an
INPUT_RECORD
.