use {cursive::event::*, std::collections::*};
pub type Actions = HashMap<Event, Action>;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
SelectTop,
SelectUp,
SelectUpPage,
SelectBottom,
SelectDown,
SelectDownPage,
Expand,
ExpandRecursive,
ExpandAll,
Collapse,
CollapseRecursive,
CollapseAll,
ToggleState,
ToggleDebug,
}
impl Action {
pub fn defaults() -> Actions {
[
(Event::Key(Key::Home), Self::SelectTop),
(Event::Key(Key::Up), Self::SelectUp),
(Event::Key(Key::PageUp), Self::SelectUpPage),
(Event::Key(Key::End), Self::SelectBottom),
(Event::Key(Key::Down), Self::SelectDown),
(Event::Key(Key::PageDown), Self::SelectDownPage),
(Event::Key(Key::Right), Self::Expand),
(Event::Char('+'), Self::ExpandRecursive),
(Event::Char('>'), Self::ExpandAll),
(Event::Key(Key::Left), Self::Collapse),
(Event::Char('-'), Self::CollapseRecursive),
(Event::Char('<'), Self::CollapseAll),
(Event::Key(Key::Enter), Self::ToggleState),
]
.into()
}
pub fn remove(&self, actions: &mut Actions) -> bool {
let events = self.events(actions);
for event in &events {
actions.remove(event);
}
!events.is_empty()
}
pub fn events(&self, actions: &Actions) -> Vec<Event> {
actions
.into_iter()
.filter_map(|(event, action)| if action == self { Some(event.clone()) } else { None })
.collect()
}
}