From 9dd54e3219465bf10a0c531c42f9ec6fc1b2d363 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 8 Oct 2020 11:00:18 +0200 Subject: [PATCH] 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. --- src/viewer/tui/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/viewer/tui/mod.rs b/src/viewer/tui/mod.rs index 8c0c067..bf67aed 100644 --- a/src/viewer/tui/mod.rs +++ b/src/viewer/tui/mod.rs @@ -200,11 +200,23 @@ fn create_cursive( sources: Vec>, args: args::ViewerArgs, ) -> anyhow::Result { + use cursive::event::{Event, Key}; + let mut cursive = cursive::Cursive::try_new(create_backend).context("Could not create Cursive instance")?; 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(event::Key::Backspace, |s| { let screen = s.screen_mut();