Make parser for ex commands and move actions to their own mod
parent
375b256a4e
commit
e4760e4d25
|
@ -1,10 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
const MAX_COLS: usize = 500;
|
const MAX_COLS: usize = 500;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum MailListingAction {
|
|
||||||
ToggleThreaded,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
|
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
|
||||||
/// `Pager`.
|
/// `Pager`.
|
||||||
|
@ -582,7 +578,16 @@ impl Component for MailListing {
|
||||||
.threaded;
|
.threaded;
|
||||||
self.refresh_mailbox(context);
|
self.refresh_mailbox(context);
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
Action::ViewMailbox(idx) => {
|
||||||
|
eprintln!("listing got viewmailbox({})", idx);
|
||||||
|
self.new_cursor_pos.1 = *idx;
|
||||||
|
self.dirty = true;
|
||||||
|
self.refresh_mailbox(context);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
_ => {},
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,7 +428,7 @@ impl Component for StatusBar {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
UIEventType::ChangeMode(m) => {
|
UIEventType::ChangeMode(m) => {
|
||||||
let offset = self.status.find('|').unwrap_or(self.status.len());
|
let offset = self.status.find('|').unwrap_or_else(|| self.status.len());
|
||||||
self.status.replace_range(..offset, &format!("{} ", m));
|
self.status.replace_range(..offset, &format!("{} ", m));
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.mode = m.clone();
|
self.mode = m.clone();
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MailListingAction {
|
||||||
|
ToggleThreaded,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Action {
|
||||||
|
MailListing(MailListingAction),
|
||||||
|
ViewMailbox(usize),
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
/*! A parser module for user commands passed through the Ex mode.
|
/*! A parser module for user commands passed through the Ex mode.
|
||||||
*/
|
*/
|
||||||
use nom::digit;
|
use nom::{digit, };
|
||||||
use std;
|
use std;
|
||||||
|
pub mod actions;
|
||||||
|
pub use actions::*;
|
||||||
|
|
||||||
|
|
||||||
named!(
|
named!(
|
||||||
usize_c<usize>,
|
usize_c<usize>,
|
||||||
|
@ -11,14 +14,22 @@ named!(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
named!(pub goto<usize>,
|
named!(goto<Action>,
|
||||||
preceded!(tag!("b "),
|
preceded!(tag!("b "),
|
||||||
call!(usize_c))
|
map!(call!(usize_c), |v| Action::ViewMailbox(v))
|
||||||
);
|
));
|
||||||
|
|
||||||
/*
|
//named!(sort<&str>,
|
||||||
named!(pub sort<&str>,
|
// preceded!(tag!("sort "),
|
||||||
preceded!(tag!("sort "),
|
// map_res!(call!(alpha), std::str::from_utf8))
|
||||||
map_res!(call!(alpha), std::str::from_utf8))
|
// );
|
||||||
);
|
|
||||||
*/
|
named!(threaded<Action>,
|
||||||
|
map!(ws!(tag!("threaded")), |_| Action::MailListing(MailListingAction::ToggleThreaded)));
|
||||||
|
named!(toggle<Action>,
|
||||||
|
preceded!(tag!("toggle "),
|
||||||
|
alt_complete!( threaded )));
|
||||||
|
|
||||||
|
named!(pub parse_command<Action>,
|
||||||
|
alt_complete!( goto | toggle)
|
||||||
|
);
|
||||||
|
|
|
@ -9,6 +9,12 @@ pub struct File {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for File {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
std::fs::remove_file(self.path()).unwrap_or_else(|_| {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
pub fn file(&mut self) -> std::fs::File {
|
pub fn file(&mut self) -> std::fs::File {
|
||||||
std::fs::File::create(&self.path).unwrap()
|
std::fs::File::create(&self.path).unwrap()
|
||||||
|
@ -18,7 +24,6 @@ impl File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add temp files to a list to reap them when dropped
|
|
||||||
pub fn create_temp_file(bytes: &[u8], filename: Option<&PathBuf>) -> File {
|
pub fn create_temp_file(bytes: &[u8], filename: Option<&PathBuf>) -> File {
|
||||||
let mut dir = std::env::temp_dir();
|
let mut dir = std::env::temp_dir();
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,10 @@ pub use helpers::*;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod execute;
|
mod execute;
|
||||||
|
use execute::*;
|
||||||
use self::cells::*;
|
use self::cells::*;
|
||||||
pub use self::components::*;
|
pub use self::components::*;
|
||||||
pub use self::position::*;
|
pub use self::position::*;
|
||||||
use execute::goto;
|
|
||||||
|
|
||||||
extern crate melib;
|
extern crate melib;
|
||||||
extern crate mime_apps;
|
extern crate mime_apps;
|
||||||
|
@ -66,10 +66,6 @@ use termion::{clear, cursor, style};
|
||||||
extern crate nom;
|
extern crate nom;
|
||||||
use chan::Sender;
|
use chan::Sender;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Action {
|
|
||||||
MailListing(MailListingAction),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads
|
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads
|
||||||
/// to the main process.
|
/// to the main process.
|
||||||
|
@ -390,10 +386,13 @@ impl<W: Write> State<W> {
|
||||||
fn parse_command(&mut self, cmd: String) {
|
fn parse_command(&mut self, cmd: String) {
|
||||||
//TODO: Make ex mode useful
|
//TODO: Make ex mode useful
|
||||||
|
|
||||||
let result = goto(&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.refresh_mailbox(0, v);
|
eprintln!("result is {:?}", v);
|
||||||
|
self.rcv_event(UIEvent { id: 0, event_type: UIEventType::Action(v) });
|
||||||
|
;
|
||||||
|
//self.refresh_mailbox(0, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,6 +449,12 @@ impl<W: Write> State<W> {
|
||||||
for i in 0..self.entities.len() {
|
for i in 0..self.entities.len() {
|
||||||
self.entities[i].rcv_event(&event, &mut self.context);
|
self.entities[i].rcv_event(&event, &mut self.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.context.replies.is_empty() {
|
||||||
|
let replies: Vec<UIEvent>= self.context.replies.drain(0..).collect();
|
||||||
|
// Pass replies to self and call count on the map iterator to force evaluation
|
||||||
|
replies.into_iter().map(|r| self.rcv_event(r)).count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to load a mailbox's content
|
/// Tries to load a mailbox's content
|
||||||
|
|
Loading…
Reference in New Issue