pub struct HashedEventRegister<S>(/* private fields */);Expand description
A hash store for events and it’s related callback
Each item is a key value pair, where the key is a event and it’s value is a callback. When a event occurs, it is matched inside and when the related match is found, it’s related callback is called.
Implementations§
Source§impl HashedEventRegister<RandomState>
impl HashedEventRegister<RandomState>
Sourcepub fn with_default_hasher() -> Self
pub fn with_default_hasher() -> Self
Create a new HashedEventRegister with the default hasher
Source§impl<S> HashedEventRegister<S>where
S: BuildHasher,
impl<S> HashedEventRegister<S>where
S: BuildHasher,
Sourcepub fn format_help(&self) -> String
pub fn format_help(&self) -> String
Format dynamic help table from all registered key bindings that have non-empty descriptions.
Sourcepub fn insert_wild_event_matcher(
&mut self,
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
)
pub fn insert_wild_event_matcher( &mut self, cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, )
Adds a callback to handle all events that failed to match
Sometimes there are bunch of keys having equal importance that should have the same callback, for instance all the numbers on the keyboard. To handle these types of scenerios this is extremely useful. This callback is called when no event matches the incoming event, then we just match whether the event is a keyboard number and perform the required action.
This is also helpful when you need to do some action, like sending a message when the user presses wrong keyboard/mouse buttons.
Sourcepub fn add_resize_event(
&mut self,
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
)
pub fn add_resize_event( &mut self, cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, )
Adds a callback for handling resize events
§Example
These are from the original sources
use minus::input::{InputEvent, HashedEventRegister, crossterm_event::Event};
let mut input_register = HashedEventRegister::default();
input_register.add_resize_event(|ev, _| {
let (cols, rows) = if let Event::Resize(cols, rows) = ev {
(cols, rows)
} else {
unreachable!();
};
InputEvent::UpdateTermArea(cols as usize, rows as usize)
});Sourcepub fn remove_resize_event(&mut self)
pub fn remove_resize_event(&mut self)
Removes the currently active resize event callback
Source§impl<S> HashedEventRegister<S>where
S: BuildHasher,
impl<S> HashedEventRegister<S>where
S: BuildHasher,
Sourcepub fn add_key_events(
&mut self,
desc: &[&str],
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
)
pub fn add_key_events( &mut self, desc: &[&str], cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, )
Add all elements of desc as key bindings that minus should respond to with the callback cb
You should prefer using the add_key_events_checked
over this one.
§Example
use minus::input::{InputEvent, HashedEventRegister, crossterm_event};
let mut input_register = HashedEventRegister::default();
input_register.add_key_events(&["down"], |_, ps| {
InputEvent::UpdateUpperMark(ps.upper_mark.saturating_sub(1))
});Sourcepub fn add_described_key_events(
&mut self,
keys: &[&str],
desc: impl Into<Cow<'static, str>>,
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
)
pub fn add_described_key_events( &mut self, keys: &[&str], desc: impl Into<Cow<'static, str>>, cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, )
Add all elements of keys as key bindings with a description that minus should respond to with the callback cb.
Sourcepub fn add_key_events_checked(
&mut self,
desc: &[&str],
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
remap: bool,
)
pub fn add_key_events_checked( &mut self, desc: &[&str], cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, remap: bool, )
Add all elements of desc as key bindings that minus should respond to with the callback cb.
Prefer using this over add_key_events.
§Panics
This will panic if you the keybinding has been previously defined, unless the remap
is set to true. This helps preventing accidental overrides of your keybindings.
§Example
use minus::input::{InputEvent, HashedEventRegister, crossterm_event};
let mut input_register = HashedEventRegister::default();
input_register.add_key_events_checked(&["down"], |_, ps| {
InputEvent::UpdateUpperMark(ps.upper_mark.saturating_sub(1))
}, false);Sourcepub fn add_described_key_events_checked(
&mut self,
keys: &[&str],
desc: impl Into<Cow<'static, str>>,
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
remap: bool,
)
pub fn add_described_key_events_checked( &mut self, keys: &[&str], desc: impl Into<Cow<'static, str>>, cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, remap: bool, )
Add all elements of keys as key bindings with a description that minus should respond to with the callback cb, with conflict checking.
§Panics
Panics if a key already exists and remap is false.
Sourcepub fn remove_key_events(&mut self, desc: &[&str])
pub fn remove_key_events(&mut self, desc: &[&str])
Removes the callback associated with the all the elements of desc.
use minus::input::{InputEvent, HashedEventRegister, crossterm_event};
let mut input_register = HashedEventRegister::default();
input_register.remove_key_events(&["down"])Sourcepub fn add_help_key(&mut self, desc: &[&str])
pub fn add_help_key(&mut self, desc: &[&str])
Add key binding(s) to show help in the pager prompt.
If desc is empty, defaults to &["m-h"].
§Example
use minus::input::HashedEventRegister;
let mut input_register = HashedEventRegister::default();
// Bind default Meta/Alt-h key to show help
input_register.add_help_key(&[]);
// Or specify custom keys
input_register.add_help_key(&["f1"]);Sourcepub fn add_help_key_checked(&mut self, desc: &[&str], remap: bool)
pub fn add_help_key_checked(&mut self, desc: &[&str], remap: bool)
Add key binding(s) to show help in the pager prompt with conflict checking.
If desc is empty, defaults to &["m-h"].
§Panics
This will panic if any of the keybindings has been previously defined, unless remap
is set to true.
Source§impl<S> HashedEventRegister<S>where
S: BuildHasher,
impl<S> HashedEventRegister<S>where
S: BuildHasher,
Sourcepub fn add_mouse_events(
&mut self,
desc: &[&str],
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
)
pub fn add_mouse_events( &mut self, desc: &[&str], cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, )
Add all elemnts of desc as mouse bindings that minus should respond to with the callback cb
You should prefer using the add_mouse_events_checked
over this one.
§Example
use minus::input::{InputEvent, HashedEventRegister};
let mut input_register = HashedEventRegister::default();
input_register.add_mouse_events(&["scroll:down"], |_, ps| {
InputEvent::UpdateUpperMark(ps.upper_mark.saturating_sub(5))
});Sourcepub fn add_mouse_events_checked(
&mut self,
desc: &[&str],
cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static,
remap: bool,
)
pub fn add_mouse_events_checked( &mut self, desc: &[&str], cb: impl Fn(Event, &PagerState) -> InputEvent + Send + Sync + 'static, remap: bool, )
Add all elemnts of desc as mouse bindings that minus should respond to with the callback cb.
Prefer using this over add_mouse_events.
§Panics
This will panic if you the keybinding has been previously defined, unless the remap
is set to true. This helps preventing accidental overrides of your keybindings.
§Example
use minus::input::{InputEvent, HashedEventRegister};
let mut input_register = HashedEventRegister::default();
input_register.add_mouse_events_checked(&["scroll:down"], |_, ps| {
InputEvent::UpdateUpperMark(ps.upper_mark.saturating_sub(5))
}, false);Sourcepub fn remove_mouse_events(&mut self, mouse: &[&str])
pub fn remove_mouse_events(&mut self, mouse: &[&str])
Removes the callback associated with the all the elements of desc.
use minus::input::{InputEvent, HashedEventRegister, crossterm_event};
let mut input_register = HashedEventRegister::default();
input_register.remove_mouse_events(&["scroll:down"])Trait Implementations§
Source§impl Default for HashedEventRegister<RandomState>
impl Default for HashedEventRegister<RandomState>
Source§fn default() -> Self
fn default() -> Self
Create a new HashedEventRegister with the default hasher and insert the default bindings
Source§impl<S> InputClassifier for HashedEventRegister<S>where
S: BuildHasher,
impl<S> InputClassifier for HashedEventRegister<S>where
S: BuildHasher,
Source§fn classify_input(&self, ev: Event, ps: &PagerState) -> Option<InputEvent>
fn classify_input(&self, ev: Event, ps: &PagerState) -> Option<InputEvent>
See #163.
Auto Trait Implementations§
impl<S> !RefUnwindSafe for HashedEventRegister<S>
impl<S> !UnwindSafe for HashedEventRegister<S>
impl<S> Freeze for HashedEventRegister<S>where
S: Freeze,
impl<S> Send for HashedEventRegister<S>where
S: Send,
impl<S> Sync for HashedEventRegister<S>where
S: Sync,
impl<S> Unpin for HashedEventRegister<S>where
S: Unpin,
impl<S> UnsafeUnpin for HashedEventRegister<S>where
S: UnsafeUnpin,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.