Skip to content

Commit

Permalink
feat(permissions): expose PermissionPrompter and set_prompter function (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
lucasfernog-crabnebula authored Oct 17, 2024
1 parent 33ceae4 commit 3b62e05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions runtime/permissions/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions runtime/permissions/prompter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 3b62e05

Please sign in to comment.