about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--aerc.go14
-rw-r--r--commands/quit.go24
-rw-r--r--lib/ui/ui.go5
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()