#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Key {
Up,
Down,
Left,
Right,
Enter,
Escape,
Digit(u8),
Char(char),
Plus,
Minus,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ZoomStep {
In,
Out,
Reset,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mods {
Bare,
Command,
CommandShift,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Held {
Nothing,
TextBox,
Modal,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyAction {
ListPrev,
ListNext,
ExpandRow,
CollapseRow,
Tab(InspectorTab),
Center(CenterTab),
FocusComposer,
NewConversation,
NewWorkspace,
StartHead,
Stop,
Scan,
Search,
CloseBall,
ReleaseBall,
ToggleBalls,
ToggleModelPicker,
ToggleGrouping,
ToggleActivity,
Zoom(ZoomStep),
Fire,
Cancel,
DismissModal,
}
pub fn keymap(key: Key, mods: Mods, held: Held) -> Option<KeyAction> {
match mods {
Mods::Bare => bare_plane(key, held),
Mods::Command => command(key),
Mods::CommandShift => command_shift(key),
}
}
fn bare_plane(key: Key, held: Held) -> Option<KeyAction> {
match held {
Held::Nothing => bare(key),
Held::TextBox => None,
Held::Modal => matches!(key, Key::Escape).then_some(KeyAction::DismissModal),
}
}
fn bare(key: Key) -> Option<KeyAction> {
Some(match key {
Key::Up => KeyAction::ListPrev,
Key::Down => KeyAction::ListNext,
Key::Left => KeyAction::CollapseRow,
Key::Right => KeyAction::ExpandRow,
Key::Enter => KeyAction::Fire,
Key::Escape => KeyAction::Cancel,
Key::Digit(n) => KeyAction::Tab(InspectorTab::from_digit(n)?),
Key::Char('i') => KeyAction::FocusComposer,
Key::Char('n') => KeyAction::NewConversation,
Key::Char('w') => KeyAction::NewWorkspace,
Key::Char('s') => KeyAction::StartHead,
Key::Char('x') => KeyAction::Stop,
Key::Char('f') => KeyAction::Scan,
Key::Char('c') => KeyAction::CloseBall,
Key::Char('r') => KeyAction::ReleaseBall,
Key::Char('b') => KeyAction::ToggleBalls,
Key::Char('m') => KeyAction::ToggleModelPicker,
Key::Char('g') => KeyAction::ToggleGrouping,
Key::Char('a') => KeyAction::ToggleActivity,
Key::Char(_) | Key::Plus | Key::Minus => return None,
})
}
fn command(key: Key) -> Option<KeyAction> {
Some(match key {
Key::Up => KeyAction::ListPrev,
Key::Down => KeyAction::ListNext,
Key::Left => KeyAction::CollapseRow,
Key::Right => KeyAction::ExpandRow,
Key::Plus => KeyAction::Zoom(ZoomStep::In),
Key::Minus => KeyAction::Zoom(ZoomStep::Out),
Key::Digit(0) => KeyAction::Zoom(ZoomStep::Reset),
Key::Digit(n) => KeyAction::Tab(InspectorTab::from_digit(n)?),
Key::Char('i') => KeyAction::FocusComposer,
Key::Char('n') => KeyAction::NewConversation,
Key::Char('b') => KeyAction::ToggleBalls,
Key::Char('f') => KeyAction::Search,
Key::Char('g') => KeyAction::ToggleGrouping,
Key::Char('j') => KeyAction::ToggleActivity,
_ => return None,
})
}
fn command_shift(key: Key) -> Option<KeyAction> {
match key {
Key::Char('n') => Some(KeyAction::NewWorkspace),
Key::Plus => Some(KeyAction::Zoom(ZoomStep::In)),
Key::Digit(n) => CenterTab::from_digit(n).map(KeyAction::Center),
_ => None,
}
}
mod center;
#[cfg(test)]
pub(crate) mod spell;
mod tabs;
pub use center::CenterTab;
pub use tabs::InspectorTab;
#[cfg(test)]
mod tests;