pub enum GlobalKeyPolicy {
Default,
Keys(Vec<(KeyCode, KeyModifiers)>),
Custom(Box<dyn Fn(&EventKind) -> bool + Send + Sync>),
}Expand description
Policy for determining which events are treated as global.
Global events bypass modal blocking and are delivered to global subscribers even when a modal is active. Resize events are always treated as global regardless of this policy.
By default, Esc, Ctrl+C, and Ctrl+Q are global keys. Use this to customize that behavior — for example, if your app uses Esc for “close modal” and doesn’t want it treated as global.
§Example
use tui_dispatch::{EventBus, GlobalKeyPolicy};
// Remove Esc from global keys (keep only Ctrl+C, Ctrl+Q)
let bus = EventBus::new()
.with_global_key_policy(GlobalKeyPolicy::without_esc());
// Custom set of global keys
let bus = EventBus::new()
.with_global_key_policy(GlobalKeyPolicy::keys(vec![
(KeyCode::Char('c'), KeyModifiers::CONTROL),
]));
// No key events are global (only Resize remains global)
let bus = EventBus::new()
.with_global_key_policy(GlobalKeyPolicy::none());Variants§
Default
Default: Esc, Ctrl+C, Ctrl+Q are global. Same as EventKind::is_global().
Keys(Vec<(KeyCode, KeyModifiers)>)
Only these specific key combinations are global.
Each entry is (KeyCode, required_modifiers).
Custom(Box<dyn Fn(&EventKind) -> bool + Send + Sync>)
Custom predicate function.
Implementations§
Source§impl GlobalKeyPolicy
impl GlobalKeyPolicy
Sourcepub fn without_esc() -> Self
pub fn without_esc() -> Self
Default without Esc — only Ctrl+C and Ctrl+Q are global.
Useful for apps that use Esc to close modals/dialogs.
Sourcepub fn keys(keys: Vec<(KeyCode, KeyModifiers)>) -> Self
pub fn keys(keys: Vec<(KeyCode, KeyModifiers)>) -> Self
Only these specific key combinations are global.
Each entry is (KeyCode, required_modifiers) — the key matches if
its code equals the given code and its modifiers contain the
required modifiers.
Trait Implementations§
Source§impl Default for GlobalKeyPolicy
impl Default for GlobalKeyPolicy
Source§fn default() -> GlobalKeyPolicy
fn default() -> GlobalKeyPolicy
Auto Trait Implementations§
impl Freeze for GlobalKeyPolicy
impl !RefUnwindSafe for GlobalKeyPolicy
impl Send for GlobalKeyPolicy
impl Sync for GlobalKeyPolicy
impl Unpin for GlobalKeyPolicy
impl UnsafeUnpin for GlobalKeyPolicy
impl !UnwindSafe for GlobalKeyPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more