4fc6fee734e1b88c9aab94e66f5a2f908a86452f — Drew DeVault 12 days ago f0a0c5a
Revert "add close command at global level"

This reverts commit f0a0c5aa733fa66958c113465bfc5fdd3d7cc9f0.
6 files changed, 100 insertions(+), 72 deletions(-)

D commands/close.go
A commands/compose/abort.go
A commands/msgview/close.go
A commands/terminal/close.go
M doc/aerc.1.scd
M widgets/aerc.go
D commands/close.go => commands/close.go +0 -59
@@ 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")
- 	}
- }

A commands/compose/abort.go => commands/compose/abort.go +33 -0
@@ 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
+ }

A commands/msgview/close.go => commands/msgview/close.go +30 -0
@@ 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
+ }

A commands/terminal/close.go => commands/terminal/close.go +30 -0
@@ 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
+ }

M doc/aerc.1.scd => doc/aerc.1.scd +7 -5
@@ 41,10 41,6 @@ it's treated as an index. If + or - is specified, the number is interpreted
  	as a delta from the selected tab.
  
- *close* [tab name]
- 	Closes current tab if no tab name provided, or tab with tab name if
- 	argument is provided. Cannot close account tabs.
- 
  *exec* <command...>
  	Executes an arbitrary command in the background.
  


@@ 188,6 184,9 @@   ## MESSAGE VIEW COMMANDS
  
+ *close*
+ 	Closes the message viewer.
+ 
  *next* <n>[%], *prev* <n>[%]
  	Selects the next (or previous) message in the message list. If specified as
  	a percentage, the percentage is applied to the number of messages shown on


@@ 212,7 211,7 @@ ## MESSAGE COMPOSE COMMANDS
  
  *abort*
-     Close the composor without sending, discarding the message in progress.
+ 	Close the composor without sending, discarding the message in progress.
  
  *attach* <path>
  	Attaches the file at the given path to the email.


@@ 247,6 246,9 @@   ## TERMINAL COMMANDS
  
+ *close*
+ 	Closes the terminal.
+ 
  # LOGGING
  
  Aerc does not log by default, but collecting log output can be useful for

M widgets/aerc.go => widgets/aerc.go +0 -8
@@ 244,14 244,6 @@ return aerc.tabs.Tabs[aerc.tabs.Selected].Content
  }
  
- func (aerc *Aerc) SelectedTabName() string {
- 	return aerc.tabs.Tabs[aerc.tabs.Selected].Name
- }
- 
- 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)