Start building out command subsystem
This commit is contained in:
parent
62862d8a9e
commit
b60999c39e
7 changed files with 119 additions and 8 deletions
28
commands/commands.go
Normal file
28
commands/commands.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
type AercCommand func(aerc *widgets.Aerc, cmd string) error
|
||||
|
||||
var (
|
||||
commands map[string]AercCommand
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands = make(map[string]AercCommand)
|
||||
}
|
||||
|
||||
func Register(name string, cmd AercCommand) {
|
||||
commands[name] = cmd
|
||||
}
|
||||
|
||||
func ExecuteCommand(aerc *widgets.Aerc, cmd string) error {
|
||||
if fn, ok := commands[cmd]; ok {
|
||||
return fn(aerc, cmd)
|
||||
}
|
||||
return errors.New("Unknown command " + cmd)
|
||||
}
|
15
commands/next-folder.go
Normal file
15
commands/next-folder.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("next-folder", NextFolder)
|
||||
}
|
||||
|
||||
func NextFolder(aerc *widgets.Aerc, cmd string) error {
|
||||
acct := aerc.SelectedAccount()
|
||||
acct.Directories().Next()
|
||||
return nil
|
||||
}
|
15
commands/prev-folder.go
Normal file
15
commands/prev-folder.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("prev-folder", PrevFolder)
|
||||
}
|
||||
|
||||
func PrevFolder(aerc *widgets.Aerc, cmd string) error {
|
||||
acct := aerc.SelectedAccount()
|
||||
acct.Directories().Prev()
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue