pub fn should_render_column(bindings: &[&Binding]) -> boolExpand description
Determines if a column of key bindings should be rendered.
A column should be rendered if it contains at least one enabled binding.
This helper function matches the behavior of the Go implementation’s
shouldRenderColumn function and provides consistent column visibility
logic across the help system.
§Purpose
This function prevents empty columns from appearing in the help display:
- Enabled Bindings: Columns with active key bindings are shown
- Disabled Bindings: Columns with only disabled bindings are hidden
- Mixed Columns: Columns with some enabled bindings are shown
- Empty Columns: Completely empty columns are hidden
§Use Cases
§Context-Sensitive Help
// In a text editor, cut/copy might be disabled when no text is selected
let cut_key = Binding::new(vec![KeyCode::Char('x')])
.with_help("x", "cut")
.with_disabled(); // Disabled because nothing selected
let copy_key = Binding::new(vec![KeyCode::Char('c')])
.with_help("c", "copy")
.with_disabled(); // Also disabled
let edit_column = vec![&cut_key, ©_key];
assert!(!should_render_column(&edit_column)); // Hidden - all disabled§Progressive Disclosure
// Advanced features might be disabled for beginners
let basic_key = Binding::new(vec![KeyCode::Char('s')])
.with_help("s", "save"); // Always enabled
let advanced_key = Binding::new(vec![KeyCode::Char('m')])
.with_help("m", "macro")
.with_disabled(); // Disabled in beginner mode
let mixed_column = vec![&basic_key, &advanced_key];
assert!(should_render_column(&mixed_column)); // Shown - has enabled binding§Arguments
bindings- A slice of key binding references to check. Typically represents a logical group of related key bindings that would form a column in the help display.
§Returns
true- The column should be rendered because it contains at least one enabled binding that users can actually use.false- The column should be hidden because all bindings are disabled or the column is empty.
§Performance
This function uses early return optimization - it stops checking as soon as it finds the first enabled binding, making it efficient for columns with many bindings.
§Examples
§All Bindings Enabled
use bubbletea_widgets::help::should_render_column;
use bubbletea_widgets::key::Binding;
use crossterm::event::KeyCode;
let save_key = Binding::new(vec![KeyCode::Char('s')]).with_help("s", "save");
let quit_key = Binding::new(vec![KeyCode::Char('q')]).with_help("q", "quit");
let column = vec![&save_key, &quit_key];
assert!(should_render_column(&column)); // Show column§All Bindings Disabled
let disabled1 = Binding::new(vec![KeyCode::F(1)]).with_disabled();
let disabled2 = Binding::new(vec![KeyCode::F(2)]).with_disabled();
let column = vec![&disabled1, &disabled2];
assert!(!should_render_column(&column)); // Hide column§Mixed State
let enabled = Binding::new(vec![KeyCode::Enter]).with_help("enter", "select");
let disabled = Binding::new(vec![KeyCode::Delete]).with_disabled();
let column = vec![&enabled, &disabled];
assert!(should_render_column(&column)); // Show column (has enabled binding)§Empty Column
let empty_column = vec![];
assert!(!should_render_column(&empty_column)); // Hide empty column