From 5d0402aeea1dcc69adb46227ab1cd73b5e768880 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 30 Mar 2019 21:45:41 -0400 Subject: Add message view commands, :close --- commands/msgview/close.go | 21 +++++++++++++++++++++ commands/msgview/msgview.go | 16 ++++++++++++++++ commands/terminal/close.go | 5 +---- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 commands/msgview/close.go create mode 100644 commands/msgview/msgview.go (limited to 'commands') diff --git a/commands/msgview/close.go b/commands/msgview/close.go new file mode 100644 index 0000000..404bb1c --- /dev/null +++ b/commands/msgview/close.go @@ -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 +} + diff --git a/commands/msgview/msgview.go b/commands/msgview/msgview.go new file mode 100644 index 0000000..e3db828 --- /dev/null +++ b/commands/msgview/msgview.go @@ -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) +} diff --git a/commands/terminal/close.go b/commands/terminal/close.go index 0a9d100..aee7f3e 100644 --- a/commands/terminal/close.go +++ b/commands/terminal/close.go @@ -14,10 +14,7 @@ func CommandClose(aerc *widgets.Aerc, args []string) error { if len(args) != 1 { return errors.New("Usage: close") } - term, ok := aerc.SelectedTab().(*widgets.Terminal) - if !ok { - return errors.New("Error: not a terminal") - } + term, _ := aerc.SelectedTab().(*widgets.Terminal) term.Close(nil) aerc.RemoveTab(term) return nil -- cgit 1.4.1-2-gfad0