use crate::key_code::KeyCode;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum SequenceEvent {
NoOp,
Press(KeyCode),
Release(KeyCode),
Tap(KeyCode),
Delay {
duration: u32, },
Continue {
index: usize,
events: &'static [SequenceEvent],
},
Complete,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum HoldTapConfig {
Default,
HoldOnOtherKeyPress,
PermissiveHold,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Action<T = core::convert::Infallible>
where
T: 'static,
{
NoOp,
Trans,
KeyCode(KeyCode),
MultipleKeyCodes(&'static [KeyCode]),
MultipleActions(&'static [Action<T>]),
Layer(usize),
DefaultLayer(usize),
HoldTap {
timeout: u16,
hold: &'static Action<T>,
tap: &'static Action<T>,
config: HoldTapConfig,
tap_hold_interval: u16,
},
Sequence {
events: &'static [SequenceEvent],
},
CancelSequences,
Custom(T),
}
impl<T> Action<T> {
pub fn layer(self) -> Option<usize> {
match self {
Action::Layer(l) => Some(l),
_ => None,
}
}
pub fn key_codes(&self) -> impl Iterator<Item = KeyCode> + '_ {
match self {
Action::KeyCode(kc) => core::slice::from_ref(kc).iter().cloned(),
Action::MultipleKeyCodes(kcs) => kcs.iter().cloned(),
_ => [].iter().cloned(),
}
}
}
pub const fn k<T>(kc: KeyCode) -> Action<T> {
Action::KeyCode(kc)
}
pub const fn l<T>(layer: usize) -> Action<T> {
Action::Layer(layer)
}
pub const fn d<T>(layer: usize) -> Action<T> {
Action::DefaultLayer(layer)
}
pub const fn m<T>(kcs: &'static [KeyCode]) -> Action<T> {
Action::MultipleKeyCodes(kcs)
}