Skip to main content

GlobalKeyPolicy

Enum GlobalKeyPolicy 

Source
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

Source

pub fn none() -> Self

No key events are global (only Resize remains global).

Source

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.

Source

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.

Source

pub fn custom(f: impl Fn(&EventKind) -> bool + Send + Sync + 'static) -> Self

Custom predicate for full control over global classification.

Resize events are still always global regardless of the predicate.

Source

pub fn is_global(&self, event: &EventKind) -> bool

Check whether an event is global under this policy.

Resize events always return true regardless of the policy.

Trait Implementations§

Source§

impl Default for GlobalKeyPolicy

Source§

fn default() -> GlobalKeyPolicy

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.