Skip to main content

verso/ui/keymap/
actions.rs

1use std::str::FromStr;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum Action {
5    // Movement
6    MoveDown,
7    MoveUp,
8    PageDown,
9    PageUp,
10    HalfPageDown,
11    HalfPageUp,
12    GotoTop,
13    GotoBottom,
14    NextChapter,
15    PrevChapter,
16    // Counts / commands
17    BeginCount(u8),
18    BeginCmd,
19    BeginSearchFwd,
20    BeginSearchBack,
21    SearchNext,
22    SearchPrev,
23    // Marks
24    MarkSetPrompt,
25    MarkJumpPrompt,
26    // Highlights
27    VisualSelect,
28    YankHighlight,
29    ListHighlights,
30    // View
31    ToggleTheme,
32    CycleWidth,
33    Help,
34    // Quit
35    QuitToLibrary,
36}
37
38impl FromStr for Action {
39    type Err = String;
40    fn from_str(s: &str) -> Result<Self, String> {
41        Ok(match s {
42            "move_down" => Action::MoveDown,
43            "move_up" => Action::MoveUp,
44            "page_down" => Action::PageDown,
45            "page_up" => Action::PageUp,
46            "half_page_down" => Action::HalfPageDown,
47            "half_page_up" => Action::HalfPageUp,
48            "goto_top" => Action::GotoTop,
49            "goto_bottom" => Action::GotoBottom,
50            "next_chapter" => Action::NextChapter,
51            "prev_chapter" => Action::PrevChapter,
52            "cmd" => Action::BeginCmd,
53            "search_forward" => Action::BeginSearchFwd,
54            "search_backward" => Action::BeginSearchBack,
55            "search_next" => Action::SearchNext,
56            "search_prev" => Action::SearchPrev,
57            "mark_set" => Action::MarkSetPrompt,
58            "mark_jump" => Action::MarkJumpPrompt,
59            "visual_select" => Action::VisualSelect,
60            "yank_highlight" => Action::YankHighlight,
61            "list_highlights" => Action::ListHighlights,
62            "toggle_theme" => Action::ToggleTheme,
63            "cycle_width" => Action::CycleWidth,
64            "help" => Action::Help,
65            "quit_to_library" => Action::QuitToLibrary,
66            other => return Err(format!("unknown action: {other}")),
67        })
68    }
69}