Add quit command

jmap-eventsource
Manos Pitsidianakis 2020-10-14 20:14:07 +03:00
parent 0c68807814
commit 67f50d95f4
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 20 additions and 0 deletions

View File

@ -779,6 +779,17 @@ Alternatives(&[to_stream!(One(Literal("add-attachment")), One(Filepath)), to_str
Ok((input, ToggleMouse))
}
)
},
{ tags: ["quit"],
desc: "quit meli",
tokens: &[One(Literal("quit"))],
parser:(
fn quit(input: &[u8]) -> IResult<&[u8], Action> {
let (input, _) = tag("quit")(input.trim())?;
let (input, _) = eof(input.trim())?;
Ok((input, Quit))
}
)
}
]);
@ -872,6 +883,7 @@ pub fn parse_command(input: &[u8]) -> Result<Action, MeliError> {
account_action,
print_setting,
toggle_mouse,
quit,
))(input)
.map(|(_, v)| v)
.map_err(|err| err.into())

View File

@ -122,6 +122,7 @@ pub enum Action {
AccountAction(AccountName, AccountAction),
PrintSetting(String),
ToggleMouse,
Quit,
}
impl Action {
@ -141,6 +142,7 @@ impl Action {
Action::AccountAction(_, _) => false,
Action::PrintSetting(_) => false,
Action::ToggleMouse => false,
Action::Quit => true,
}
}
}

View File

@ -982,6 +982,12 @@ impl State {
self.set_mouse(self.mouse);
self.rcv_event(UIEvent::StatusEvent(StatusEvent::SetMouse(self.mouse)));
}
Quit => {
self.context
.sender
.send(ThreadEvent::Input((Key::Char('q'), vec![b'q'])))
.unwrap();
}
v => {
self.rcv_event(UIEvent::Action(v));
}