use super::{Held, Key, KeyAction, Mods, keymap};
const PLANES: [Mods; 3] = [Mods::Bare, Mods::Command, Mods::CommandShift];
pub(crate) const FLOOR: &str = "Tab";
fn keys() -> Vec<Key> {
let mut all = vec![
Key::Up,
Key::Down,
Key::Left,
Key::Right,
Key::Enter,
Key::Escape,
Key::Plus,
Key::Minus,
];
all.extend((0..=9).map(Key::Digit));
all.extend(('a'..='z').map(Key::Char));
all
}
pub(crate) fn bindings() -> Vec<(String, KeyAction)> {
let mut found = Vec::new();
for mods in PLANES {
for key in keys() {
if let Some(action) = keymap(key, mods, Held::Nothing) {
found.push((press(key, mods), action));
}
}
}
found
}
pub(crate) fn spellings() -> Vec<String> {
let mut found: Vec<String> = Vec::new();
for (press, _) in bindings() {
if !found.contains(&press) {
found.push(press);
}
}
found
}
fn press(key: Key, mods: Mods) -> String {
let name = name_of(key);
match mods {
Mods::Bare if name.len() == 1 => format!("({name})"),
Mods::Bare => name,
Mods::Command => format!("Ctrl+{}", name.to_uppercase()),
Mods::CommandShift => format!("Ctrl+Shift+{}", name.to_uppercase()),
}
}
fn name_of(key: Key) -> String {
match key {
Key::Up => "↑".to_owned(),
Key::Down => "↓".to_owned(),
Key::Left => "←".to_owned(),
Key::Right => "→".to_owned(),
Key::Enter => "Enter".to_owned(),
Key::Escape => "Escape".to_owned(),
Key::Digit(n) => n.to_string(),
Key::Char(c) => c.to_string(),
Key::Plus => "+".to_owned(),
Key::Minus => "-".to_owned(),
}
}