Add message view commands, :close

This commit is contained in:
Drew DeVault 2019-03-30 21:45:41 -04:00
parent 04d9ab3ce6
commit 5d0402aeea
6 changed files with 47 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"git.sr.ht/~sircmpwn/aerc2/config" "git.sr.ht/~sircmpwn/aerc2/config"
"git.sr.ht/~sircmpwn/aerc2/commands" "git.sr.ht/~sircmpwn/aerc2/commands"
"git.sr.ht/~sircmpwn/aerc2/commands/account" "git.sr.ht/~sircmpwn/aerc2/commands/account"
"git.sr.ht/~sircmpwn/aerc2/commands/msgview"
"git.sr.ht/~sircmpwn/aerc2/commands/terminal" "git.sr.ht/~sircmpwn/aerc2/commands/terminal"
libui "git.sr.ht/~sircmpwn/aerc2/lib/ui" libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
"git.sr.ht/~sircmpwn/aerc2/widgets" "git.sr.ht/~sircmpwn/aerc2/widgets"
@ -24,6 +25,11 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
account.AccountCommands, account.AccountCommands,
commands.GlobalCommands, commands.GlobalCommands,
} }
case *widgets.MessageViewer:
return []*commands.Commands{
msgview.MessageViewCommands,
commands.GlobalCommands,
}
case *widgets.Terminal: case *widgets.Terminal:
return []*commands.Commands{ return []*commands.Commands{
terminal.TerminalCommands, terminal.TerminalCommands,

21
commands/msgview/close.go Normal file
View File

@ -0,0 +1,21 @@
package msgview
import (
"errors"
"git.sr.ht/~sircmpwn/aerc2/widgets"
)
func init() {
register("close", CommandClose)
}
func CommandClose(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 {
return errors.New("Usage: close")
}
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer)
aerc.RemoveTab(mv)
return nil
}

View File

@ -0,0 +1,16 @@
package msgview
import (
"git.sr.ht/~sircmpwn/aerc2/commands"
)
var (
MessageViewCommands *commands.Commands
)
func register(name string, cmd commands.AercCommand) {
if MessageViewCommands == nil {
MessageViewCommands = commands.NewCommands()
}
MessageViewCommands.Register(name, cmd)
}

View File

@ -14,10 +14,7 @@ func CommandClose(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: close") return errors.New("Usage: close")
} }
term, ok := aerc.SelectedTab().(*widgets.Terminal) term, _ := aerc.SelectedTab().(*widgets.Terminal)
if !ok {
return errors.New("Error: not a terminal")
}
term.Close(nil) term.Close(nil)
aerc.RemoveTab(term) aerc.RemoveTab(term)
return nil return nil

View File

@ -32,7 +32,7 @@ c = :cf<space>
$ = :term<space> $ = :term<space>
| = :pipe<space> | = :pipe<space>
[msgview] [view]
q = :close<Enter> q = :close<Enter>
| = :pipe<space> | = :pipe<space>
r = :reply<Enter> r = :reply<Enter>

View File

@ -93,6 +93,8 @@ func (aerc *Aerc) getBindings() *config.KeyBindings {
switch aerc.SelectedTab().(type) { switch aerc.SelectedTab().(type) {
case *AccountView: case *AccountView:
return aerc.conf.Bindings.MessageList return aerc.conf.Bindings.MessageList
case *MessageViewer:
return aerc.conf.Bindings.MessageView
case *Terminal: case *Terminal:
return aerc.conf.Bindings.Terminal return aerc.conf.Bindings.Terminal
default: default: