use crate::key_code::KeyCode;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Action {
NoOp,
Trans,
KeyCode(KeyCode),
MultipleKeyCodes(&'static [KeyCode]),
MultipleActions(&'static [Action]),
Layer(usize),
DefaultLayer(usize),
HoldTap {
timeout: u16,
hold: &'static Action,
tap: &'static Action,
},
}
impl Action {
pub fn layer(self) -> Option<usize> {
match self {
Action::Layer(l) => Some(l),
_ => None,
}
}
pub fn key_codes<'a>(&'a self) -> impl Iterator<Item = KeyCode> + 'a {
match self {
Action::KeyCode(kc) => core::slice::from_ref(kc).iter().cloned(),
Action::MultipleKeyCodes(kcs) => kcs.iter().cloned(),
_ => [].iter().cloned(),
}
}
}
pub const fn k(kc: KeyCode) -> Action {
Action::KeyCode(kc)
}
pub const fn l(layer: usize) -> Action {
Action::Layer(layer)
}
pub const fn d(layer: usize) -> Action {
Action::DefaultLayer(layer)
}
pub const fn m(kcs: &'static [KeyCode]) -> Action {
Action::MultipleKeyCodes(kcs)
}