#![warn(clippy::pedantic)]
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Keymap {
pub id: &'static str,
pub name: &'static str,
pub tooltip: &'static str,
}
pub const KEYMAPS: &[Keymap] = &[
Keymap {
id: "apple",
name: "Apple",
tooltip: "Apple controls",
},
Keymap {
id: "vscode-macos",
name: "VSCode macOS",
tooltip: "VS Code (macOS) bindings",
},
Keymap {
id: "vscode-windows",
name: "VSCode Windows",
tooltip: "VS Code (Windows) bindings",
},
Keymap {
id: "emacs",
name: "Emacs",
tooltip: "Emacs chords",
},
Keymap {
id: "vi",
name: "Vi",
tooltip: "Vi modes",
},
Keymap {
id: "spacemacs",
name: "Spacemacs",
tooltip: "Vi modes + Space leader",
},
Keymap {
id: "intellij-macos",
name: "IntelliJ macOS",
tooltip: "IntelliJ (macOS) bindings",
},
Keymap {
id: "intellij-windows",
name: "IntelliJ Windows",
tooltip: "IntelliJ (Windows) bindings",
},
Keymap {
id: "eclipse",
name: "Eclipse",
tooltip: "Eclipse (Windows) bindings",
},
Keymap {
id: "sublime",
name: "Sublime Text",
tooltip: "Sublime Text bindings",
},
];
#[must_use]
pub fn by_id(id: &str) -> Option<&'static Keymap> {
KEYMAPS.iter().find(|k| k.id == id)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ids_are_unique_and_lookups_work() {
for k in KEYMAPS {
assert_eq!(by_id(k.id).map(|m| m.id), Some(k.id));
}
assert!(by_id("nope").is_none());
assert_eq!(KEYMAPS[0].id, "apple");
}
}