~sircmpwn/aerc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] add close-tab command

Details
Message ID
<20190808051238.13836-1-adityasri@ocf.berkeley.edu>
DKIM signature
missing
Download raw message
Patch: +54 -0
This adds the close-tab command per https://todo.sr.ht/~sircmpwn/aerc2/242

---
 commands/closetab.go | 47 ++++++++++++++++++++++++++++++++++++++++++++
 doc/aerc.1.scd       |  3 +++
 widgets/aerc.go      |  4 ++++
 3 files changed, 54 insertions(+)
 create mode 100644 commands/closetab.go

diff --git a/commands/closetab.go b/commands/closetab.go
new file mode 100644
index 0000000..89b6262
--- /dev/null
+++ b/commands/closetab.go
@@ -0,0 +1,47 @@
package commands

import (
	"errors"
	"fmt"

	"git.sr.ht/~sircmpwn/aerc/widgets"
)

type CloseTab struct{}

func init() {
	register(CloseTab{})
}

func (_ CloseTab) Aliases() []string {
	return []string{"close-tab"}
}

func (_ CloseTab) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func (_ CloseTab) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) != 2 {
		return errors.New("Usage: close-tab <tab name>")
	} else {
		tabname := args[1]
		for _, tab := range aerc.TabNames() {
			if tab == tabname {
				curTabIndex := aerc.SelectedTabIndex()
				aerc.SelectTab(tabname)
				switch tab := aerc.SelectedTab().(type) {
				default:
					aerc.RemoveTab(tab)
					return nil
				case *widgets.AccountView:
					aerc.SelectTabIndex(curTabIndex)
					return errors.New("Cannot close account tab")
				}
			}
		}
		return errors.New(fmt.Sprintf("Tab %s not found", tabname))
	}
	return nil
}

diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 10e6485..3b04010 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -41,6 +41,9 @@ These commands work in any context.
	it's treated as an index. If + or - is specified, the number is interpreted
	as a delta from the selected tab.

*close-tab* <tab name>
    Closes tab with the given name. Cannot close account tabs.

*exec* <command...>
	Executes an arbitrary command in the background.

diff --git a/widgets/aerc.go b/widgets/aerc.go
index 5a7914a..ab96e19 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -244,6 +244,10 @@ func (aerc *Aerc) SelectedTab() ui.Drawable {
	return aerc.tabs.Tabs[aerc.tabs.Selected].Content
}

func (aerc *Aerc) SelectedTabIndex() int {
	return aerc.tabs.Selected
}

func (aerc *Aerc) NewTab(drawable ui.Drawable, name string) *ui.Tab {
	tab := aerc.tabs.Add(drawable, name)
	aerc.tabs.Select(len(aerc.tabs.Tabs) - 1)
-- 
2.22.0
Details
Message ID
<BW4BXZ3DUE8G.2FFGOG0Z8X12@jupiter.local>
In-Reply-To
<20190808051238.13836-1-adityasri@ocf.berkeley.edu> (view parent)
DKIM signature
missing
Download raw message
We already have :close and :abort, could we simply make the existing

Perhaps somewhat selfishly, I don't really want to remember that :close
works for the message viewer and the terminal, abort for the composer,
and if I want to close one by name I should use :close-tab.

I think it would be possible to just have a single :close command which
uses a type switch to do the additional cleanup required by the term and
the composer, and it could also be extended to take an optional tab
name, acting on the focused tab if none is provided.

Thoughts?