aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/config.rs b/src/config.rs
index 62e0ba49..ada6f8d1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -378,6 +378,17 @@ impl de::Deserialize for ActionWrapper {
}
}
+#[derive(Debug, Deserialize)]
+#[serde(untagged)]
+enum CommandWrapper {
+ Just(String),
+ WithArgs {
+ program: String,
+ #[serde(default)]
+ args: Vec<String>,
+ },
+}
+
use ::term::{mode, TermMode};
struct ModeWrapper {
@@ -517,7 +528,8 @@ impl de::Deserialize for RawBinding {
Mode,
Action,
Chars,
- Mouse
+ Mouse,
+ Command,
}
impl de::Deserialize for Field {
@@ -527,7 +539,7 @@ impl de::Deserialize for RawBinding {
struct FieldVisitor;
static FIELDS: &'static [&'static str] = &[
- "key", "mods", "mode", "action", "chars", "mouse"
+ "key", "mods", "mode", "action", "chars", "mouse", "command",
];
impl Visitor for FieldVisitor {
@@ -547,6 +559,7 @@ impl de::Deserialize for RawBinding {
"action" => Ok(Field::Action),
"chars" => Ok(Field::Chars),
"mouse" => Ok(Field::Mouse),
+ "command" => Ok(Field::Command),
_ => Err(E::unknown_field(value, FIELDS)),
}
}
@@ -577,6 +590,7 @@ impl de::Deserialize for RawBinding {
let mut mode: Option<TermMode> = None;
let mut not_mode: Option<TermMode> = None;
let mut mouse: Option<::glutin::MouseButton> = None;
+ let mut command: Option<CommandWrapper> = None;
use ::serde::de::Error;
@@ -626,17 +640,32 @@ impl de::Deserialize for RawBinding {
}
mouse = Some(visitor.visit_value::<MouseButton>()?.into_inner());
- }
+ },
+ Field::Command => {
+ if command.is_some() {
+ return Err(<V::Error as Error>::duplicate_field("command"));
+ }
+
+ command = Some(visitor.visit_value::<CommandWrapper>()?);
+ },
}
}
- let action = match (action, chars) {
- (Some(_), Some(_)) => {
- return Err(V::Error::custom("must specify only chars or action"));
+ let action = match (action, chars, command) {
+ (Some(action), None, None) => action,
+ (None, Some(chars), None) => Action::Esc(chars),
+ (None, None, Some(cmd)) => {
+ match cmd {
+ CommandWrapper::Just(program) => {
+ Action::Command(program, vec![])
+ },
+ CommandWrapper::WithArgs { program, args } => {
+ Action::Command(program, args)
+ },
+ }
},
- (Some(action), _) => action,
- (_, Some(chars)) => Action::Esc(chars),
- _ => return Err(V::Error::custom("must specify chars or action"))
+ (None, None, None) => return Err(V::Error::custom("must specify chars, action or command")),
+ _ => return Err(V::Error::custom("must specify only chars, action or command")),
};
let mode = mode.unwrap_or_else(TermMode::empty);
@@ -659,7 +688,7 @@ impl de::Deserialize for RawBinding {
}
const FIELDS: &'static [&'static str] = &[
- "key", "mods", "mode", "action", "chars", "mouse"
+ "key", "mods", "mode", "action", "chars", "mouse", "command",
];
deserializer.deserialize_struct("RawBinding", FIELDS, RawBindingVisitor)