ui: print and set environment variables
parent
8fefdf80ad
commit
34054d46ea
|
@ -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>,
|
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)
|
||||||
);
|
);
|
||||||
|
|
|
@ -68,4 +68,6 @@ pub enum Action {
|
||||||
Tab(TabAction),
|
Tab(TabAction),
|
||||||
ToggleThreadSnooze,
|
ToggleThreadSnooze,
|
||||||
MailingListAction(MailingListAction),
|
MailingListAction(MailingListAction),
|
||||||
|
SetEnv(String, String),
|
||||||
|
PrintEnv(String),
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ use melib::backends::{FolderHash, NotifyFn};
|
||||||
|
|
||||||
use chan::{Receiver, Sender};
|
use chan::{Receiver, Sender};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
|
use std::env;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
@ -471,7 +472,21 @@ impl State {
|
||||||
let result = parse_command(&cmd.as_bytes()).to_full_result();
|
let result = parse_command(&cmd.as_bytes()).to_full_result();
|
||||||
|
|
||||||
if let Ok(v) = 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…
Reference in New Issue