parent
1bb1cf7aac
commit
d4c64916f0
|
@ -26,11 +26,14 @@ extern crate bincode;
|
||||||
|
|
||||||
pub mod pager;
|
pub mod pager;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
|
pub mod shortcuts;
|
||||||
|
|
||||||
pub mod accounts;
|
pub mod accounts;
|
||||||
pub use self::accounts::Account;
|
pub use self::accounts::Account;
|
||||||
|
pub use self::shortcuts::*;
|
||||||
use self::config::{Config, File, FileFormat};
|
use self::config::{Config, File, FileFormat};
|
||||||
|
|
||||||
|
|
||||||
use melib::conf::AccountSettings;
|
use melib::conf::AccountSettings;
|
||||||
use melib::error::*;
|
use melib::error::*;
|
||||||
use pager::PagerSettings;
|
use pager::PagerSettings;
|
||||||
|
@ -113,6 +116,7 @@ struct FileSettings {
|
||||||
accounts: HashMap<String, FileAccount>,
|
accounts: HashMap<String, FileAccount>,
|
||||||
pager: PagerSettings,
|
pager: PagerSettings,
|
||||||
notifications: NotificationsSettings,
|
notifications: NotificationsSettings,
|
||||||
|
shortcuts: CompactListingShortcuts,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
@ -138,6 +142,7 @@ pub struct Settings {
|
||||||
pub accounts: HashMap<String, AccountConf>,
|
pub accounts: HashMap<String, AccountConf>,
|
||||||
pub pager: PagerSettings,
|
pub pager: PagerSettings,
|
||||||
pub notifications: NotificationsSettings,
|
pub notifications: NotificationsSettings,
|
||||||
|
pub shortcuts: CompactListingShortcuts,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileSettings {
|
impl FileSettings {
|
||||||
|
@ -184,6 +189,7 @@ impl Settings {
|
||||||
accounts: s,
|
accounts: s,
|
||||||
pager: fs.pager,
|
pager: fs.pager,
|
||||||
notifications: fs.notifications,
|
notifications: fs.notifications,
|
||||||
|
shortcuts: fs.shortcuts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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!()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod position;
|
mod position;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -39,6 +39,8 @@ use std;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use self::serde::{de, Deserialize, Deserializer, };
|
||||||
|
use self::serde::de::Visitor;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum StatusEvent {
|
pub enum StatusEvent {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use chan;
|
use chan;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
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_START: &[u8] = b"\x1B[200~";
|
||||||
pub const BRACKET_PASTE_END: &[u8] = b"\x1B[201~";
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue