summaryrefslogtreecommitdiffstats
path: root/ui/src/conf/shortcuts.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-03-04 10:15:11 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:39 +0300
commitb437e55b676585403d261f887514b5260591aee0 (patch)
tree780a2062bed671306b84a2a0588d44ca380ba342 /ui/src/conf/shortcuts.rs
parent1f200cfc88decb60e2c197460e6587c7ba5f1611 (diff)
use shortcuts from config or default
closes #63
Diffstat (limited to 'ui/src/conf/shortcuts.rs')
-rw-r--r--ui/src/conf/shortcuts.rs74
1 files changed, 63 insertions, 11 deletions
diff --git a/ui/src/conf/shortcuts.rs b/ui/src/conf/shortcuts.rs
index bea6b0da..c7f23f0c 100644
--- a/ui/src/conf/shortcuts.rs
+++ b/ui/src/conf/shortcuts.rs
@@ -2,9 +2,19 @@ use types::Key;
//use std::any::TypeId;
use fnv::FnvHashMap;
+#[derive(Debug, Clone, Default, Deserialize)]
+pub struct Shortcuts {
+ #[serde(flatten)]
+ pub compact_listing: CompactListingShortcuts,
+ #[serde(flatten)]
+ pub contact_list: ContactListShortcuts,
+ #[serde(flatten)]
+ pub pager: PagerShortcuts,
+}
+
#[macro_export]
macro_rules! key_values {
- ( $cname:expr, derive ($($derives:ident),*) : pub struct $name:ident { $($fname:ident : Key),* }) => {
+ ( $cname:expr, derive ($($derives:ident),*) : pub struct $name:ident { $($fname:ident : Key |> $fdesc:expr),* }) => {
#[derive($($derives),*)]
#[serde(default)]
#[serde(rename = $cname)]
@@ -13,6 +23,12 @@ macro_rules! key_values {
}
impl $name {
+ pub fn key_desc(&self, key: &str) -> &'static str {
+ match key {
+ $(stringify!($fname) => $fdesc),*,
+ _ => unreachable!()
+ }
+ }
pub fn key_values(&self) -> FnvHashMap<&'static str, &Key> {
let mut map: FnvHashMap<&'static str, &Key> = Default::default();
$(map.insert(stringify!($fname),&(self.$fname));)*
@@ -24,22 +40,22 @@ macro_rules! key_values {
key_values!{ "compact-listing", derive (Debug, Clone, Deserialize) :
pub struct CompactListingShortcuts {
- open_thread: Key,
- exit_thread: Key,
- prev_page: Key,
- next_page: Key,
- prev_folder: Key,
- next_folder: Key,
- prev_account: Key,
- next_account: Key,
- new_mail: Key
+ open_thread: Key |> "Open thread.",
+ exit_thread: Key |> "Exit thread view.",
+ prev_page: Key |> "Go to previous page.",
+ next_page: Key |> "Go to next page.",
+ prev_folder: Key |> "Go to previous folder.",
+ next_folder: Key |> "Go to next folder.",
+ prev_account: Key |> "Go to previous account.",
+ next_account: Key |> "Go to next account.",
+ new_mail: Key |> "Start new mail draft in new tab."
}
}
impl Default for CompactListingShortcuts {
fn default() -> Self {
- CompactListingShortcuts {
+ CompactListingShortcuts {
open_thread: Key::Char('\n'),
exit_thread: Key::Char('i'),
prev_page: Key::PageUp,
@@ -52,3 +68,39 @@ impl Default for CompactListingShortcuts {
}
}
}
+
+key_values!{ "contact-list", derive (Debug, Clone, Deserialize) :
+pub struct ContactListShortcuts {
+ create_contact: Key |> "Create new contact.",
+ edit_contact: Key |> "Edit contact under cursor."
+}
+}
+
+impl Default for ContactListShortcuts {
+ fn default() -> Self {
+ ContactListShortcuts {
+ create_contact: Key::Char('c'),
+ edit_contact: Key::Char('e'),
+ }
+ }
+}
+
+key_values!{ "pager", derive (Debug, Clone, Deserialize) :
+pub struct PagerShortcuts {
+ scroll_up: Key |> "Scroll up pager.",
+ scroll_down: Key |> "Scroll down pager.",
+ page_up: Key |> "Go to previous pager page",
+ page_down: Key |> "Go to next pager page"
+}
+}
+
+impl Default for PagerShortcuts {
+ fn default() -> Self {
+ PagerShortcuts {
+ scroll_up: Key::Char('k'),
+ scroll_down: Key::Char('j'),
+ page_up: Key::PageUp,
+ page_down: Key::PageDown,
+ }
+ }
+}