use {
cursive::{direction::*, event::*},
std::collections::*,
};
pub type Actions = HashMap<Event, Action>;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
MoveDividerToFront,
MoveDividerToBack,
ToggleBorder,
ToggleVisibleDivider,
ToggleMovableDivider,
ToggleOrientation,
}
impl Action {
pub fn defaults(orientation: Orientation) -> Actions {
match orientation {
Orientation::Horizontal => [
(Event::Shift(Key::Left), Self::MoveDividerToFront),
(Event::Shift(Key::Right), Self::MoveDividerToBack),
],
Orientation::Vertical => {
[(Event::Shift(Key::Up), Self::MoveDividerToFront), (Event::Shift(Key::Down), Self::MoveDividerToBack)]
}
}
.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()
}
}