Soft question: handling multi key hotkeys

Context: I'm building a TUI app in Rust.

say we have something like:

pub trait Widget_T { ... }

pub Repl_Widget {
  pub editor: Rc<dyn Widge_T>,
  pub eval_history: Rc<dyn Widget_T>,
  pub some_other_component: Rc<dyn Widget_T>,

Imagine for a moment that all our hot keys are a single key, i.e. C-x, or C-y, but not C-s C-s or C-x C-e.

In this world, if a hot key hits Repl_Widget, it is pretty easy: if we can handle it, we handle it, if not, we find the focused component, and send the key to the Rc<dyn Widget_T>


Now suppose we allow multi key hotkeys, things like C-x C-e or C-x C-s, ... (or, 3, 4, 5 key combos).

Is there an idiomatic way to handle this ? (I.e. some standard algorithm / data structure / ... ).

C-x C-s is not a multi-key hot key :wink:

It’s just a single C-x, bound to the action of “change the current keymap to the one where C-s is bound to “save” action”.

Despite being a fan of function-currying, I somehow never thought about hot keys this way. Is this the idiomatic way to approach this? Collect common prefixes, setup new keymaps, and dynamically swap keymaps ?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.