gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.31k stars 247 forks source link

[FEATURE] Allow Keyboard Remapping for In-App Navigation #720

Open leoferaderonugraha opened 1 year ago

leoferaderonugraha commented 1 year ago

Hi,

I've tried cursive for several days, however, I couldn't find the documentation for remapping a keyboard input to in-app action like navigation. It would be great if it's possible to remap/rebind the keyboard input to some in-app action, for example:

let cs = cursive::Cursive();

cs.add_global_callback('k', |c| c.event.navigation.up());
/* or */
cs.add_global_keymap('h', cursive::event::Key::Left);

//...

Kindly let me know if it's already possible or if I'm missing something.

gyscos commented 1 year ago

Hi, and thanks for the report.

There is no currently any global "navigation" mechanism. Each view group is free to interpret some keys as navigation.

In practice most view groups support navigation through the arrow and tab/shift-tab keys. So one way to have h behave like the left key is to set a callback that calls Cursive::on_event with Event::Key::Left. This can be set either as a global callback, or locally for a given view subtree (using OnEventView for example).