Skip to main content

handle_navigation_key

Function handle_navigation_key 

Source
pub fn handle_navigation_key(
    key: Key,
    current: usize,
    section_count: usize,
) -> Option<Navigation>
Expand description

Helper to check if a key is a navigation key and return the navigation action.

This utility function is provided for library consumers who want to implement custom widgets that support wizard navigation shortcuts. It checks for:

  • Number keys (1-9): Jump to that section
  • Escape: Go back to the previous section (returns None if at first section)

§Example

use demand::{handle_navigation_key, Navigation};
use console::Key;

// In your custom widget's key handling loop:
if let Some(nav) = handle_navigation_key(key, current_section, total_sections) {
    return Ok(nav);
}
// ... handle other keys