Add :quit command

This commit is contained in:
Drew DeVault 2019-03-15 20:32:09 -04:00
parent 22f453f56a
commit f406bf5a3b
3 changed files with 35 additions and 8 deletions

14
aerc.go
View File

@ -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)
}

24
commands/quit.go Normal file
View File

@ -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)
}

View File

@ -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()