From f406bf5a3bb953426a00f2feac1f2863a29ab269 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 15 Mar 2019 20:32:09 -0400 Subject: [PATCH] Add :quit command --- aerc.go | 14 +++++++++++--- commands/quit.go | 24 ++++++++++++++++++++++++ lib/ui/ui.go | 5 ----- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 commands/quit.go diff --git a/aerc.go b/aerc.go index 1e2f884..0da80e9 100644 --- a/aerc.go +++ b/aerc.go @@ -33,12 +33,20 @@ func main() { panic(err) } - var aerc *widgets.Aerc + var ( + aerc *widgets.Aerc + ui *libui.UI + ) aerc = widgets.NewAerc(conf, logger, func(cmd string) error { - return commands.ExecuteCommand(aerc, cmd) + err = commands.ExecuteCommand(aerc, cmd) + if _, ok := err.(commands.ErrorExit); ok { + ui.Exit = true + return nil + } + return err }) - ui, err := libui.Initialize(conf, aerc) + ui, err = libui.Initialize(conf, aerc) if err != nil { panic(err) } diff --git a/commands/quit.go b/commands/quit.go new file mode 100644 index 0000000..3435859 --- /dev/null +++ b/commands/quit.go @@ -0,0 +1,24 @@ +package commands + +import ( + "errors" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + Register("quit", ChangeQuit) +} + +type ErrorExit int + +func (err ErrorExit) Error() string { + return "exit" +} + +func ChangeQuit(aerc *widgets.Aerc, args []string) error { + if len(args) != 1 { + return errors.New("Usage: quit") + } + return ErrorExit(1) +} diff --git a/lib/ui/ui.go b/lib/ui/ui.go index 8fabf59..eb86e70 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -65,11 +65,6 @@ func (state *UI) Tick() bool { select { case event := <-state.tcEvents: switch event := event.(type) { - case *tcell.EventKey: - // TODO: temporary - if event.Key() == tcell.KeyEsc { - state.Exit = true - } case *tcell.EventResize: state.screen.Clear() width, height := event.Size()