diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-15 20:32:09 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-15 20:32:09 -0400 |
commit | f406bf5a3bb953426a00f2feac1f2863a29ab269 (patch) | |
tree | 70b1c238bae590b7f1814840ba303faa1532d8cb | |
parent | 22f453f56a18da91c987baa3a47fa91f666d8b7a (diff) | |
download | aerc-f406bf5a3bb953426a00f2feac1f2863a29ab269.tar.gz |
Add :quit command
-rw-r--r-- | aerc.go | 14 | ||||
-rw-r--r-- | commands/quit.go | 24 | ||||
-rw-r--r-- | lib/ui/ui.go | 5 |
3 files changed, 35 insertions, 8 deletions
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() |