// Listens and interprets live keyboard input from the main menu
Listens and interprets live keyboard input from the main menu
Listens and interprets live keyboard input from the main menu
pub fn menu_input() -> (MenuAnswer, usize) {
    let stdin = stdin();
    let mut stdout = stdout().into_raw_mode().unwrap();
    write!(
        stdout,
        "{}{}{}",
        get_color(4),
        get_color(5),
        termion::cursor::Hide
    )
    .unwrap();
    stdout.flush().unwrap();
    let mut data = 0;
    let event = match stdin.events().next() {
        Some(ev) => match ev {
            Ok(eve) => eve,
            Err(_) => return (MenuAnswer::Nothing, 0),
        },
        None => return (MenuAnswer::Nothing, 0),
    };
    let ans = match event {
        Event::Key(key) => match key {
            Key::Left => MenuAnswer::CycleLeft,
            Key::Right => MenuAnswer::CycleRight,
            Key::Up => MenuAnswer::FirstPage,
            Key::Down => MenuAnswer::LastPage,
            Key::PageUp => MenuAnswer::CycleLeft,
            Key::PageDown => MenuAnswer::CycleRight,
            Key::Home => MenuAnswer::FirstPage,
            Key::End => MenuAnswer::LastPage,
            Key::Esc => MenuAnswer::RefreshPage,
            Key::Backspace => MenuAnswer::EditLastNote,
            Key::Char(ch) => match ch {
                d if d.is_digit(10) => {
                    let n = d.to_digit(10).unwrap() as usize;
                    if n > 0 {
                        data = n;
                        MenuAnswer::PageNumber
                    } else {
                        MenuAnswer::Nothing
                    }
                }
                'a' => MenuAnswer::AddNote,
                'A' => MenuAnswer::AddNoteStart,
                'e' => MenuAnswer::EditNote,
                'f' => MenuAnswer::FindNotes,
                'm' => MenuAnswer::MoveNotes,
                'd' => MenuAnswer::DeleteNotes,
                'F' => MenuAnswer::FindNotesSuggest,
                'S' => MenuAnswer::SwapNotes,
                'G' => MenuAnswer::GotoPage,
                'R' => MenuAnswer::ResetFile,
                'P' => MenuAnswer::ChangeSecurity,
                'H' => MenuAnswer::ShowAllNotes,
                'T' => MenuAnswer::ShowStats,
                '?' => MenuAnswer::ShowAbout,
                'O' => MenuAnswer::OpenFromPath,
                'N' => MenuAnswer::FetchSource,
                'Q' => MenuAnswer::Exit,
                '+' => MenuAnswer::IncreasePageSize,
                '-' => MenuAnswer::DecreasePageSize,
                ':' => MenuAnswer::ScreenSaver,
                'U' => MenuAnswer::Undo,
                'X' => MenuAnswer::Destroy,
                '\n' => MenuAnswer::ModeAction,
                '^' => MenuAnswer::ChangeRowSpace,
                '$' => MenuAnswer::ChangeColors,
                ' ' => MenuAnswer::ChangeMenu,
                _ => MenuAnswer::Nothing,
            },
            Key::Ctrl(ch) => match ch {
                'c' => MenuAnswer::Exit,
                _ => MenuAnswer::Nothing,
            },
            _ => MenuAnswer::Nothing,
        },
        Event::Mouse(moe) => match moe {
            MouseEvent::Press(btn, _, _) => match btn {
                MouseButton::WheelUp => MenuAnswer::CycleLeft,
                MouseButton::WheelDown => MenuAnswer::CycleRight,
                _ => MenuAnswer::Nothing,
            },
            _ => MenuAnswer::Nothing,
        },
        _ => MenuAnswer::Nothing,
    };
    write!(stdout, "{}", termion::cursor::Show).unwrap();
    stdout.flush().unwrap();
    (ans, data)
}
pub fn menu_input ( ) -> ( MenuAnswer , usize ) { let stdin = stdin ( ) ; let mut stdout = stdout ( ) . into_raw_mode ( ) . unwrap ( ) ; write ! ( stdout " " get_color ( 4 ) get_color ( 5 ) termion cursor Hide ) . unwrap ( ) ; stdout . flush ( ) . unwrap ( ) ; let mut data = 0 ; let event = match stdin . events ( ) . next ( ) { Some ( ev ) => match ev { Ok ( eve ) => eve , Err ( _ ) => return ( MenuAnswer :: Nothing , 0 ) , } , None => return ( MenuAnswer :: Nothing , 0 ) , } ; let ans = match event { Event :: Key ( key ) => match key { Key :: Left => MenuAnswer :: CycleLeft , Key :: Right => MenuAnswer :: CycleRight , Key :: Up => MenuAnswer :: FirstPage , Key :: Down => MenuAnswer :: LastPage , Key :: PageUp => MenuAnswer :: CycleLeft , Key :: PageDown => MenuAnswer :: CycleRight , Key :: Home => MenuAnswer :: FirstPage , Key :: End => MenuAnswer :: LastPage , Key :: Esc => MenuAnswer :: RefreshPage , Key :: Backspace => MenuAnswer :: EditLastNote , Key :: Char ( ch ) => match ch { d if d . is_digit ( 10 ) => { let n = d . to_digit ( 10 ) . unwrap ( ) as usize ; if n > 0 { data = n ; MenuAnswer :: PageNumber } else { MenuAnswer :: Nothing } } 'a' => MenuAnswer :: AddNote , 'A' => MenuAnswer :: AddNoteStart , 'e' => MenuAnswer :: EditNote , 'f' => MenuAnswer :: FindNotes , 'm' => MenuAnswer :: MoveNotes , 'd' => MenuAnswer :: DeleteNotes , 'F' => MenuAnswer :: FindNotesSuggest , 'S' => MenuAnswer :: SwapNotes , 'G' => MenuAnswer :: GotoPage , 'R' => MenuAnswer :: ResetFile , 'P' => MenuAnswer :: ChangeSecurity , 'H' => MenuAnswer :: ShowAllNotes , 'T' => MenuAnswer :: ShowStats , '?' => MenuAnswer :: ShowAbout , 'O' => MenuAnswer :: OpenFromPath , 'N' => MenuAnswer :: FetchSource , 'Q' => MenuAnswer :: Exit , '+' => MenuAnswer :: IncreasePageSize , '-' => MenuAnswer :: DecreasePageSize , ':' => MenuAnswer :: ScreenSaver , 'U' => MenuAnswer :: Undo , 'X' => MenuAnswer :: Destroy , '\n' => MenuAnswer :: ModeAction , '^' => MenuAnswer :: ChangeRowSpace , '$' => MenuAnswer :: ChangeColors , ' ' => MenuAnswer :: ChangeMenu , _ => MenuAnswer :: Nothing , } , Key :: Ctrl ( ch ) => match ch { 'c' => MenuAnswer :: Exit , _ => MenuAnswer :: Nothing , } , _ => MenuAnswer :: Nothing , } , Event :: Mouse ( moe ) => match moe { MouseEvent :: Press ( btn , _ , _ ) => match btn { MouseButton :: WheelUp => MenuAnswer :: CycleLeft , MouseButton :: WheelDown => MenuAnswer :: CycleRight , _ => MenuAnswer :: Nothing , } , _ => MenuAnswer :: Nothing , } , _ => MenuAnswer :: Nothing , } ; write ! ( stdout " " termion cursor Show ) . unwrap ( ) ; stdout . flush ( ) . unwrap ( ) ; ( ans , data ) }
Listens and interprets live keyboard input from the main menu
Listens and interprets live keyboard input from the main menu