use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use crate::app::View; pub enum Action { Quit, NavigateUp, NavigateDown, NavigateLeft, NavigateRight, Select, Back, Search, Import, Delete, DeleteSelected, Open, TagView, CollectionView, AuditView, SettingsView, DuplicatesView, DatabaseView, QueueView, StatisticsView, TasksView, ScanTrigger, Refresh, NextTab, PrevTab, PageUp, PageDown, GoTop, GoBottom, CreateTag, TagMedia, UntagMedia, Help, Char(char), Backspace, None, } pub fn handle_key(key: KeyEvent, in_input_mode: bool, current_view: &View) -> Action { if in_input_mode { match key.code { KeyCode::Esc => Action::Back, KeyCode::Enter => Action::Select, KeyCode::Char(c) => Action::Char(c), KeyCode::Backspace => Action::Backspace, _ => Action::None, } } else { match (key.code, key.modifiers) { (KeyCode::Char('q'), _) | (KeyCode::Char('c'), KeyModifiers::CONTROL) => Action::Quit, (KeyCode::Up | KeyCode::Char('k'), _) => Action::NavigateUp, (KeyCode::Down | KeyCode::Char('j'), _) => Action::NavigateDown, (KeyCode::Left | KeyCode::Char('h'), _) => Action::NavigateLeft, (KeyCode::Right | KeyCode::Char('l'), _) => Action::NavigateRight, (KeyCode::Home, _) => Action::GoTop, (KeyCode::End, _) => Action::GoBottom, (KeyCode::Enter, _) => Action::Select, (KeyCode::Esc, _) => Action::Back, (KeyCode::Char('/'), _) => Action::Search, (KeyCode::Char('?'), _) => Action::Help, (KeyCode::Char('i'), _) => Action::Import, (KeyCode::Char('d'), _) => match current_view { View::Tags | View::Collections => Action::DeleteSelected, _ => Action::Delete, }, (KeyCode::Char('o'), _) => Action::Open, (KeyCode::Char('e'), _) => match current_view { View::Detail => Action::Select, _ => Action::None, }, (KeyCode::Char('t'), _) => Action::TagView, (KeyCode::Char('c'), _) => Action::CollectionView, (KeyCode::Char('a'), _) => Action::AuditView, (KeyCode::Char('S'), _) => Action::SettingsView, (KeyCode::Char('D'), _) => Action::DuplicatesView, (KeyCode::Char('B'), _) => Action::DatabaseView, (KeyCode::Char('Q'), _) => Action::QueueView, (KeyCode::Char('X'), _) => Action::StatisticsView, (KeyCode::Char('T'), _) => Action::TasksView, (KeyCode::Char('s'), _) => Action::ScanTrigger, (KeyCode::Char('r'), _) => Action::Refresh, (KeyCode::Char('n'), _) => Action::CreateTag, (KeyCode::Char('+'), _) => Action::TagMedia, (KeyCode::Char('-'), _) => Action::UntagMedia, (KeyCode::Tab, _) => Action::NextTab, (KeyCode::BackTab, _) => Action::PrevTab, (KeyCode::PageUp, _) => Action::PageUp, (KeyCode::PageDown, _) => Action::PageDown, _ => Action::None, } } }