meli/ui/src/execute.rs

101 lines
2.5 KiB
Rust
Raw Normal View History

2018-08-07 15:01:15 +03:00
/*
* meli - ui crate.
*
* Copyright 2017-2018 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
2018-07-18 10:42:52 +03:00
/*! A parser module for user commands passed through the Ex mode.
*/
pub use melib::mailbox::{SortField, SortOrder};
use nom::{digit, not_line_ending};
use std;
pub mod actions;
2019-06-18 21:13:58 +03:00
pub use crate::actions::Action::{self, *};
pub use crate::actions::ListingAction::{self, *};
pub use crate::actions::TabAction::{self, *};
2018-07-27 21:37:56 +03:00
named!(
usize_c<usize>,
map_res!(
map_res!(ws!(digit), std::str::from_utf8),
std::str::FromStr::from_str
)
);
2018-08-07 15:01:15 +03:00
named!(
sortfield<SortField>,
map_res!(
map_res!(take_until_s!(" "), std::str::from_utf8),
std::str::FromStr::from_str
)
);
2018-08-07 15:01:15 +03:00
named!(
sortorder<SortOrder>,
map_res!(
map_res!(call!(not_line_ending), std::str::from_utf8),
std::str::FromStr::from_str
)
);
named!(close<Action>, map!(ws!(tag!("close")), |_| Tab(Close)));
2018-08-07 15:01:15 +03:00
named!(
goto<Action>,
2019-05-07 21:54:14 +03:00
preceded!(tag!("go "), map!(call!(usize_c), Action::ViewMailbox))
2018-08-07 15:01:15 +03:00
);
2018-08-07 15:01:15 +03:00
named!(
subsort<Action>,
do_parse!(tag!("subsort ") >> p: pair!(sortfield, sortorder) >> (SubSort(p.0, p.1)))
2018-08-07 15:01:15 +03:00
);
named!(
sort<Action>,
do_parse!(
tag!("sort ") >> p: separated_pair!(sortfield, tag!(" "), sortorder) >> (Sort(p.0, p.1))
2018-08-07 15:01:15 +03:00
)
);
2018-08-07 15:01:15 +03:00
named!(
threaded<Action>,
map!(ws!(tag!("threaded")), |_| Listing(SetThreaded))
2018-08-07 15:01:15 +03:00
);
named!(
plain<Action>,
map!(ws!(tag!("plain")), |_| Listing(SetPlain))
);
named!(
compact<Action>,
map!(ws!(tag!("compact")), |_| Listing(SetCompact))
);
2018-08-07 15:01:15 +03:00
named!(
toggle<Action>,
preceded!(tag!("set "), alt_complete!(threaded | plain | compact))
2018-08-07 15:01:15 +03:00
);
2018-07-21 11:20:13 +03:00
named!(
toggle_thread_snooze<Action>,
map!(ws!(tag!("toggle_thread_snooze")), |_| ToggleThreadSnooze)
);
named!(pub parse_command<Action>,
alt_complete!( goto | toggle | sort | subsort | close | toggle_thread_snooze)
);