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