You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shortcuts.rs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. use crate::terminal::Key;
  2. //use std::any::TypeId;
  3. use fnv::FnvHashMap;
  4. #[derive(Debug, Clone, Default, Deserialize)]
  5. pub struct Shortcuts {
  6. #[serde(flatten)]
  7. pub listing: ListingShortcuts,
  8. #[serde(flatten)]
  9. pub compact_listing: CompactListingShortcuts,
  10. #[serde(flatten)]
  11. pub contact_list: ContactListShortcuts,
  12. #[serde(flatten)]
  13. pub pager: PagerShortcuts,
  14. }
  15. /// Create a struct holding all of a Component's shortcuts.
  16. #[macro_export]
  17. macro_rules! shortcut_key_values {
  18. (
  19. $cname:expr,
  20. $(#[$outer:meta])*
  21. pub struct $name:ident { $($fname:ident : Key |> $fdesc:expr),* }) => {
  22. $(#[$outer])*
  23. #[derive(Debug, Clone, Deserialize)]
  24. #[serde(default)]
  25. #[serde(rename = $cname)]
  26. pub struct $name {
  27. $($fname : Key),*
  28. }
  29. impl $name {
  30. /// Returns a shortcut's description
  31. pub fn key_desc(&self, key: &str) -> &'static str {
  32. match key {
  33. $(stringify!($fname) => $fdesc),*,
  34. _ => unreachable!()
  35. }
  36. }
  37. /// Returns a hashmap of all shortcuts and their values
  38. pub fn key_values(&self) -> FnvHashMap<&'static str, &Key> {
  39. [
  40. $((stringify!($fname),&(self.$fname)),)*
  41. ].iter().cloned().collect()
  42. }
  43. }
  44. }
  45. }
  46. shortcut_key_values! { "compact_listing",
  47. /// Shortcut listing for a mail listing in compact mode.
  48. pub struct CompactListingShortcuts {
  49. open_thread: Key |> "Open thread.",
  50. exit_thread: Key |> "Exit thread view."
  51. }
  52. }
  53. impl Default for CompactListingShortcuts {
  54. fn default() -> Self {
  55. CompactListingShortcuts {
  56. open_thread: Key::Char('\n'),
  57. exit_thread: Key::Char('i'),
  58. }
  59. }
  60. }
  61. shortcut_key_values! { "listing",
  62. /// Shortcut listing for a mail listing.
  63. pub struct ListingShortcuts {
  64. prev_page: Key |> "Go to previous page.",
  65. next_page: Key |> "Go to next page.",
  66. prev_folder: Key |> "Go to previous folder.",
  67. next_folder: Key |> "Go to next folder.",
  68. prev_account: Key |> "Go to previous account.",
  69. next_account: Key |> "Go to next account.",
  70. new_mail: Key |> "Start new mail draft in new tab."
  71. }
  72. }
  73. impl Default for ListingShortcuts {
  74. fn default() -> Self {
  75. ListingShortcuts {
  76. prev_page: Key::PageUp,
  77. next_page: Key::PageDown,
  78. prev_folder: Key::Char('K'),
  79. next_folder: Key::Char('J'),
  80. prev_account: Key::Char('l'),
  81. next_account: Key::Char('h'),
  82. new_mail: Key::Char('m'),
  83. }
  84. }
  85. }
  86. shortcut_key_values! { "contact-list",
  87. /// Shortcut listing for the contact list view
  88. pub struct ContactListShortcuts {
  89. create_contact: Key |> "Create new contact.",
  90. edit_contact: Key |> "Edit contact under cursor."
  91. }
  92. }
  93. impl Default for ContactListShortcuts {
  94. fn default() -> Self {
  95. ContactListShortcuts {
  96. create_contact: Key::Char('c'),
  97. edit_contact: Key::Char('e'),
  98. }
  99. }
  100. }
  101. shortcut_key_values! { "pager",
  102. /// Shortcut listing for the text pager
  103. pub struct PagerShortcuts {
  104. scroll_up: Key |> "Scroll up pager.",
  105. scroll_down: Key |> "Scroll down pager.",
  106. page_up: Key |> "Go to previous pager page",
  107. page_down: Key |> "Go to next pager page"
  108. }
  109. }
  110. impl Default for PagerShortcuts {
  111. fn default() -> Self {
  112. PagerShortcuts {
  113. scroll_up: Key::Char('k'),
  114. scroll_down: Key::Char('j'),
  115. page_up: Key::PageUp,
  116. page_down: Key::PageDown,
  117. }
  118. }
  119. }