Trait minus::input::InputHandler [−][src]
pub trait InputHandler { fn handle_input(
&self,
ev: Event,
upper_mark: usize,
search_mode: SearchMode,
ln: LineNumbers,
rows: usize
) -> 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, InputHandler}, LineNumbers, Pager}; use minus::SearchMode; use crossterm::event::{Event, KeyEvent, KeyCode, KeyModifiers}; struct CustomInputHandler; impl InputHandler for CustomInputHandler { fn handle_input( &self, ev: Event, upper_mark: usize, // This `search_mode` parameter is available, only if `search` feature is enabled search_mode: SearchMode, ln: LineNumbers, rows: usize ) -> 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 (upper_mark.saturating_sub(1))), _ => None } } } let mut pager = Pager::new().unwrap(); pager.set_input_handler( Box::new(CustomInputHandler) );
Required methods
fn handle_input(
&self,
ev: Event,
upper_mark: usize,
search_mode: SearchMode,
ln: LineNumbers,
rows: usize
) -> Option<InputEvent>