Add configurable shortcuts for compact mail listing

concerns #63
embed
Manos Pitsidianakis 2019-03-03 14:24:15 +02:00
parent 1bb1cf7aac
commit d4c64916f0
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 119 additions and 1 deletions

View File

@ -26,11 +26,14 @@ extern crate bincode;
pub mod pager;
pub mod notifications;
pub mod shortcuts;
pub mod accounts;
pub use self::accounts::Account;
pub use self::shortcuts::*;
use self::config::{Config, File, FileFormat};
use melib::conf::AccountSettings;
use melib::error::*;
use pager::PagerSettings;
@ -113,6 +116,7 @@ struct FileSettings {
accounts: HashMap<String, FileAccount>,
pager: PagerSettings,
notifications: NotificationsSettings,
shortcuts: CompactListingShortcuts,
}
#[derive(Debug, Clone, Default)]
@ -138,6 +142,7 @@ pub struct Settings {
pub accounts: HashMap<String, AccountConf>,
pub pager: PagerSettings,
pub notifications: NotificationsSettings,
pub shortcuts: CompactListingShortcuts,
}
impl FileSettings {
@ -184,6 +189,7 @@ impl Settings {
accounts: s,
pager: fs.pager,
notifications: fs.notifications,
shortcuts: fs.shortcuts,
}
}
}

View File

@ -0,0 +1,65 @@
use types::Key;
//use std::any::TypeId;
use fnv::FnvHashMap;
#[macro_export]
macro_rules! key_values {
(derive ($($derives:ident),*) : pub struct $name:ident { $($fname:ident : Key),* }) => {
#[derive($($derives),*)]
#[serde(default)]
pub struct $name {
$($fname : Key),*
}
impl $name {
pub fn key_values(&self) -> FnvHashMap<&'static str, &Key> {
let mut map: FnvHashMap<&'static str, &Key> = Default::default();
$(map.insert(stringify!($fname),&(self.$fname));)*
map
}
}
}
}
key_values!{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
}
}
impl Default for CompactListingShortcuts {
fn default() -> Self {
CompactListingShortcuts {
open_thread: Key::Char('\n'),
exit_thread: Key::PageUp,
prev_page: Key::PageDown,
next_page: Key::Char('i'),
prev_folder: Key::Char('J'),
next_folder: Key::Char('K'),
prev_account:Key::Char('h'),
next_account:Key::Char('l'),
new_mail: Key::Char('m'),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_macro() {
panic!()
}
}

View File

@ -18,7 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
extern crate serde;
#[macro_use]
mod position;
#[macro_use]
@ -39,6 +39,8 @@ use std;
use std::fmt;
use std::thread;
use uuid::Uuid;
use self::serde::{de, Deserialize, Deserializer, };
use self::serde::de::Visitor;
#[derive(Debug)]
pub enum StatusEvent {

View File

@ -19,6 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use super::*;
use chan;
use std::fmt;
use std::io;
@ -199,3 +200,47 @@ derive_csi_sequence!("End Bracketed Paste Mode", BracketModeEnd, "?2003l");
pub const BRACKET_PASTE_START: &[u8] = b"\x1B[200~";
pub const BRACKET_PASTE_END: &[u8] = b"\x1B[201~";
const FIELDS: &'static [&'static str] = &[];
impl<'de> Deserialize<'de> for Key {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct KeyVisitor;
impl<'de> Visitor<'de> for KeyVisitor {
type Value = Key;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("`secs` or `nanos`")
}
fn visit_str<E>(self, value: &str) -> Result<Key, E>
where
E: de::Error,
{
match value {
"Backspace" => Ok(Key::Backspace),
"Left" => Ok(Key::Left),
"Right" => Ok(Key::Right),
"Up" => Ok(Key::Up),
"Down" => Ok(Key::Down),
"Home" => Ok(Key::Home),
"End" => Ok(Key::End),
"PageUp" => Ok(Key::PageUp),
"PageDown" => Ok(Key::PageDown),
"Delete" => Ok(Key::Delete),
"Insert" => Ok(Key::Insert),
"Esc" => Ok(Key::Esc),
ref s if s.len() == 1 => Ok(Key::Char(s.chars().nth(0).unwrap())),
_ => Err(de::Error::unknown_field(value, FIELDS)),
}
}
}
deserializer.deserialize_identifier(KeyVisitor)
}
}