cursive_split_panel/
actions.rs1use {
2 cursive::{direction::*, event::*},
3 std::collections::*,
4};
5
6pub type Actions = HashMap<Event, Action>;
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub enum Action {
16 MoveDividerToFront,
18
19 MoveDividerToBack,
21}
22
23impl Action {
24 pub fn defaults(orientation: Orientation) -> Actions {
26 match orientation {
27 Orientation::Horizontal => [
28 (Event::Shift(Key::Left), Self::MoveDividerToFront),
29 (Event::Shift(Key::Right), Self::MoveDividerToBack),
30 ],
31 Orientation::Vertical => {
32 [(Event::Shift(Key::Up), Self::MoveDividerToFront), (Event::Shift(Key::Down), Self::MoveDividerToBack)]
33 }
34 }
35 .into()
36 }
37
38 pub fn remove(&self, actions: &mut Actions) -> bool {
42 let events = self.events(actions);
43 for event in &events {
44 actions.remove(event);
45 }
46 !events.is_empty()
47 }
48
49 pub fn events(&self, actions: &Actions) -> Vec<Event> {
51 actions
52 .into_iter()
53 .filter_map(|(event, action)| if action == self { Some(event.clone()) } else { None })
54 .collect()
55 }
56}