summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-26 18:56:29 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-26 18:56:29 +0300
commit34054d46ea7a3d5543e3cceeb7b77d175e7ebbcc (patch)
treede25a0d985a9aefc1e1ed68f11cd8dc7e5533cc4
parent8fefdf80ad40c17bd2eaf07b433c58d4fbc836ef (diff)
ui: print and set environment variables
-rw-r--r--ui/src/execute.rs22
-rw-r--r--ui/src/execute/actions.rs2
-rw-r--r--ui/src/state.rs17
3 files changed, 39 insertions, 2 deletions
diff --git a/ui/src/execute.rs b/ui/src/execute.rs
index c48b2739..e19b5051 100644
--- a/ui/src/execute.rs
+++ b/ui/src/execute.rs
@@ -135,6 +135,26 @@ named!(
)
);
+named!(
+ setenv<Action>,
+ do_parse!(
+ ws!(tag!("setenv"))
+ >> key: map_res!(take_until1!("="), std::str::from_utf8)
+ >> ws!(tag!("="))
+ >> val: map_res!(call!(not_line_ending), std::str::from_utf8)
+ >> (SetEnv(key.to_string(), val.to_string()))
+ )
+);
+
+named!(
+ printenv<Action>,
+ do_parse!(
+ ws!(tag!("env"))
+ >> key: map_res!(call!(not_line_ending), std::str::from_utf8)
+ >> (PrintEnv(key.to_string()))
+ )
+);
+
named!(pub parse_command<Action>,
- alt_complete!( goto | listing_action | sort | subsort | close | mailinglist)
+ alt_complete!( goto | listing_action | sort | subsort | close | mailinglist | setenv | printenv)
);
diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs
index 5b17a947..0b13bdf7 100644
--- a/ui/src/execute/actions.rs
+++ b/ui/src/execute/actions.rs
@@ -68,4 +68,6 @@ pub enum Action {
Tab(TabAction),
ToggleThreadSnooze,
MailingListAction(MailingListAction),
+ SetEnv(String, String),
+ PrintEnv(String),
}
diff --git a/ui/src/state.rs b/ui/src/state.rs
index 96495f14..36efc1fe 100644
--- a/ui/src/state.rs
+++ b/ui/src/state.rs
@@ -33,6 +33,7 @@ use melib::backends::{FolderHash, NotifyFn};
use chan::{Receiver, Sender};
use fnv::FnvHashMap;
+use std::env;
use std::io::Write;
use std::result;
use std::thread;
@@ -471,7 +472,21 @@ impl State {
let result = parse_command(&cmd.as_bytes()).to_full_result();
if let Ok(v) = result {
- self.rcv_event(UIEvent::Action(v));
+ match v {
+ SetEnv(key, val) => {
+ env::set_var(key.as_str(), val.as_str());
+ }
+ PrintEnv(key) => {
+ self.context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(
+ env::var(key.as_str()).unwrap_or_else(|e| e.to_string()),
+ ),
+ ));
+ }
+ v => {
+ self.rcv_event(UIEvent::Action(v));
+ }
+ }
}
}