1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(permissions): expose PermissionPrompter and set_prompter function (#26327)

when defining a custom runtime, it might be useful to define a custom
prompter - for instance when you are not relying on the terminal and
want a GUI prompter instead
This commit is contained in:
Lucas Nogueira 2024-10-17 13:39:18 -03:00 committed by GitHub
parent 33ceae4ce5
commit 3b62e05062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -39,6 +39,8 @@ use prompter::PromptResponse;
use prompter::PERMISSION_EMOJI;
pub use prompter::set_prompt_callbacks;
pub use prompter::set_prompter;
pub use prompter::PermissionPrompter;
pub use prompter::PromptCallback;
/// Fast exit from permission check routines if this permission

View file

@ -80,6 +80,10 @@ pub fn set_prompt_callbacks(
*MAYBE_AFTER_PROMPT_CALLBACK.lock() = Some(after_callback);
}
pub fn set_prompter(prompter: Box<dyn PermissionPrompter>) {
*PERMISSION_PROMPTER.lock() = prompter;
}
pub type PromptCallback = Box<dyn FnMut() + Send + Sync>;
pub trait PermissionPrompter: Send + Sync {
@ -476,8 +480,4 @@ pub mod tests {
STUB_PROMPT_VALUE.store(value, Ordering::SeqCst);
}
}
pub fn set_prompter(prompter: Box<dyn PermissionPrompter>) {
*PERMISSION_PROMPTER.lock() = prompter;
}
}