Expand description
A help component for bubbletea-rs, ported from the Go version.
This component provides a customizable help view that can automatically generate its content from a set of key bindings. It supports both compact single-line help displays and expanded multi-column layouts.
The help component integrates seamlessly with the bubbletea-rs architecture and provides adaptive styling for both light and dark terminal themes.
§Features
- Dual Display Modes: Switch between compact and expanded help views
- Adaptive Styling: Automatically adjusts colors for light/dark themes
- Width Constraints: Truncates content with ellipsis when space is limited
- Column Layout: Organizes key bindings into logical, aligned columns
- Disabled Key Handling: Automatically hides disabled key bindings
§Quick Start
use bubbletea_widgets::help::{Model, KeyMap};
use bubbletea_widgets::key::Binding;
use crossterm::event::KeyCode;
// Create key bindings for your application
let quit_key = Binding::new(vec![KeyCode::Char('q')])
.with_help("q", "quit");
let help_key = Binding::new(vec![KeyCode::Char('?')])
.with_help("?", "help");
// Implement KeyMap for your application state
struct MyApp {
quit_key: Binding,
help_key: Binding,
}
impl KeyMap for MyApp {
fn short_help(&self) -> Vec<&bubbletea_widgets::key::Binding> {
vec![&self.quit_key, &self.help_key]
}
fn full_help(&self) -> Vec<Vec<&bubbletea_widgets::key::Binding>> {
vec![
vec![&self.help_key], // Help column
vec![&self.quit_key], // Quit column
]
}
}
// Create and use the help component
let app = MyApp { quit_key, help_key };
let help = Model::new().with_width(80);
// Render help text
let short_help = help.view(&app); // Shows compact help
let mut full_help = help;
full_help.show_all = true;
let detailed_help = full_help.view(&app); // Shows detailed helpStructs§
- Model
- The help model that manages help view state and rendering.
- Styles
- A set of styles for the help component.
Traits§
- KeyMap
- A trait that defines the key bindings to be displayed in the help view.
Functions§
- should_
render_ column - Determines if a column of key bindings should be rendered.