summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-08-13 10:55:50 +0900
committerDrew DeVault <sir@cmpwn.com>2019-08-13 10:55:50 +0900
commit4fc6fee734e1b88c9aab94e66f5a2f908a86452f (patch)
tree76a2d79320ec2da88762d28ef66a391243206543 /commands
parentf0a0c5aa733fa66958c113465bfc5fdd3d7cc9f0 (diff)
downloadaerc-4fc6fee734e1b88c9aab94e66f5a2f908a86452f.tar.gz
Revert "add close command at global level"
This reverts commit f0a0c5aa733fa66958c113465bfc5fdd3d7cc9f0.
Diffstat (limited to 'commands')
-rw-r--r--commands/close.go59
-rw-r--r--commands/compose/abort.go33
-rw-r--r--commands/msgview/close.go30
-rw-r--r--commands/terminal/close.go30
4 files changed, 93 insertions, 59 deletions
diff --git a/commands/close.go b/commands/close.go
deleted file mode 100644
index c885ee9..0000000
--- a/commands/close.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package commands
-
-import (
-	"errors"
-	"fmt"
-
-	"git.sr.ht/~sircmpwn/aerc/widgets"
-)
-
-type Close struct{}
-
-func init() {
-	register(Close{})
-}
-
-func (_ Close) Aliases() []string {
-	return []string{"close", "abort"}
-}
-
-func (_ Close) Complete(aerc *widgets.Aerc, args []string) []string {
-	return nil
-}
-
-func (_ Close) Execute(aerc *widgets.Aerc, args []string) error {
-	if len(args) > 2 {
-		return errors.New("Usage: close [tab name]")
-	} else if len(args) == 1 {
-		return CloseTab(aerc, aerc.SelectedTabName())
-	} else {
-		tabname := args[1]
-		for _, tab := range aerc.TabNames() {
-			if tab == tabname {
-				return CloseTab(aerc, tabname)
-			}
-		}
-		return errors.New(fmt.Sprintf("Tab %s not found", tabname))
-	}
-	return nil
-}
-
-func CloseTab(aerc *widgets.Aerc, tabname string) error {
-	curTabIndex := aerc.SelectedTabIndex()
-	aerc.SelectTab(tabname)
-	switch tab := aerc.SelectedTab().(type) {
-	default:
-		aerc.RemoveTab(tab)
-		return nil
-	case *widgets.Terminal:
-		tab.Close(nil)
-		return nil
-	case *widgets.Composer:
-		aerc.RemoveTab(tab)
-		tab.Close()
-		return nil
-	case *widgets.AccountView:
-		aerc.SelectTabIndex(curTabIndex)
-		return errors.New("Cannot close account tab")
-	}
-}
diff --git a/commands/compose/abort.go b/commands/compose/abort.go
new file mode 100644
index 0000000..4c121d7
--- /dev/null
+++ b/commands/compose/abort.go
@@ -0,0 +1,33 @@
+package compose
+
+import (
+	"errors"
+
+	"git.sr.ht/~sircmpwn/aerc/widgets"
+)
+
+type Abort struct{}
+
+func init() {
+	register(Abort{})
+}
+
+func (_ Abort) Aliases() []string {
+	return []string{"abort"}
+}
+
+func (_ Abort) Complete(aerc *widgets.Aerc, args []string) []string {
+	return nil
+}
+
+func (_ Abort) Execute(aerc *widgets.Aerc, args []string) error {
+	if len(args) != 1 {
+		return errors.New("Usage: abort")
+	}
+	composer, _ := aerc.SelectedTab().(*widgets.Composer)
+
+	aerc.RemoveTab(composer)
+	composer.Close()
+
+	return nil
+}
diff --git a/commands/msgview/close.go b/commands/msgview/close.go
new file mode 100644
index 0000000..6a7eb0a
--- /dev/null
+++ b/commands/msgview/close.go
@@ -0,0 +1,30 @@
+package msgview
+
+import (
+	"errors"
+
+	"git.sr.ht/~sircmpwn/aerc/widgets"
+)
+
+type Close struct{}
+
+func init() {
+	register(Close{})
+}
+
+func (_ Close) Aliases() []string {
+	return []string{"close"}
+}
+
+func (_ Close) Complete(aerc *widgets.Aerc, args []string) []string {
+	return nil
+}
+
+func (_ Close) Execute(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/terminal/close.go b/commands/terminal/close.go
new file mode 100644
index 0000000..8256e67
--- /dev/null
+++ b/commands/terminal/close.go
@@ -0,0 +1,30 @@
+package terminal
+
+import (
+	"errors"
+
+	"git.sr.ht/~sircmpwn/aerc/widgets"
+)
+
+type Close struct{}
+
+func init() {
+	register(Close{})
+}
+
+func (_ Close) Aliases() []string {
+	return []string{"close"}
+}
+
+func (_ Close) Complete(aerc *widgets.Aerc, args []string) []string {
+	return nil
+}
+
+func (_ Close) Execute(aerc *widgets.Aerc, args []string) error {
+	if len(args) != 1 {
+		return errors.New("Usage: close")
+	}
+	term, _ := aerc.SelectedTab().(*widgets.Terminal)
+	term.Close(nil)
+	return nil
+}