/// parse a string as a keyboard key definition.
///
/// Note that some mappings allowed by crossterm aren't
/// parsed because we don't want to let the user override
/// the related behaviors.
parse a string as a keyboard key definition.
Note that some mappings allowed by crossterm aren't
parsed because we don't want to let the user override
the related behaviors.
parse a string as a keyboard key definition . Note that some mappings allowed by crossterm aren ' t parsed because we don ' t want to let the user override the related behaviors .
pub fn parse_key(raw: &str) -> Result<KeyEvent, ConfError> {
    let key_regex = regex!(
        r"(?x)
        ^
        (?P<major>([a-zA-Z]+|\^))
        (?:\W?(?P<minor>\w\d?)\W?)?
        $
        "
    );
    match key_regex.captures(raw) {
        Some(c) => Ok(match (
                c.name("major").unwrap().as_str().to_ascii_lowercase().as_ref(), c.name("minor")
            ) {
            ("left", None) => KeyEvent::Left,
            ("right", None) => KeyEvent::Right,
            ("up", None) => KeyEvent::Up,
            ("down", None) => KeyEvent::Down,
            ("home", None) => KeyEvent::Home,
            ("end", None) => KeyEvent::End,
            ("pageup", None) => KeyEvent::PageUp,
            ("pagedown", None) => KeyEvent::PageDown,
            ("backtab", None) => KeyEvent::BackTab,
            ("delete", None) => KeyEvent::Delete,
            ("insert", None) => KeyEvent::Insert,
            ("f", Some(minor)) => match minor.as_str().parse() {
                    Ok(digit) => KeyEvent::F(digit),
                    _ => bad_key(raw)?
            },
            ("alt", Some(minor)) => KeyEvent::Alt(
                minor.as_str().chars().next().unwrap().to_ascii_lowercase()
            ),
            ("ctrl", Some(minor)) | ("^", Some(minor)) => KeyEvent::Ctrl(
                minor.as_str().chars().next().unwrap().to_ascii_lowercase()
            ),
            // other possible mappings are disabled as they would break basic behaviors of broot
            _ => bad_key(raw)?
        }),
        None => bad_key(raw)
    }
}
pub fn parse_key ( raw : & str ) -> Result < KeyEvent , ConfError > { let key_regex = regex ! ( r"(?x)
        ^
        (?P<major>([a-zA-Z]+|\^))
        (?:\W?(?P<minor>\w\d?)\W?)?
        $
        " ) ; match key_regex . captures ( raw ) { Some ( c ) => Ok ( match ( c . name ( " " ) . unwrap ( ) . as_str ( ) . to_ascii_lowercase ( ) . as_ref ( ) , c . name ( " " ) ) { ( " " , None ) => KeyEvent :: Left , ( " " , None ) => KeyEvent :: Right , ( " " , None ) => KeyEvent :: Up , ( " " , None ) => KeyEvent :: Down , ( " " , None ) => KeyEvent :: Home , ( " " , None ) => KeyEvent :: End , ( " " , None ) => KeyEvent :: PageUp , ( " " , None ) => KeyEvent :: PageDown , ( " " , None ) => KeyEvent :: BackTab , ( " " , None ) => KeyEvent :: Delete , ( " " , None ) => KeyEvent :: Insert , ( " " , Some ( minor ) ) => match minor . as_str ( ) . parse ( ) { Ok ( digit ) => KeyEvent :: F ( digit ) , _ => bad_key ( raw ) ? } , ( " " , Some ( minor ) ) => KeyEvent :: Alt ( minor . as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . to_ascii_lowercase ( ) ) , ( " " , Some ( minor ) ) | ( " " , Some ( minor ) ) => KeyEvent :: Ctrl ( minor . as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . to_ascii_lowercase ( ) ) , // other possible mappings are disabled as they would break basic behaviors of broot _ => bad_key ( raw ) ? } ) , None => bad_key ( raw ) } }
parse a string as a keyboard key definition.
parse a string as a keyboard key definition .
raw
&str