fast-fs 0.2.1

High-speed async file system traversal library with batteries-included file browser component
Documentation
// <FILE>crates/fast-fs/src/nav/key_input.rs</FILE> - <DESC>Framework-agnostic key input representation</DESC>
// <VERS>VERSION: 0.1.0</VERS>
// <WCTX>Implementing nav module PRD</WCTX>
// <CLOG>Initial creation</CLOG>

//! Framework-agnostic key input
//!
//! This module provides a `KeyInput` enum that represents keyboard input
//! without depending on any specific UI framework. Consumers map their
//! framework's key events to this type.

/// Framework-agnostic key input representation.
///
/// Consumers map their framework's events to this type. For example:
/// - crossterm: `KeyEvent` → `KeyInput`
/// - winit: `KeyEvent` → `KeyInput`
/// - egui: `Key` → `KeyInput`
///
/// # Keyboard Layout Considerations
///
/// When using `Shift(char)`, be aware that keyboard layouts vary:
/// - US: `Shift+'n'` produces `'N'`
/// - German: `Shift+'7'` produces `'/'`
///
/// For cross-layout compatibility, prefer:
/// - Function keys (`F1`-`F12`) for important actions
/// - Ctrl/Alt modifiers with navigation keys
/// - Unshifted character keys for common actions
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum KeyInput {
    // Character input
    /// A character key was pressed
    Char(char),

    // Navigation keys
    /// Up arrow key
    Up,
    /// Down arrow key
    Down,
    /// Left arrow key
    Left,
    /// Right arrow key
    Right,
    /// Home key
    Home,
    /// End key
    End,
    /// Page Up key
    PageUp,
    /// Page Down key
    PageDown,

    // Action keys
    /// Enter/Return key
    Enter,
    /// Backspace key
    Backspace,
    /// Delete key
    Delete,
    /// Escape key
    Escape,
    /// Tab key
    Tab,

    // Function keys
    /// Function key (F1-F12)
    F(u8),

    // Modified character keys
    /// Ctrl + character
    Ctrl(char),
    /// Alt + character
    Alt(char),
    /// Shift + character (for uppercase letters)
    Shift(char),

    // Modified navigation keys (for power users)
    /// Ctrl + Up arrow
    CtrlUp,
    /// Ctrl + Down arrow
    CtrlDown,
    /// Ctrl + Left arrow
    CtrlLeft,
    /// Ctrl + Right arrow
    CtrlRight,
    /// Ctrl + Home
    CtrlHome,
    /// Ctrl + End
    CtrlEnd,
    /// Alt + Up arrow
    AltUp,
    /// Alt + Down arrow
    AltDown,
    /// Alt + Enter
    AltEnter,
    /// Shift + Up arrow
    ShiftUp,
    /// Shift + Down arrow
    ShiftDown,
}

impl KeyInput {
    /// Check if this is a character key (including modified characters)
    pub fn is_char(&self) -> bool {
        matches!(
            self,
            KeyInput::Char(_) | KeyInput::Ctrl(_) | KeyInput::Alt(_) | KeyInput::Shift(_)
        )
    }

    /// Get the character if this is a character key
    pub fn as_char(&self) -> Option<char> {
        match self {
            KeyInput::Char(c) | KeyInput::Shift(c) => Some(*c),
            _ => None,
        }
    }

    /// Check if this key has Ctrl modifier
    pub fn has_ctrl(&self) -> bool {
        matches!(
            self,
            KeyInput::Ctrl(_)
                | KeyInput::CtrlUp
                | KeyInput::CtrlDown
                | KeyInput::CtrlLeft
                | KeyInput::CtrlRight
                | KeyInput::CtrlHome
                | KeyInput::CtrlEnd
        )
    }

    /// Check if this key has Alt modifier
    pub fn has_alt(&self) -> bool {
        matches!(
            self,
            KeyInput::Alt(_) | KeyInput::AltUp | KeyInput::AltDown | KeyInput::AltEnter
        )
    }

    /// Check if this key has Shift modifier
    pub fn has_shift(&self) -> bool {
        matches!(
            self,
            KeyInput::Shift(_) | KeyInput::ShiftUp | KeyInput::ShiftDown
        )
    }
}

// <FILE>crates/fast-fs/src/nav/key_input.rs</FILE>
// <VERS>END OF VERSION: 0.1.0</VERS>