diff options
Diffstat (limited to 'ui/src/execute.rs')
-rw-r--r-- | ui/src/execute.rs | 221 |
1 files changed, 136 insertions, 85 deletions
diff --git a/ui/src/execute.rs b/ui/src/execute.rs index e19b5051..7008064a 100644 --- a/ui/src/execute.rs +++ b/ui/src/execute.rs @@ -30,6 +30,140 @@ pub use crate::actions::ListingAction::{self, *}; pub use crate::actions::MailingListAction::{self, *}; pub use crate::actions::TabAction::{self, *}; +/* Create a const table with every command part that can be auto-completed and its description */ +macro_rules! define_commands { + ( [$({ tags: [$( $tags:literal),*], desc: $desc:literal, parser: ($parser:item)}),*]) => { + pub const COMMAND_COMPLETION: &[(&str, &str)] = &[$($( ($tags, $desc ) ),*),* ]; + $( $parser )* + }; +} + +define_commands!([ + { tags: ["set"], + desc: "set [seen/unseen], toggles message's Seen flag.", + parser: + ( named!( + envelope_action<Action>, + alt_complete!( + preceded!( + ws!(tag!("set")), + alt_complete!( + map!(ws!(tag!("read")), |_| Listing(SetRead)) + | map!(ws!(tag!("unread")), |_| Listing(SetUnread)) + ) + ) | map!(ws!(tag!("delete")), |_| Listing(Delete)) + ) + ); ) + }, + { tags: ["close"], + desc: "close non-sticky tabs", + parser: ( + named!(close<Action>, map!(ws!(tag!("close")), |_| Tab(Close))); + ) + }, + { tags: ["goto"], + desc: "goto [n], switch to nth mailbox in this account", + parser: ( + named!( + goto<Action>, + preceded!(tag!("go "), map!(call!(usize_c), Action::ViewMailbox)) + ); + ) + }, + { tags: ["subsort"], + desc: "subsort [date/subject] [asc/desc], sorts first level replies in threads.", + parser: ( + named!( + subsort<Action>, + do_parse!(tag!("subsort ") >> p: pair!(sortfield, sortorder) >> (SubSort(p.0, p.1))) + ); + ) + }, + { tags: ["sort"], + desc: "sort [date/subject] [asc/desc], sorts threads.", + parser: ( + named!( + sort<Action>, + do_parse!( + tag!("sort ") >> p: separated_pair!(sortfield, tag!(" "), sortorder) >> (Sort(p.0, p.1)) + ) + ); + ) + }, + { tags: ["set", "set plain", "set threaded", "set compact"], + desc: "set [plain/threaded/compact], changes the mail listing view", + parser: ( + named!( + toggle<Action>, + preceded!(tag!("set "), alt_complete!(threaded | plain | compact)) + ); + ) + }, + { tags: ["toggle_thread_snooze"], + desc: "turn off new notifications for this thread", + parser: ( + named!(toggle_thread_snooze<Action>, + map!(ws!(tag!("toggle_thread_snooze")), |_| ToggleThreadSnooze) + ); + ) + }, + { tags: ["filter"], + desc: "filter <TERM>, filters list with given term", + parser:( + named!(filter<Action>, + do_parse!( + ws!(tag!("filter")) + >> string: map_res!(call!(not_line_ending), std::str::from_utf8) + >> (Listing(Filter(String::from(string)))) + ) + ); + ) + }, + { tags: ["list-archive", "list-post", "list-unsubscribe", "list-"], + desc: "list-[unsubscribe/post/archive]", + parser: ( + named!( + mailinglist<Action>, + alt_complete!( + map!(ws!(tag!("list-post")), |_| MailingListAction(ListPost)) + | map!(ws!(tag!("list-unsubscribe")), |_| MailingListAction( + ListUnsubscribe + )) + | map!(ws!(tag!("list-archive")), |_| MailingListAction( + ListArchive + )) + ) + ); + ) + }, + { tags: ["setenv "], + desc:"setenv VAR=VALUE", + parser: ( + 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())) + ) + ); + ) + }, + { tags: ["printenv "], + desc: "printenv VAR", + parser:( + named!( printenv<Action>, + do_parse!( + ws!(tag!("env")) + >> key: map_res!(call!(not_line_ending), std::str::from_utf8) + >> (PrintEnv(key.to_string())) + ) + ); + ) + } +]); + named!( usize_c<usize>, map_res!( @@ -54,23 +188,6 @@ named!( ) ); -named!(close<Action>, map!(ws!(tag!("close")), |_| Tab(Close))); -named!( - goto<Action>, - preceded!(tag!("go "), map!(call!(usize_c), Action::ViewMailbox)) -); - -named!( - subsort<Action>, - do_parse!(tag!("subsort ") >> p: pair!(sortfield, sortorder) >> (SubSort(p.0, p.1))) -); -named!( - sort<Action>, - do_parse!( - tag!("sort ") >> p: separated_pair!(sortfield, tag!(" "), sortorder) >> (Sort(p.0, p.1)) - ) -); - named!( threaded<Action>, map!(ws!(tag!("threaded")), |_| Listing(SetThreaded)) @@ -85,76 +202,10 @@ named!( compact<Action>, map!(ws!(tag!("compact")), |_| Listing(SetCompact)) ); - -named!( - toggle<Action>, - preceded!(tag!("set "), alt_complete!(threaded | plain | compact)) -); named!( listing_action<Action>, alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze) ); - -named!( - toggle_thread_snooze<Action>, - map!(ws!(tag!("toggle_thread_snooze")), |_| ToggleThreadSnooze) -); - -named!( - filter<Action>, - do_parse!( - ws!(tag!("filter")) - >> string: map_res!(call!(not_line_ending), std::str::from_utf8) - >> (Listing(Filter(String::from(string)))) - ) -); - -named!( - mailinglist<Action>, - alt_complete!( - map!(ws!(tag!("list-post")), |_| MailingListAction(ListPost)) - | map!(ws!(tag!("list-unsubscribe")), |_| MailingListAction( - ListUnsubscribe - )) - | map!(ws!(tag!("list-archive")), |_| MailingListAction( - ListArchive - )) - ) -); - -named!( - envelope_action<Action>, - alt_complete!( - preceded!( - ws!(tag!("set")), - alt_complete!( - map!(ws!(tag!("read")), |_| Listing(SetRead)) - | map!(ws!(tag!("unread")), |_| Listing(SetUnread)) - ) - ) | map!(ws!(tag!("delete")), |_| Listing(Delete)) - ) -); - -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 | setenv | printenv) - ); + alt_complete!( goto | listing_action | sort | subsort | close | mailinglist | setenv | printenv) +); |