Browse Source

ui: print and set environment variables

tags/pre-alpha-0.0
Manos Pitsidianakis 2 years ago
parent
commit
34054d46ea
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 22
      ui/src/execute.rs
  2. 2
      ui/src/execute/actions.rs
  3. 17
      ui/src/state.rs

22
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)
);

2
ui/src/execute/actions.rs

@ -68,4 +68,6 @@ pub enum Action {
Tab(TabAction),
ToggleThreadSnooze,
MailingListAction(MailingListAction),
SetEnv(String, String),
PrintEnv(String),
}

17
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));
}
}
}
}

Loading…
Cancel
Save