Add vim-like keybindings to tui viewer

This patch adds vim-like keybindings to the tui viewer:  hjkl for
navigation, G and g (instead of gg) for End and Home, and Ctrl+F and
Ctrl+B for Page Down and Up.
This commit is contained in:
Robin Krahl 2020-10-08 11:00:18 +02:00
parent 7756803e35
commit 9dd54e3219
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8

View File

@ -200,11 +200,23 @@ fn create_cursive(
sources: Vec<Box<dyn source::Source>>, sources: Vec<Box<dyn source::Source>>,
args: args::ViewerArgs, args: args::ViewerArgs,
) -> anyhow::Result<cursive::Cursive> { ) -> anyhow::Result<cursive::Cursive> {
use cursive::event::{Event, Key};
let mut cursive = let mut cursive =
cursive::Cursive::try_new(create_backend).context("Could not create Cursive instance")?; cursive::Cursive::try_new(create_backend).context("Could not create Cursive instance")?;
cursive.set_user_data(Context::new(sources, args)?); cursive.set_user_data(Context::new(sources, args)?);
// vim-like keybindings
cursive.add_global_callback('j', |s| s.on_event(Key::Down.into()));
cursive.add_global_callback('k', |s| s.on_event(Key::Up.into()));
cursive.add_global_callback('h', |s| s.on_event(Key::Left.into()));
cursive.add_global_callback('l', |s| s.on_event(Key::Right.into()));
cursive.add_global_callback('G', |s| s.on_event(Key::End.into()));
cursive.add_global_callback('g', |s| s.on_event(Key::Home.into()));
cursive.add_global_callback(Event::CtrlChar('f'), |s| s.on_event(Key::PageDown.into()));
cursive.add_global_callback(Event::CtrlChar('b'), |s| s.on_event(Key::PageUp.into()));
cursive.add_global_callback('q', |s| s.quit()); cursive.add_global_callback('q', |s| s.quit());
cursive.add_global_callback(event::Key::Backspace, |s| { cursive.add_global_callback(event::Key::Backspace, |s| {
let screen = s.screen_mut(); let screen = s.screen_mut();