Trait minus::input::InputClassifier
source · [−]pub trait InputClassifier {
fn classify_input(&self, ev: Event, ps: &PagerState) -> Option<InputEvent>;
}
Expand description
Define custom keybindings
This trait can help define custom keybindings in case the downsteam applications aren’t satisfied with the defaults
Please do note that, in order to match the keybindings,
you need to directly work with the underlying crossterm
crate
Example
use minus::{input::{InputEvent, InputClassifier}, LineNumbers, Pager, PagerState};
use minus::SearchMode;
use crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers};
struct CustomInputClassifier;
impl InputClassifier for CustomInputClassifier {
fn classify_input(
&self,
ev: Event,
ps: &PagerState
) -> Option<InputEvent> {
match ev {
Event::Key(KeyEvent {
code: KeyCode::Up,
modifiers: KeyModifiers::NONE,
})
| Event::Key(KeyEvent {
code: KeyCode::Char('j'),
modifiers: KeyModifiers::NONE,
}) => Some(InputEvent::UpdateUpperMark
(ps.upper_mark.saturating_sub(1))),
_ => None
}
}
}
let mut pager = Pager::new();
pager.set_input_classifier(
Box::new(CustomInputClassifier)
);