pub trait KeyMap {
// Required methods
fn short_help(&self) -> Vec<&Binding>;
fn full_help(&self) -> Vec<Vec<&Binding>>;
}
Expand description
A trait that defines the key bindings to be displayed in the help view.
Any model that uses the help component should implement this trait to provide the key bindings that the help view will render. The trait provides two methods for different display contexts:
short_help()
: Returns key bindings for compact, single-line displayfull_help()
: Returns grouped key bindings for detailed, multi-column display
§Implementation Guidelines
§Short Help
Should include only the most essential key bindings (typically 3-6 keys) that users need for basic operation. These are displayed horizontally with bullet separators.
§Full Help
Should group related key bindings into logical columns:
- Navigation keys in one group
- Action keys in another group
- Application control keys in a third group
Each inner Vec
becomes a column in the final display, so group
related functionality together.
§Examples
use bubbletea_widgets::help::KeyMap;
use bubbletea_widgets::key::Binding;
use crossterm::event::KeyCode;
struct TextEditor {
save_key: Binding,
quit_key: Binding,
undo_key: Binding,
redo_key: Binding,
}
impl KeyMap for TextEditor {
fn short_help(&self) -> Vec<&bubbletea_widgets::key::Binding> {
// Only show essential keys in compact view
vec![&self.save_key, &self.quit_key]
}
fn full_help(&self) -> Vec<Vec<&bubbletea_widgets::key::Binding>> {
vec![
// File operations column
vec![&self.save_key],
// Edit operations column
vec![&self.undo_key, &self.redo_key],
// Application control column
vec![&self.quit_key],
]
}
}
Required Methods§
Sourcefn short_help(&self) -> Vec<&Binding>
fn short_help(&self) -> Vec<&Binding>
Returns a slice of key bindings for the short help view.
This method should return the most essential key bindings for your application, typically 3-6 keys that users need for basic operation. These bindings will be displayed in a single horizontal line.
§Guidelines
- Include only the most frequently used keys
- Prioritize navigation and core functionality
- Consider the typical workflow of your application
- Keep the total count manageable (3-6 keys)
§Returns
A vector of key binding references that will be displayed horizontally.
Sourcefn full_help(&self) -> Vec<Vec<&Binding>>
fn full_help(&self) -> Vec<Vec<&Binding>>
Returns a nested slice of key bindings for the full help view.
Each inner Vec
represents a column in the help view and should contain
logically related key bindings. The help component will render these as
separate columns with proper alignment and spacing.
§Guidelines
- Group related functionality together in the same column
- Keep columns roughly the same height for visual balance
- Consider the logical flow: navigation → actions → application control
- Each column should have 2-8 key bindings for optimal display
§Column Organization Examples
Column 1: Navigation Column 2: Actions Column 3: App Control
↑/k move up enter select q quit
↓/j move down space toggle ? help
→ next page d delete ctrl+c force quit
← prev page
§Returns
A vector of vectors, where each inner vector represents a column of key bindings to display.
Implementors§
impl KeyMap for bubbletea_widgets::table::Model
Help system integration for displaying table navigation keys.
This implementation provides the help system with information about the table’s key bindings, enabling automatic generation of help text that documents the available navigation commands.