From 67f50d95f4492efe842a6039615fb122129e1d53 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 14 Oct 2020 20:14:07 +0300 Subject: [PATCH] Add quit command --- src/command.rs | 12 ++++++++++++ src/command/actions.rs | 2 ++ src/state.rs | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/command.rs b/src/command.rs index c20631b9..ac08a898 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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 { account_action, print_setting, toggle_mouse, + quit, ))(input) .map(|(_, v)| v) .map_err(|err| err.into()) diff --git a/src/command/actions.rs b/src/command/actions.rs index 9faad818..110a637c 100644 --- a/src/command/actions.rs +++ b/src/command/actions.rs @@ -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, } } } diff --git a/src/state.rs b/src/state.rs index 1c193dfe..4eac6404 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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)); }