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 ToggleBorder,
26
27 ToggleVisibleDivider,
31
32 ToggleMovableDivider,
36
37 ToggleOrientation,
43}
44
45impl Action {
46 pub fn defaults(orientation: Orientation) -> Actions {
48 match orientation {
49 Orientation::Horizontal => [
50 (Event::Shift(Key::Left), Self::MoveDividerToFront),
51 (Event::Shift(Key::Right), Self::MoveDividerToBack),
52 ],
53 Orientation::Vertical => {
54 [(Event::Shift(Key::Up), Self::MoveDividerToFront), (Event::Shift(Key::Down), Self::MoveDividerToBack)]
55 }
56 }
57 .into()
58 }
59
60 pub fn remove(&self, actions: &mut Actions) -> bool {
64 let events = self.events(actions);
65 for event in &events {
66 actions.remove(event);
67 }
68 !events.is_empty()
69 }
70
71 pub fn events(&self, actions: &Actions) -> Vec<Event> {
73 actions
74 .into_iter()
75 .filter_map(|(event, action)| if action == self { Some(event.clone()) } else { None })
76 .collect()
77 }
78}