#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Key {
Up,
Down,
Digit(u8),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum InspectorTab {
#[default]
Transcript,
Steps,
Inbox,
Files,
Config,
}
impl InspectorTab {
pub fn from_digit(n: u8) -> Option<Self> {
Some(match n {
1 => Self::Transcript,
2 => Self::Steps,
3 => Self::Inbox,
4 => Self::Files,
5 => Self::Config,
_ => return None,
})
}
pub(crate) fn label(self) -> &'static str {
match self {
Self::Transcript => "Transcript",
Self::Steps => "Steps",
Self::Inbox => "Inbox",
Self::Files => "Files",
Self::Config => "Config",
}
}
pub fn all() -> [Self; 5] {
[
Self::Transcript,
Self::Steps,
Self::Inbox,
Self::Files,
Self::Config,
]
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyAction {
RosterPrev,
RosterNext,
Tab(InspectorTab),
}
pub fn keymap(key: Key) -> Option<KeyAction> {
match key {
Key::Up => Some(KeyAction::RosterPrev),
Key::Down => Some(KeyAction::RosterNext),
Key::Digit(n) => InspectorTab::from_digit(n).map(KeyAction::Tab),
}
}
#[cfg(test)]
mod tests;