aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/account-wizard.go36
-rw-r--r--app/account.go24
-rw-r--r--app/aerc.go16
-rw-r--r--app/app.go80
-rw-r--r--app/compose.go44
-rw-r--r--app/msglist.go22
-rw-r--r--app/msgviewer.go2
-rw-r--r--app/status.go11
-rw-r--r--commands/account/cf.go8
-rw-r--r--commands/account/check-mail.go6
-rw-r--r--commands/account/clear.go6
-rw-r--r--commands/account/compose.go10
-rw-r--r--commands/account/connection.go6
-rw-r--r--commands/account/expand-folder.go6
-rw-r--r--commands/account/export-mbox.go20
-rw-r--r--commands/account/import-mbox.go23
-rw-r--r--commands/account/mkdir.go14
-rw-r--r--commands/account/next-folder.go6
-rw-r--r--commands/account/next-result.go6
-rw-r--r--commands/account/next.go6
-rw-r--r--commands/account/recover.go14
-rw-r--r--commands/account/rmdir.go12
-rw-r--r--commands/account/search.go13
-rw-r--r--commands/account/select.go6
-rw-r--r--commands/account/sort.go8
-rw-r--r--commands/account/split.go12
-rw-r--r--commands/account/view.go14
-rw-r--r--commands/cd.go6
-rw-r--r--commands/choose.go6
-rw-r--r--commands/commands.go40
-rw-r--r--commands/completion_helpers.go6
-rw-r--r--commands/compose/abort.go8
-rw-r--r--commands/compose/attach-key.go6
-rw-r--r--commands/compose/attach.go38
-rw-r--r--commands/compose/cc-bcc.go6
-rw-r--r--commands/compose/detach.go10
-rw-r--r--commands/compose/edit.go6
-rw-r--r--commands/compose/encrypt.go6
-rw-r--r--commands/compose/header.go8
-rw-r--r--commands/compose/multipart.go8
-rw-r--r--commands/compose/next-field.go6
-rw-r--r--commands/compose/postpone.go24
-rw-r--r--commands/compose/send.go28
-rw-r--r--commands/compose/sign.go8
-rw-r--r--commands/compose/switch.go16
-rw-r--r--commands/ct.go18
-rw-r--r--commands/eml.go16
-rw-r--r--commands/exec.go12
-rw-r--r--commands/help.go16
-rw-r--r--commands/move-tab.go6
-rw-r--r--commands/msg/archive.go22
-rw-r--r--commands/msg/copy.go12
-rw-r--r--commands/msg/delete.go22
-rw-r--r--commands/msg/envelope.go12
-rw-r--r--commands/msg/fold.go7
-rw-r--r--commands/msg/forward.go14
-rw-r--r--commands/msg/invite.go16
-rw-r--r--commands/msg/mark.go7
-rw-r--r--commands/msg/modify-labels.go12
-rw-r--r--commands/msg/move.go27
-rw-r--r--commands/msg/pipe.go22
-rw-r--r--commands/msg/read.go14
-rw-r--r--commands/msg/recall.go22
-rw-r--r--commands/msg/reply.go26
-rw-r--r--commands/msg/toggle-thread-context.go7
-rw-r--r--commands/msg/toggle-threads.go7
-rw-r--r--commands/msg/unsubscribe.go44
-rw-r--r--commands/msg/utils.go8
-rw-r--r--commands/msgview/close.go8
-rw-r--r--commands/msgview/next-part.go6
-rw-r--r--commands/msgview/next.go12
-rw-r--r--commands/msgview/open-link.go10
-rw-r--r--commands/msgview/open.go12
-rw-r--r--commands/msgview/save.go15
-rw-r--r--commands/msgview/toggle-headers.go6
-rw-r--r--commands/msgview/toggle-key-passthrough.go6
-rw-r--r--commands/new-account.go8
-rw-r--r--commands/next-tab.go10
-rw-r--r--commands/pin-tab.go8
-rw-r--r--commands/prompt.go10
-rw-r--r--commands/pwd.go6
-rw-r--r--commands/quit.go5
-rw-r--r--commands/term.go14
-rw-r--r--commands/terminal/close.go6
-rw-r--r--commands/util.go12
-rw-r--r--commands/z.go16
-rw-r--r--main.go39
87 files changed, 645 insertions, 600 deletions
diff --git a/app/account-wizard.go b/app/account-wizard.go
index db3aae2f..9ee69627 100644
--- a/app/account-wizard.go
+++ b/app/account-wizard.go
@@ -32,7 +32,6 @@ const (
)
type AccountWizard struct {
- aerc *Aerc
step int
steps []*ui.Grid
focus int
@@ -68,7 +67,7 @@ type AccountWizard struct {
complete []ui.Interactive
}
-func showPasswordWarning(aerc *Aerc) {
+func showPasswordWarning() {
title := "ATTENTION"
text := `
The Wizard will store your passwords as clear text in:
@@ -81,12 +80,12 @@ after the setup.
`
warning := NewSelectorDialog(
title, text, []string{"OK"}, 0,
- aerc.SelectedAccountUiConfig(),
+ SelectedAccountUiConfig(),
func(_ string, _ error) {
- aerc.CloseDialog()
+ CloseDialog()
},
)
- aerc.AddDialog(warning)
+ AddDialog(warning)
}
type configStep struct {
@@ -171,10 +170,9 @@ var (
transports = []string{SSL_TLS, OAUTH, XOAUTH, STARTTLS, INSECURE}
)
-func NewAccountWizard(aerc *Aerc) *AccountWizard {
+func NewAccountWizard() *AccountWizard {
wizard := &AccountWizard{
accountName: ui.NewTextInput("", config.Ui).Prompt("> "),
- aerc: aerc,
temporary: false,
email: ui.NewTextInput("", config.Ui).Prompt("> "),
fullName: ui.NewTextInput("", config.Ui).Prompt("> "),
@@ -244,7 +242,7 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard {
wizard.sourcePassword.OnFocusLost(func(_ *ui.TextInput) {
if wizard.sourcePassword.String() != "" {
once.Do(func() {
- showPasswordWarning(aerc)
+ showPasswordWarning()
})
}
})
@@ -262,7 +260,7 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard {
wizard.outgoingPassword.OnChange(func(_ *ui.TextInput) {
if wizard.outgoingPassword.String() != "" {
once.Do(func() {
- showPasswordWarning(aerc)
+ showPasswordWarning()
})
}
wizard.outgoingUri()
@@ -387,7 +385,7 @@ func (wizard *AccountWizard) ConfigureTemporaryAccount(temporary bool) {
func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
if d == nil {
- wizard.aerc.PushError(err.Error())
+ PushError(err.Error())
wizard.Invalidate()
return
}
@@ -402,7 +400,7 @@ func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
wizard.step = step
wizard.focus = focus
wizard.Focus(true)
- wizard.aerc.PushError(err.Error())
+ PushError(err.Error())
wizard.Invalidate()
return
}
@@ -554,13 +552,13 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
config.Accounts = append(config.Accounts, account)
- view, err := NewAccountView(wizard.aerc, account, wizard.aerc, nil)
+ view, err := NewAccountView(account, nil)
if err != nil {
- wizard.aerc.NewTab(errorScreen(err.Error()), account.Name)
+ NewTab(errorScreen(err.Error()), account.Name)
return
}
- wizard.aerc.accounts[account.Name] = view
- wizard.aerc.NewTab(view, account.Name)
+ aerc.accounts[account.Name] = view
+ NewTab(view, account.Name)
if tutorial {
name := "aerc-tutorial"
@@ -573,16 +571,16 @@ func (wizard *AccountWizard) finish(tutorial bool) {
wizard.errorFor(nil, err)
return
}
- wizard.aerc.NewTab(term, "Tutorial")
+ NewTab(term, "Tutorial")
term.OnClose = func(err error) {
- wizard.aerc.RemoveTab(term, false)
+ RemoveTab(term, false)
if err != nil {
- wizard.aerc.PushError(err.Error())
+ PushError(err.Error())
}
}
}
- wizard.aerc.RemoveTab(wizard, false)
+ RemoveTab(wizard, false)
}
func splitHostPath(server string) (string, string) {
diff --git a/app/account.go b/app/account.go
index 3ab7fc8f..bcb5028a 100644
--- a/app/account.go
+++ b/app/account.go
@@ -28,7 +28,6 @@ var _ ProvidesMessages = (*AccountView)(nil)
type AccountView struct {
sync.Mutex
acct *config.AccountConfig
- aerc *Aerc
dirlist DirectoryLister
labels []string
grid *ui.Grid
@@ -58,15 +57,12 @@ func (acct *AccountView) UiConfig() *config.UIConfig {
}
func NewAccountView(
- aerc *Aerc, acct *config.AccountConfig,
- host TabHost, deferLoop chan struct{},
+ acct *config.AccountConfig, deferLoop chan struct{},
) (*AccountView, error) {
acctUiConf := config.Ui.ForAccount(acct.Name)
view := &AccountView{
acct: acct,
- aerc: aerc,
- host: host,
uiConf: acctUiConf,
}
@@ -81,7 +77,7 @@ func NewAccountView(
worker, err := worker.NewWorker(acct.Source, acct.Name)
if err != nil {
- host.SetError(fmt.Sprintf("%s: %s", acct.Name, err))
+ SetError(fmt.Sprintf("%s: %s", acct.Name, err))
log.Errorf("%s: %v", acct.Name, err)
return view, err
}
@@ -92,7 +88,7 @@ func NewAccountView(
view.grid.AddChild(ui.NewBordered(view.dirlist, ui.BORDER_RIGHT, acctUiConf))
}
- view.msglist = NewMessageList(aerc, view)
+ view.msglist = NewMessageList(view)
view.grid.AddChild(view.msglist).At(0, 1)
view.dirlist.OnVirtualNode(func() {
@@ -134,15 +130,15 @@ func (acct *AccountView) UpdateStatus() {
}
func (acct *AccountView) PushStatus(status string, expiry time.Duration) {
- acct.aerc.PushStatus(fmt.Sprintf("%s: %s", acct.acct.Name, status), expiry)
+ PushStatus(fmt.Sprintf("%s: %s", acct.acct.Name, status), expiry)
}
func (acct *AccountView) PushError(err error) {
- acct.aerc.PushError(fmt.Sprintf("%s: %v", acct.acct.Name, err))
+ PushError(fmt.Sprintf("%s: %v", acct.acct.Name, err))
}
func (acct *AccountView) PushWarning(warning string) {
- acct.aerc.PushWarning(fmt.Sprintf("%s: %s", acct.acct.Name, warning))
+ PushWarning(fmt.Sprintf("%s: %s", acct.acct.Name, warning))
}
func (acct *AccountView) AccountConfig() *config.AccountConfig {
@@ -226,7 +222,7 @@ func (acct *AccountView) SelectedMessagePart() *PartInfo {
}
func (acct *AccountView) isSelected() bool {
- return acct == acct.aerc.SelectedAccount()
+ return acct == SelectedAccount()
}
func (acct *AccountView) newStore(name string) *lib.MessageStore {
@@ -247,7 +243,7 @@ func (acct *AccountView) newStore(name string) *lib.MessageStore {
})
if err != nil {
msg := fmt.Sprintf("mail-received hook: %s", err)
- acct.aerc.PushError(msg)
+ PushError(msg)
}
}, func() {
if uiConf.NewMessageBell {
@@ -544,10 +540,10 @@ func (acct *AccountView) updateSplitView(msg *models.MessageInfo) {
acct.grid.RemoveChild(acct.split)
acct.split.Close()
}
- lib.NewMessageStoreView(msg, false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
+ lib.NewMessageStoreView(msg, false, acct.Store(), CryptoProvider(), DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- acct.aerc.PushError(err.Error())
+ PushError(err.Error())
return
}
acct.split = NewMessageViewer(acct, view)
diff --git a/app/aerc.go b/app/aerc.go
index a1995c2d..1170a6f2 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -87,10 +87,8 @@ func NewAerc(
Crypto: crypto,
}
- statusline.SetAerc(aerc)
-
for _, acct := range config.Accounts {
- view, err := NewAccountView(aerc, acct, aerc, deferLoop)
+ view, err := NewAccountView(acct, deferLoop)
if err != nil {
tabs.Add(errorScreen(err.Error()), acct.Name, nil)
} else {
@@ -100,7 +98,7 @@ func NewAerc(
}
if len(config.Accounts) == 0 {
- wizard := NewAccountWizard(aerc)
+ wizard := NewAccountWizard()
wizard.Focus(true)
aerc.NewTab(wizard, "New account")
}
@@ -732,7 +730,7 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
defer ui.Invalidate()
- composer, err := NewComposer(aerc, acct,
+ composer, err := NewComposer(acct,
acct.AccountConfig(), acct.Worker(),
config.Compose.EditHeaders, template, h, nil,
strings.NewReader(body))
@@ -775,7 +773,7 @@ func (aerc *Aerc) Mbox(source string) error {
defer ui.Invalidate()
- mboxView, err := NewAccountView(aerc, &acctConf, aerc, nil)
+ mboxView, err := NewAccountView(&acctConf, nil)
if err != nil {
aerc.NewTab(errorScreen(err.Error()), acctConf.Name)
} else {
@@ -886,9 +884,9 @@ func (aerc *Aerc) isExKey(event *tcell.EventKey, exKey config.KeyStroke) bool {
return event.Modifiers() == exKey.Modifiers && event.Key() == exKey.Key
}
-// CmdFallbackSearch checks cmds for the first executable availabe in PATH. An error is
+// cmdFallbackSearch checks cmds for the first executable availabe in PATH. An error is
// returned if none are found
-func (aerc *Aerc) CmdFallbackSearch(cmds []string) (string, error) {
+func cmdFallbackSearch(cmds []string) (string, error) {
var tried []string
for _, cmd := range cmds {
if cmd == "" {
@@ -899,7 +897,7 @@ func (aerc *Aerc) CmdFallbackSearch(cmds []string) (string, error) {
if err != nil {
tried = append(tried, cmd)
warn := fmt.Sprintf("cmd '%s' not found in PATH, using fallback", cmd)
- aerc.PushWarning(warn)
+ PushWarning(warn)
continue
}
return cmd, nil
diff --git a/app/app.go b/app/app.go
new file mode 100644
index 00000000..80f940a3
--- /dev/null
+++ b/app/app.go
@@ -0,0 +1,80 @@
+package app
+
+import (
+ "time"
+
+ "git.sr.ht/~rjarry/aerc/config"
+ "git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/lib/crypto"
+ "git.sr.ht/~rjarry/aerc/lib/ipc"
+ "git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/models"
+ "git.sr.ht/~rjarry/aerc/worker/types"
+ "github.com/ProtonMail/go-crypto/openpgp"
+)
+
+var aerc *Aerc
+
+func Init(
+ crypto crypto.Provider,
+ cmd func([]string, *config.AccountConfig, *models.MessageInfo) error,
+ complete func(cmd string) ([]string, string), history lib.History,
+ deferLoop chan struct{},
+) {
+ aerc = NewAerc(crypto, cmd, complete, history, deferLoop)
+}
+
+func Drawable() ui.DrawableInteractive { return aerc }
+func IPCHandler() ipc.Handler { return aerc }
+func HandleMessage(msg types.WorkerMessage) { aerc.HandleMessage(msg) }
+
+func CloseBackends() error { return aerc.CloseBackends() }
+
+func AddDialog(d ui.DrawableInteractive) { aerc.AddDialog(d) }
+func CloseDialog() { aerc.CloseDialog() }
+
+func HumanReadableBindings() []string {
+ return aerc.HumanReadableBindings()
+}
+
+func Account(name string) (*AccountView, error) { return aerc.Account(name) }
+func AccountNames() []string { return aerc.AccountNames() }
+func NextAccount() (*AccountView, error) { return aerc.NextAccount() }
+func PrevAccount() (*AccountView, error) { return aerc.PrevAccount() }
+func SelectedAccount() *AccountView { return aerc.SelectedAccount() }
+func SelectedAccountUiConfig() *config.UIConfig { return aerc.SelectedAccountUiConfig() }
+
+func NextTab() { aerc.NextTab() }
+func PrevTab() { aerc.PrevTab() }
+func PinTab() { aerc.PinTab() }
+func UnpinTab() { aerc.UnpinTab() }
+func MoveTab(i int, relative bool) { aerc.MoveTab(i, relative) }
+func TabNames() []string { return aerc.TabNames() }
+func SelectTab(name string) bool { return aerc.SelectTab(name) }
+func SelectPreviousTab() bool { return aerc.SelectPreviousTab() }
+func SelectedTab() *ui.Tab { return aerc.SelectedTab() }
+func SelectedTabContent() ui.Drawable { return aerc.SelectedTabContent() }
+func SelectTabIndex(index int) bool { return aerc.SelectTabIndex(index) }
+func RemoveTab(tab ui.Drawable, closeContent bool) { aerc.RemoveTab(tab, closeContent) }
+func NewTab(clickable ui.Drawable, name string) *ui.Tab { return aerc.NewTab(clickable, name) }
+func ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name string, closeSrc bool) {
+ aerc.ReplaceTab(tabSrc, tabTarget, name, closeSrc)
+}
+
+func UpdateStatus() { aerc.UpdateStatus() }
+func PushPrompt(prompt *ExLine) { aerc.PushPrompt(prompt) }
+func SetError(text string) { aerc.SetError(text) }
+func PushError(text string) *StatusMessage { return aerc.PushError(text) }
+func PushWarning(text string) *StatusMessage { return aerc.PushWarning(text) }
+func PushSuccess(text string) *StatusMessage { return aerc.PushSuccess(text) }
+func PushStatus(text string, expiry time.Duration) *StatusMessage {
+ return aerc.PushStatus(text, expiry)
+}
+
+func RegisterChoices(choices []Choice) { aerc.RegisterChoices(choices) }
+func RegisterPrompt(prompt string, cmd []string) { aerc.RegisterPrompt(prompt, cmd) }
+
+func CryptoProvider() crypto.Provider { return aerc.Crypto }
+func DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err error) {
+ return aerc.DecryptKeys(keys, symmetric)
+}
diff --git a/app/compose.go b/app/compose.go
index 6eda2b0d..546184d8 100644
--- a/app/compose.go
+++ b/app/compose.go
@@ -41,7 +41,6 @@ type Composer struct {
acctConfig *config.AccountConfig
acct *AccountView
- aerc *Aerc
attachments []lib.Attachment
editor *Terminal
@@ -75,7 +74,7 @@ type Composer struct {
}
func NewComposer(
- aerc *Aerc, acct *AccountView, acctConfig *config.AccountConfig,
+ acct *AccountView, acctConfig *config.AccountConfig,
worker *types.Worker, editHeaders bool, template string,
h *mail.Header, orig *models.OriginalMail, body io.Reader,
) (*Composer, error) {
@@ -92,7 +91,6 @@ func NewComposer(
c := &Composer{
acct: acct,
acctConfig: acctConfig,
- aerc: aerc,
header: h,
parent: orig,
email: email,
@@ -178,7 +176,7 @@ func (c *Composer) setupFor(view *AccountView) error {
cmd = config.Compose.AddressBookCmd
}
cmpl := completer.New(cmd, func(err error) {
- c.aerc.PushError(
+ PushError(
fmt.Sprintf("could not complete header: %v", err))
log.Errorf("could not complete header: %v", err)
})
@@ -192,7 +190,7 @@ func (c *Composer) setupFor(view *AccountView) error {
}
// rebuild editors and focusable slice
- c.buildComposeHeader(c.aerc, cmpl)
+ c.buildComposeHeader(cmpl)
// restore the editor in the focusable list
if focusEditor != nil {
@@ -224,7 +222,7 @@ func (c *Composer) setupFor(view *AccountView) error {
return nil
}
-func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) {
+func (c *Composer) buildComposeHeader(cmpl *completer.Completer) {
c.layout = config.Compose.HeaderLayout
c.editors = make(map[string]*headerEditor)
c.focusable = make([]ui.MouseableDrawableInteractive, 0)
@@ -351,13 +349,13 @@ func (c *Composer) SetAttachKey(attach bool) error {
} else {
s = c.acctConfig.From.Address
}
- c.crypto.signKey, err = c.aerc.Crypto.GetSignerKeyId(s)
+ c.crypto.signKey, err = CryptoProvider().GetSignerKeyId(s)
if err != nil {
return err
}
}
- r, err := c.aerc.Crypto.ExportKey(c.crypto.signKey)
+ r, err := CryptoProvider().ExportKey(c.crypto.signKey)
if err != nil {
return err
}
@@ -435,7 +433,7 @@ func (c *Composer) updateCrypto() error {
c.crypto = newCryptoStatus(uiConfig)
}
if c.sign {
- cp := c.aerc.Crypto
+ cp := CryptoProvider()
s, err := c.Signer()
if err != nil {
return errors.Wrap(err, "Signer")
@@ -685,7 +683,7 @@ func (c *Composer) readSignatureFromFile() []byte {
sigFile = xdg.ExpandHome(sigFile)
signature, err := os.ReadFile(sigFile)
if err != nil {
- c.aerc.PushError(
+ PushError(
fmt.Sprintf(" Error loading signature from file: %v", sigFile))
return nil
}
@@ -1026,12 +1024,12 @@ func (c *Composer) WriteMessage(header *mail.Header, writer io.Writer) error {
if err != nil {
return err
}
- cleartext, err = c.aerc.Crypto.Encrypt(&buf, rcpts, signer, c.aerc.DecryptKeys, header)
+ cleartext, err = CryptoProvider().Encrypt(&buf, rcpts, signer, DecryptKeys, header)
if err != nil {
return err
}
} else {
- cleartext, err = c.aerc.Crypto.Sign(&buf, signer, c.aerc.DecryptKeys, header)
+ cleartext, err = CryptoProvider().Sign(&buf, signer, DecryptKeys, header)
if err != nil {
return err
}
@@ -1235,7 +1233,7 @@ func (c *Composer) termClosed(err error) {
return
}
if e := c.reopenEmailFile(); e != nil {
- c.aerc.PushError("Failed to reopen email file: " + e.Error())
+ PushError("Failed to reopen email file: " + e.Error())
}
editor := c.editor
defer editor.Destroy()
@@ -1247,8 +1245,8 @@ func (c *Composer) termClosed(err error) {
if editor.cmd.ProcessState.ExitCode() > 0 {
c.Close()
- c.aerc.RemoveTab(c, true)
- c.aerc.PushError("Editor exited with error. Compose aborted!")
+ RemoveTab(c, true)
+ PushError("Editor exited with error. Compose aborted!")
return
}
@@ -1256,12 +1254,12 @@ func (c *Composer) termClosed(err error) {
// parse embedded header when editor is closed
embedHeader, err := c.parseEmbeddedHeader()
if err != nil {
- c.aerc.PushError(err.Error())
+ PushError(err.Error())
err := c.showTerminal()
if err != nil {
c.Close()
- c.aerc.RemoveTab(c, true)
- c.aerc.PushError(err.Error())
+ RemoveTab(c, true)
+ PushError(err.Error())
}
return
}
@@ -1311,7 +1309,7 @@ func (c *Composer) showTerminal() error {
"vi",
"nano",
}
- editorName, err := c.aerc.CmdFallbackSearch(cmds)
+ editorName, err := cmdFallbackSearch(cmds)
if err != nil {
c.acct.PushError(fmt.Errorf("could not start editor: %w", err))
}
@@ -1900,12 +1898,12 @@ func (c *Composer) checkEncryptionKeys(_ string) bool {
// explicitly call c.SetEncrypt(false) when encryption is not possible
c.SetEncrypt(false)
st := fmt.Sprintf("Cannot encrypt: %v", err)
- c.aerc.statusline.PushError(st)
+ aerc.statusline.PushError(st)
return false
}
var mk []string
for _, rcpt := range rcpts {
- key, err := c.aerc.Crypto.GetKeyId(rcpt)
+ key, err := CryptoProvider().GetKeyId(rcpt)
if err != nil || key == "" {
mk = append(mk, rcpt)
}
@@ -1919,7 +1917,7 @@ func (c *Composer) checkEncryptionKeys(_ string) bool {
if c.Config().PgpOpportunisticEncrypt {
switch c.Config().PgpErrorLevel {
case config.PgpErrorLevelWarn:
- c.aerc.statusline.PushWarning(st)
+ aerc.statusline.PushWarning(st)
return false
case config.PgpErrorLevelNone:
return false
@@ -1927,7 +1925,7 @@ func (c *Composer) checkEncryptionKeys(_ string) bool {
// Continue to the default
}
}
- c.aerc.statusline.PushError(st)
+ PushError(st)
encrypt = false
case len(rcpts) == 0:
encrypt = false
diff --git a/app/msglist.go b/app/msglist.go
index 57771ae8..b60ae148 100644
--- a/app/msglist.go
+++ b/app/msglist.go
@@ -27,14 +27,12 @@ type MessageList struct {
spinner *Spinner
store *lib.MessageStore
isInitalizing bool
- aerc *Aerc
}
-func NewMessageList(aerc *Aerc, account *AccountView) *MessageList {
+func NewMessageList(account *AccountView) *MessageList {
ml := &MessageList{
spinner: NewSpinner(account.uiConf),
isInitalizing: true,
- aerc: aerc,
}
// TODO: stop spinner, probably
ml.spinner.Start()
@@ -56,11 +54,11 @@ type messageRowParams struct {
func (ml *MessageList) Draw(ctx *ui.Context) {
ml.height = ctx.Height()
ml.width = ctx.Width()
- uiConfig := ml.aerc.SelectedAccountUiConfig()
+ uiConfig := SelectedAccountUiConfig()
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT))
- acct := ml.aerc.SelectedAccount()
+ acct := SelectedAccount()
store := ml.Store()
if store == nil || acct == nil || len(store.Uids()) == 0 {
if ml.isInitalizing {
@@ -242,7 +240,7 @@ func addMessage(
}
func (ml *MessageList) drawScrollbar(ctx *ui.Context) {
- uiConfig := ml.aerc.SelectedAccountUiConfig()
+ uiConfig := SelectedAccountUiConfig()
gutterStyle := uiConfig.GetStyle(config.STYLE_MSGLIST_GUTTER)
pillStyle := uiConfig.GetStyle(config.STYLE_MSGLIST_PILL)
@@ -259,13 +257,13 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
- if ml.aerc == nil {
+ if aerc == nil {
return
}
selectedMsg, ok := ml.Clicked(localX, localY)
if ok {
ml.Select(selectedMsg)
- acct := ml.aerc.SelectedAccount()
+ acct := SelectedAccount()
if acct == nil || acct.Messages().Empty() {
return
}
@@ -275,14 +273,14 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
return
}
lib.NewMessageStoreView(msg, acct.UiConfig().AutoMarkRead,
- store, ml.aerc.Crypto, ml.aerc.DecryptKeys,
+ store, CryptoProvider(), DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- ml.aerc.PushError(err.Error())
+ PushError(err.Error())
return
}
viewer := NewMessageViewer(acct, view)
- ml.aerc.NewTab(viewer, msg.Envelope.Subject)
+ NewTab(viewer, msg.Envelope.Subject)
})
}
case tcell.WheelDown:
@@ -391,7 +389,7 @@ func (ml *MessageList) Select(index int) {
}
func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) {
- uiConfig := ml.aerc.SelectedAccountUiConfig()
+ uiConfig := SelectedAccountUiConfig()
msg := uiConfig.EmptyMessage
ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0,
uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT), "%s", msg)
diff --git a/app/msgviewer.go b/app/msgviewer.go
index 2d261c3f..5da37552 100644
--- a/app/msgviewer.go
+++ b/app/msgviewer.go
@@ -563,7 +563,7 @@ func NewPartViewer(
os.Getenv("PAGER"),
"less -Rc",
}
- pagerCmd, err := acct.aerc.CmdFallbackSearch(cmds)
+ pagerCmd, err := cmdFallbackSearch(cmds)
if err != nil {
acct.PushError(fmt.Errorf("could not start pager: %w", err))
return nil, err
diff --git a/app/status.go b/app/status.go
index f6919e29..fdeede19 100644
--- a/app/status.go
+++ b/app/status.go
@@ -18,7 +18,6 @@ import (
type StatusLine struct {
sync.Mutex
stack []*StatusMessage
- aerc *Aerc
acct *AccountView
err string
}
@@ -48,9 +47,9 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
msg = runewidth.FillRight(msg, ctx.Width())
style := status.uiConfig().GetStyle(config.STYLE_STATUSLINE_ERROR)
ctx.Printf(0, 0, style, "%s", msg)
- case status.aerc != nil && status.acct != nil:
+ case aerc != nil && status.acct != nil:
data := state.NewDataSetter()
- data.SetPendingKeys(status.aerc.pendingKeys)
+ data.SetPendingKeys(aerc.pendingKeys)
data.SetState(&status.acct.state)
data.SetAccount(status.acct.acct)
data.SetFolder(status.acct.Directories().SelectedDirectory())
@@ -154,11 +153,7 @@ func (status *StatusLine) Expire() {
}
func (status *StatusLine) uiConfig() *config.UIConfig {
- return status.aerc.SelectedAccountUiConfig()
-}
-
-func (status *StatusLine) SetAerc(aerc *Aerc) {
- status.aerc = aerc
+ return SelectedAccountUiConfig()
}
func (msg *StatusMessage) Color(style tcell.Style) {
diff --git a/commands/account/cf.go b/commands/account/cf.go
index 38841474..cd93ed29 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -22,15 +22,15 @@ func (ChangeFolder) Aliases() []string {
return []string{"cf"}
}
-func (ChangeFolder) Complete(aerc *app.Aerc, args []string) []string {
- return commands.GetFolders(aerc, args)
+func (ChangeFolder) Complete(args []string) []string {
+ return commands.GetFolders(args)
}
-func (ChangeFolder) Execute(aerc *app.Aerc, args []string) error {
+func (ChangeFolder) Execute(args []string) error {
if len(args) == 1 {
return errors.New("Usage: cf <folder>")
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/check-mail.go b/commands/account/check-mail.go
index 2b6a06f9..a8d80a66 100644
--- a/commands/account/check-mail.go
+++ b/commands/account/check-mail.go
@@ -16,12 +16,12 @@ func (CheckMail) Aliases() []string {
return []string{"check-mail"}
}
-func (CheckMail) Complete(aerc *app.Aerc, args []string) []string {
+func (CheckMail) Complete(args []string) []string {
return nil
}
-func (CheckMail) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (CheckMail) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/clear.go b/commands/account/clear.go
index 547c26c4..b67454dd 100644
--- a/commands/account/clear.go
+++ b/commands/account/clear.go
@@ -18,12 +18,12 @@ func (Clear) Aliases() []string {
return []string{"clear"}
}
-func (Clear) Complete(aerc *app.Aerc, args []string) []string {
+func (Clear) Complete(args []string) []string {
return nil
}
-func (Clear) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (Clear) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/compose.go b/commands/account/compose.go
index e2812251..56079868 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -25,16 +25,16 @@ func (Compose) Aliases() []string {
return []string{"compose"}
}
-func (Compose) Complete(aerc *app.Aerc, args []string) []string {
+func (Compose) Complete(args []string) []string {
return nil
}
-func (Compose) Execute(aerc *app.Aerc, args []string) error {
+func (Compose) Execute(args []string) error {
body, template, editHeaders, err := buildBody(args)
if err != nil {
return err
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -50,13 +50,13 @@ func (Compose) Execute(aerc *app.Aerc, args []string) error {
}
headers := mail.HeaderFromMap(msg.Header)
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
template, &headers, nil, msg.Body)
if err != nil {
return err
}
- composer.Tab = aerc.NewTab(composer, "New email")
+ composer.Tab = app.NewTab(composer, "New email")
return nil
}
diff --git a/commands/account/connection.go b/commands/account/connection.go
index 2704d9bb..3b30dbda 100644
--- a/commands/account/connection.go
+++ b/commands/account/connection.go
@@ -18,12 +18,12 @@ func (Connection) Aliases() []string {
return []string{"connect", "disconnect"}
}
-func (Connection) Complete(aerc *app.Aerc, args []string) []string {
+func (Connection) Complete(args []string) []string {
return nil
}
-func (Connection) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (Connection) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/expand-folder.go b/commands/account/expand-folder.go
index 8a7a8e93..29203adc 100644
--- a/commands/account/expand-folder.go
+++ b/commands/account/expand-folder.go
@@ -17,15 +17,15 @@ func (ExpandCollapseFolder) Aliases() []string {
return []string{"expand-folder", "collapse-folder"}
}
-func (ExpandCollapseFolder) Complete(aerc *app.Aerc, args []string) []string {
+func (ExpandCollapseFolder) Complete(args []string) []string {
return nil
}
-func (ExpandCollapseFolder) Execute(aerc *app.Aerc, args []string) error {
+func (ExpandCollapseFolder) Execute(args []string) error {
if len(args) > 1 {
return expandCollapseFolderUsage(args[0])
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/export-mbox.go b/commands/account/export-mbox.go
index c227bdf9..e9a663c5 100644
--- a/commands/account/export-mbox.go
+++ b/commands/account/export-mbox.go
@@ -25,17 +25,17 @@ func (ExportMbox) Aliases() []string {
return []string{"export-mbox"}
}
-func (ExportMbox) Complete(aerc *app.Aerc, args []string) []string {
+func (ExportMbox) Complete(args []string) []string {
return commands.CompletePath(filepath.Join(args...))
}
-func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
+func (ExportMbox) Execute(args []string) error {
if len(args) != 2 {
return exportFolderUsage(args[0])
}
filename := args[1]
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -53,15 +53,15 @@ func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
}
}
- aerc.PushStatus("Exporting to "+filename, 10*time.Second)
+ app.PushStatus("Exporting to "+filename, 10*time.Second)
// uids of messages to export
var uids []uint32
// check if something is marked - we export that then
- msgProvider, ok := aerc.SelectedTabContent().(app.ProvidesMessages)
+ msgProvider, ok := app.SelectedTabContent().(app.ProvidesMessages)
if !ok {
- msgProvider = aerc.SelectedAccount()
+ msgProvider = app.SelectedAccount()
}
if msgProvider != nil {
marked, err := msgProvider.MarkedMessages()
@@ -75,7 +75,7 @@ func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
file, err := os.Create(filename)
if err != nil {
log.Errorf("failed to create file: %v", err)
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
defer file.Close()
@@ -99,7 +99,7 @@ func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
if retries > 10 {
errorMsg := fmt.Sprintf("too many retries: %d; stopping export", retries)
log.Errorf(errorMsg)
- aerc.PushError(args[0] + " " + errorMsg)
+ app.PushError(args[0] + " " + errorMsg)
break
}
sleeping := time.Duration(retries * 1e9 * 2)
@@ -116,7 +116,7 @@ func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
done <- true
case *types.Error:
log.Errorf("failed to fetch message: %v", msg.Error)
- aerc.PushError(args[0] + " error encountered: " + msg.Error.Error())
+ app.PushError(args[0] + " error encountered: " + msg.Error.Error())
done <- false
case *types.FullMessage:
mu.Lock()
@@ -140,7 +140,7 @@ func (ExportMbox) Execute(aerc *app.Aerc, args []string) error {
retries++
}
statusInfo := fmt.Sprintf("Exported %d of %d messages to %s.", ctr, total, filename)
- aerc.PushStatus(statusInfo, 10*time.Second)
+ app.PushStatus(statusInfo, 10*time.Second)
log.Debugf(statusInfo)
}()
diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 2a441737..4ede8c26 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -28,17 +28,17 @@ func (ImportMbox) Aliases() []string {
return []string{"import-mbox"}
}
-func (ImportMbox) Complete(aerc *app.Aerc, args []string) []string {
+func (ImportMbox) Complete(args []string) []string {
return commands.CompletePath(filepath.Join(args...))
}
-func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
+func (ImportMbox) Execute(args []string) error {
if len(args) != 2 {
return importFolderUsage(args[0])
}
filename := args[1]
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -55,18 +55,18 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
importFolder := func() {
defer log.PanicHandler()
statusInfo := fmt.Sprintln("Importing", filename, "to folder", folder)
- aerc.PushStatus(statusInfo, 10*time.Second)
+ app.PushStatus(statusInfo, 10*time.Second)
log.Debugf(statusInfo)
f, err := os.Open(filename)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
defer f.Close()
messages, err := mboxer.Read(f)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
worker := acct.Worker()
@@ -94,7 +94,7 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
case *types.Unsupported:
errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
log.Errorf(errMsg)
- aerc.PushError(errMsg)
+ app.PushError(errMsg)
return
case *types.Error:
log.Errorf("AppendMessage failed: %v", msg.Error)
@@ -125,23 +125,22 @@ func (ImportMbox) Execute(aerc *app.Aerc, args []string) error {
}
infoStr := fmt.Sprintf("%s: imported %d of %d successfully.", args[0], appended, len(messages))
log.Debugf(infoStr)
- aerc.PushSuccess(infoStr)
+ app.PushSuccess(infoStr)
}
if len(store.Uids()) > 0 {
confirm := app.NewSelectorDialog(
"Selected directory is not empty",
fmt.Sprintf("Import mbox file to %s anyways?", folder),
- []string{"No", "Yes"}, 0, aerc.SelectedAccountUiConfig(),
+ []string{"No", "Yes"}, 0, app.SelectedAccountUiConfig(),
func(option string, err error) {
- aerc.CloseDialog()
- aerc.Invalidate()
+ app.CloseDialog()
if option == "Yes" {
go importFolder()
}
},
)
- aerc.AddDialog(confirm)
+ app.AddDialog(confirm)
} else {
go importFolder()
}
diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go
index 79e0a4fa..7a1f7b9e 100644
--- a/commands/account/mkdir.go
+++ b/commands/account/mkdir.go
@@ -19,13 +19,13 @@ func (MakeDir) Aliases() []string {
return []string{"mkdir"}
}
-func (MakeDir) Complete(aerc *app.Aerc, args []string) []string {
+func (MakeDir) Complete(args []string) []string {
if len(args) == 0 {
return nil
}
name := strings.Join(args, " ")
- list := aerc.SelectedAccount().Directories().List()
+ list := app.SelectedAccount().Directories().List()
inboxes := make([]string, len(list))
copy(inboxes, list)
@@ -36,16 +36,16 @@ func (MakeDir) Complete(aerc *app.Aerc, args []string) []string {
inboxes = append(inboxes[:i], inboxes[i+1:]...)
continue
}
- inboxes[i] += aerc.SelectedAccount().Worker().PathSeparator()
+ inboxes[i] += app.SelectedAccount().Worker().PathSeparator()
}
return inboxes
}
-func (MakeDir) Execute(aerc *app.Aerc, args []string) error {
+func (MakeDir) Execute(args []string) error {
if len(args) == 0 {
return errors.New("Usage: :mkdir <name>")
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -55,10 +55,10 @@ func (MakeDir) Execute(aerc *app.Aerc, args []string) error {
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Directory created.", 10*time.Second)
+ app.PushStatus("Directory created.", 10*time.Second)
acct.Directories().Select(name)
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
return nil
diff --git a/commands/account/next-folder.go b/commands/account/next-folder.go
index b0657ff1..2b23e6da 100644
--- a/commands/account/next-folder.go
+++ b/commands/account/next-folder.go
@@ -18,11 +18,11 @@ func (NextPrevFolder) Aliases() []string {
return []string{"next-folder", "prev-folder"}
}
-func (NextPrevFolder) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevFolder) Complete(args []string) []string {
return nil
}
-func (NextPrevFolder) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevFolder) Execute(args []string) error {
if len(args) > 2 {
return nextPrevFolderUsage(args[0])
}
@@ -36,7 +36,7 @@ func (NextPrevFolder) Execute(aerc *app.Aerc, args []string) error {
return nextPrevFolderUsage(args[0])
}
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/next-result.go b/commands/account/next-result.go
index 06478f0c..ef4078da 100644
--- a/commands/account/next-result.go
+++ b/commands/account/next-result.go
@@ -18,15 +18,15 @@ func (NextPrevResult) Aliases() []string {
return []string{"next-result", "prev-result"}
}
-func (NextPrevResult) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevResult) Complete(args []string) []string {
return nil
}
-func (NextPrevResult) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevResult) Execute(args []string) error {
if len(args) > 1 {
return nextPrevResultUsage(args[0])
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/next.go b/commands/account/next.go
index 224534b9..fff36bd1 100644
--- a/commands/account/next.go
+++ b/commands/account/next.go
@@ -20,16 +20,16 @@ func (NextPrevMsg) Aliases() []string {
return []string{"next", "next-message", "prev", "prev-message"}
}
-func (NextPrevMsg) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevMsg) Complete(args []string) []string {
return nil
}
-func (NextPrevMsg) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevMsg) Execute(args []string) error {
n, pct, err := ParseNextPrevMessage(args)
if err != nil {
return err
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/recover.go b/commands/account/recover.go
index 1bb1aceb..e0d1c6eb 100644
--- a/commands/account/recover.go
+++ b/commands/account/recover.go
@@ -27,7 +27,7 @@ func (Recover) Options() string {
return "feE"
}
-func (r Recover) Complete(aerc *app.Aerc, args []string) []string {
+func (r Recover) Complete(args []string) []string {
// file name of temp file is hard-coded in the NewComposer() function
files, err := filepath.Glob(
filepath.Join(os.TempDir(), "aerc-compose-*.eml"),
@@ -35,13 +35,13 @@ func (r Recover) Complete(aerc *app.Aerc, args []string) []string {
if err != nil {
return nil
}
- return commands.CompletionFromList(aerc, files,
+ return commands.CompletionFromList(files,
commands.Operands(args, r.Options()))
}
-func (r Recover) Execute(aerc *app.Aerc, args []string) error {
+func (r Recover) Execute(args []string) error {
// Complete() expects to be passed only the arguments, not including the command name
- if len(Recover{}.Complete(aerc, args[1:])) == 0 {
+ if len(Recover{}.Complete(args[1:])) == 0 {
return errors.New("No messages to recover.")
}
@@ -67,7 +67,7 @@ func (r Recover) Execute(aerc *app.Aerc, args []string) error {
return errors.New("Usage: recover [-f] [-E|-e] <file>")
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -89,13 +89,13 @@ func (r Recover) Execute(aerc *app.Aerc, args []string) error {
return err
}
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
"", nil, nil, bytes.NewReader(data))
if err != nil {
return err
}
- composer.Tab = aerc.NewTab(composer, "Recovered")
+ composer.Tab = app.NewTab(composer, "Recovered")
// remove file if force flag is set
if force {
diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go
index eca8b59f..3b109a67 100644
--- a/commands/account/rmdir.go
+++ b/commands/account/rmdir.go
@@ -20,12 +20,12 @@ func (RemoveDir) Aliases() []string {
return []string{"rmdir"}
}
-func (RemoveDir) Complete(aerc *app.Aerc, args []string) []string {
+func (RemoveDir) Complete(args []string) []string {
return nil
}
-func (RemoveDir) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (RemoveDir) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -84,11 +84,11 @@ func (RemoveDir) Execute(aerc *app.Aerc, args []string) error {
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Directory removed.", 10*time.Second)
+ app.PushStatus("Directory removed.", 10*time.Second)
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
case *types.Unsupported:
- aerc.PushError(":rmdir is not supported by the backend.")
+ app.PushError(":rmdir is not supported by the backend.")
}
})
diff --git a/commands/account/search.go b/commands/account/search.go
index 04f7ddc3..51bd3042 100644
--- a/commands/account/search.go
+++ b/commands/account/search.go
@@ -27,7 +27,6 @@ func (SearchFilter) Aliases() []string {
}
func (s SearchFilter) CompleteOption(
- aerc *app.Aerc,
r rune,
search string,
) []string {
@@ -36,20 +35,20 @@ func (s SearchFilter) CompleteOption(
case 'x', 'X':
valid = commands.GetFlagList()
case 't', 'f', 'c':
- valid = commands.GetAddress(aerc, search)
+ valid = commands.GetAddress(search)
case 'd':
valid = commands.GetDateList()
default:
}
- return commands.CompletionFromList(aerc, valid, []string{search})
+ return commands.CompletionFromList(valid, []string{search})
}
-func (SearchFilter) Complete(aerc *app.Aerc, args []string) []string {
+func (SearchFilter) Complete(args []string) []string {
return nil
}
-func (SearchFilter) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (SearchFilter) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -60,7 +59,7 @@ func (SearchFilter) Execute(aerc *app.Aerc, args []string) error {
if args[0] == "filter" {
if len(args[1:]) == 0 {
- return Clear{}.Execute(aerc, []string{"clear"})
+ return Clear{}.Execute([]string{"clear"})
}
acct.SetStatus(state.FilterActivity("Filtering..."), state.Search(""))
store.SetFilter(args[1:])
diff --git a/commands/account/select.go b/commands/account/select.go
index aeb584f4..aea17e0e 100644
--- a/commands/account/select.go
+++ b/commands/account/select.go
@@ -17,11 +17,11 @@ func (SelectMessage) Aliases() []string {
return []string{"select", "select-message"}
}
-func (SelectMessage) Complete(aerc *app.Aerc, args []string) []string {
+func (SelectMessage) Complete(args []string) []string {
return nil
}
-func (SelectMessage) Execute(aerc *app.Aerc, args []string) error {
+func (SelectMessage) Execute(args []string) error {
if len(args) != 2 {
return errors.New("Usage: :select-message <n>")
}
@@ -35,7 +35,7 @@ func (SelectMessage) Execute(aerc *app.Aerc, args []string) error {
return errors.New("Usage: :select-message <n>")
}
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
diff --git a/commands/account/sort.go b/commands/account/sort.go
index 8624ff12..a7edd552 100644
--- a/commands/account/sort.go
+++ b/commands/account/sort.go
@@ -21,7 +21,7 @@ func (Sort) Aliases() []string {
return []string{"sort"}
}
-func (Sort) Complete(aerc *app.Aerc, args []string) []string {
+func (Sort) Complete(args []string) []string {
supportedCriteria := []string{
"arrival",
"cc",
@@ -58,12 +58,12 @@ func (Sort) Complete(aerc *app.Aerc, args []string) []string {
}
// the last item is not complete
completions = commands.FilterList(supportedCriteria, last, currentPrefix,
- aerc.SelectedAccountUiConfig().FuzzyComplete)
+ app.SelectedAccountUiConfig().FuzzyComplete)
return completions
}
-func (Sort) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (Sort) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected.")
}
diff --git a/commands/account/split.go b/commands/account/split.go
index 82870d60..ddc79e2f 100644
--- a/commands/account/split.go
+++ b/commands/account/split.go
@@ -18,28 +18,28 @@ func (Split) Aliases() []string {
return []string{"split", "vsplit"}
}
-func (Split) Complete(aerc *app.Aerc, args []string) []string {
+func (Split) Complete(args []string) []string {
return nil
}
-func (Split) Execute(aerc *app.Aerc, args []string) error {
+func (Split) Execute(args []string) error {
if len(args) > 2 {
return errors.New("Usage: [v]split n")
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
- store := aerc.SelectedAccount().Store()
+ store := app.SelectedAccount().Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
n := 0
if acct.SplitSize() == 0 {
if args[0] == "split" {
- n = aerc.SelectedAccount().Messages().Height() / 4
+ n = app.SelectedAccount().Messages().Height() / 4
} else {
- n = aerc.SelectedAccount().Messages().Width() / 2
+ n = app.SelectedAccount().Messages().Width() / 2
}
}
diff --git a/commands/account/view.go b/commands/account/view.go
index cbf2ce3f..8d5bc6ed 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -18,11 +18,11 @@ func (ViewMessage) Aliases() []string {
return []string{"view-message", "view"}
}
-func (ViewMessage) Complete(aerc *app.Aerc, args []string) []string {
+func (ViewMessage) Complete(args []string) []string {
return nil
}
-func (ViewMessage) Execute(aerc *app.Aerc, args []string) error {
+func (ViewMessage) Execute(args []string) error {
peek := false
opts, optind, err := getopt.Getopts(args, "p")
if err != nil {
@@ -38,7 +38,7 @@ func (ViewMessage) Execute(aerc *app.Aerc, args []string) error {
if len(args) != optind {
return errors.New("Usage: view-message [-p]")
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -55,18 +55,18 @@ func (ViewMessage) Execute(aerc *app.Aerc, args []string) error {
return nil
}
if msg.Error != nil {
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
return nil
}
lib.NewMessageStoreView(msg, !peek && acct.UiConfig().AutoMarkRead,
- store, aerc.Crypto, aerc.DecryptKeys,
+ store, app.CryptoProvider(), app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
viewer := app.NewMessageViewer(acct, view)
- aerc.NewTab(viewer, msg.Envelope.Subject)
+ app.NewTab(viewer, msg.Envelope.Subject)
})
return nil
}
diff --git a/commands/cd.go b/commands/cd.go
index 67891589..ded325d5 100644
--- a/commands/cd.go
+++ b/commands/cd.go
@@ -21,7 +21,7 @@ func (ChangeDirectory) Aliases() []string {
return []string{"cd"}
}
-func (ChangeDirectory) Complete(aerc *app.Aerc, args []string) []string {
+func (ChangeDirectory) Complete(args []string) []string {
path := strings.Join(args, " ")
completions := CompletePath(path)
@@ -36,7 +36,7 @@ func (ChangeDirectory) Complete(aerc *app.Aerc, args []string) []string {
return dirs
}
-func (ChangeDirectory) Execute(aerc *app.Aerc, args []string) error {
+func (ChangeDirectory) Execute(args []string) error {
if len(args) < 1 {
return errors.New("Usage: cd [directory]")
}
@@ -57,7 +57,7 @@ func (ChangeDirectory) Execute(aerc *app.Aerc, args []string) error {
target = xdg.ExpandHome(target)
if err := os.Chdir(target); err == nil {
previousDir = cwd
- aerc.UpdateStatus()
+ app.UpdateStatus()
}
return err
}
diff --git a/commands/choose.go b/commands/choose.go
index 64535ea6..3f1410cf 100644
--- a/commands/choose.go
+++ b/commands/choose.go
@@ -17,11 +17,11 @@ func (Choose) Aliases() []string {
return []string{"choose"}
}
-func (Choose) Complete(aerc *app.Aerc, args []string) []string {
+func (Choose) Complete(args []string) []string {
return nil
}
-func (Choose) Execute(aerc *app.Aerc, args []string) error {
+func (Choose) Execute(args []string) error {
if len(args) < 5 || len(args)%4 != 1 {
return chooseUsage(args[0])
}
@@ -38,7 +38,7 @@ func (Choose) Execute(aerc *app.Aerc, args []string) error {
})
}
- aerc.RegisterChoices(choices)
+ app.RegisterChoices(choices)
return nil
}
diff --git a/commands/commands.go b/commands/commands.go
index 0971d478..73550a35 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -19,8 +19,8 @@ import (
type Command interface {
Aliases() []string
- Execute(*app.Aerc, []string) error
- Complete(*app.Aerc, []string) []string
+ Execute([]string) error
+ Complete([]string) []string
}
type OptionsProvider interface {
@@ -30,7 +30,7 @@ type OptionsProvider interface {
type OptionCompleter interface {
OptionsProvider
- CompleteOption(*app.Aerc, rune, string) []string
+ CompleteOption(rune, string) []string
}
type Commands map[string]Command
@@ -81,13 +81,12 @@ type CommandSource interface {
}
func templateData(
- aerc *app.Aerc,
cfg *config.AccountConfig,
msg *models.MessageInfo,
) models.TemplateData {
var folder *models.Directory
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct != nil {
folder = acct.Directories().SelectedDirectory()
}
@@ -112,7 +111,6 @@ func templateData(
}
func (cmds *Commands) ExecuteCommand(
- aerc *app.Aerc,
origArgs []string,
account *config.AccountConfig,
msg *models.MessageInfo,
@@ -120,7 +118,7 @@ func (cmds *Commands) ExecuteCommand(
if len(origArgs) == 0 {
return errors.New("Expected a command.")
}
- data := templateData(aerc, account, msg)
+ data := templateData(account, msg)
args, err := expand(data, origArgs)
if err != nil {
return err
@@ -130,7 +128,7 @@ func (cmds *Commands) ExecuteCommand(
}
if cmd, ok := cmds.dict()[args[0]]; ok {
log.Tracef("executing command %v", args)
- return cmd.Execute(aerc, args)
+ return cmd.Execute(args)
}
return NoSuchCommand(args[0])
}
@@ -178,7 +176,7 @@ func expand(data models.TemplateData, origArgs []string) ([]string, error) {
}
func GetTemplateCompletion(
- aerc *app.Aerc, cmd string,
+ cmd string,
) ([]string, string, bool) {
args, err := splitCmd(cmd)
if err != nil || len(args) == 0 {
@@ -207,12 +205,12 @@ func GetTemplateCompletion(
templates.Terms(),
strings.TrimSpace(search),
"",
- aerc.SelectedAccountUiConfig().FuzzyComplete,
+ app.SelectedAccountUiConfig().FuzzyComplete,
)
return options, prefix + padding, true
case countLeft == countRight:
// expand template
- data := templateData(aerc, nil, nil)
+ data := templateData(nil, nil)
t, err := templates.ParseTemplate("", cmd)
if err != nil {
log.Warnf("template parsing failed: %v", err)
@@ -231,7 +229,7 @@ func GetTemplateCompletion(
// GetCompletions returns the completion options and the command prefix
func (cmds *Commands) GetCompletions(
- aerc *app.Aerc, cmd string,
+ cmd string,
) (options []string, prefix string) {
log.Tracef("completing command: %s", cmd)
@@ -254,7 +252,7 @@ func (cmds *Commands) GetCompletions(
for _, n := range cmds.Names() {
options = append(options, n+" ")
}
- options = CompletionFromList(aerc, options, args)
+ options = CompletionFromList(options, args)
return
}
@@ -305,13 +303,13 @@ func (cmds *Commands) GetCompletions(
}
s := parser.flag
r := rune(s[len(s)-1])
- for _, option := range cmpl.CompleteOption(aerc, r, parser.arg) {
+ for _, option := range cmpl.CompleteOption(r, parser.arg) {
options = append(options, pad+escape(option)+" ")
}
prefix = stem
case OPERAND:
stem := strings.Join(args[:parser.optind], " ")
- for _, option := range c.Complete(aerc, args[1:]) {
+ for _, option := range c.Complete(args[1:]) {
if strings.Contains(option, " ") {
option = escape(option)
}
@@ -323,8 +321,8 @@ func (cmds *Commands) GetCompletions(
return
}
-func GetFolders(aerc *app.Aerc, args []string) []string {
- acct := aerc.SelectedAccount()
+func GetFolders(args []string) []string {
+ acct := app.SelectedAccount()
if acct == nil {
return make([]string, 0)
}
@@ -336,15 +334,15 @@ func GetFolders(aerc *app.Aerc, args []string) []string {
// CompletionFromList provides a convenience wrapper for commands to use in the
// Complete function. It simply matches the items provided in valid
-func CompletionFromList(aerc *app.Aerc, valid []string, args []string) []string {
+func CompletionFromList(valid []string, args []string) []string {
if len(args) == 0 {
return valid
}
- return FilterList(valid, args[0], "", aerc.SelectedAccountUiConfig().FuzzyComplete)
+ return FilterList(valid, args[0], "", app.SelectedAccountUiConfig().FuzzyComplete)
}
-func GetLabels(aerc *app.Aerc, args []string) []string {
- acct := aerc.SelectedAccount()
+func GetLabels(args []string) []string {
+ acct := app.SelectedAccount()
if acct == nil {
return make([]string, 0)
}
diff --git a/commands/completion_helpers.go b/commands/completion_helpers.go
index c7cb780b..e4556594 100644
--- a/commands/completion_helpers.go
+++ b/commands/completion_helpers.go
@@ -12,10 +12,10 @@ import (
)
// GetAddress uses the address-book-cmd for address completion
-func GetAddress(aerc *app.Aerc, search string) []string {
+func GetAddress(search string) []string {
var options []string
- cmd := aerc.SelectedAccount().AccountConfig().AddressBookCmd
+ cmd := app.SelectedAccount().AccountConfig().AddressBookCmd
if cmd == "" {
cmd = config.Compose.AddressBookCmd
if cmd == "" {
@@ -24,7 +24,7 @@ func GetAddress(aerc *app.Aerc, search string) []string {
}
cmpl := completer.New(cmd, func(err error) {
- aerc.PushError(
+ app.PushError(
fmt.Sprintf("could not complete header: %v", err))
log.Warnf("could not complete header: %v", err)
})
diff --git a/commands/compose/abort.go b/commands/compose/abort.go
index d6ceae6d..a11c06c5 100644
--- a/commands/compose/abort.go
+++ b/commands/compose/abort.go
@@ -16,17 +16,17 @@ func (Abort) Aliases() []string {
return []string{"abort"}
}
-func (Abort) Complete(aerc *app.Aerc, args []string) []string {
+func (Abort) Complete(args []string) []string {
return nil
}
-func (Abort) Execute(aerc *app.Aerc, args []string) error {
+func (Abort) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: abort")
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
- aerc.RemoveTab(composer, true)
+ app.RemoveTab(composer, true)
return nil
}
diff --git a/commands/compose/attach-key.go b/commands/compose/attach-key.go
index 29237374..74e05bb7 100644
--- a/commands/compose/attach-key.go
+++ b/commands/compose/attach-key.go
@@ -16,16 +16,16 @@ func (AttachKey) Aliases() []string {
return []string{"attach-key"}
}
-func (AttachKey) Complete(aerc *app.Aerc, args []string) []string {
+func (AttachKey) Complete(args []string) []string {
return nil
}
-func (AttachKey) Execute(aerc *app.Aerc, args []string) error {
+func (AttachKey) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: attach-key")
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
return composer.SetAttachKey(!composer.AttachKey())
}
diff --git a/commands/compose/attach.go b/commands/compose/attach.go
index fd84b4ea..fb533941 100644
--- a/commands/compose/attach.go
+++ b/commands/compose/attach.go
@@ -32,12 +32,12 @@ func (Attach) Aliases() []string {
return []string{"attach"}
}
-func (Attach) Complete(aerc *app.Aerc, args []string) []string {
+func (Attach) Complete(args []string) []string {
path := strings.Join(args, " ")
return commands.CompletePath(path)
}
-func (a Attach) Execute(aerc *app.Aerc, args []string) error {
+func (a Attach) Execute(args []string) error {
var (
menu bool
read bool
@@ -66,23 +66,23 @@ func (a Attach) Execute(aerc *app.Aerc, args []string) error {
args = args[optind:]
if menu {
- return a.openMenu(aerc, args)
+ return a.openMenu(args)
}
if read {
if len(args) < 2 {
return fmt.Errorf("Usage: :attach -r <name> <cmd> [args...]")
}
- return a.readCommand(aerc, args[0], args[1:])
+ return a.readCommand(args[0], args[1:])
}
if len(args) == 0 {
return fmt.Errorf("Usage: :attach <path>")
}
- return a.addPath(aerc, strings.Join(args, " "))
+ return a.addPath(strings.Join(args, " "))
}
-func (a Attach) addPath(aerc *app.Aerc, path string) error {
+func (a Attach) addPath(path string) error {
path = xdg.ExpandHome(path)
attachments, err := filepath.Glob(path)
if err != nil && errors.Is(err, filepath.ErrBadPattern) {
@@ -103,17 +103,17 @@ func (a Attach) addPath(aerc *app.Aerc, path string) error {
}
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
for _, attach := range attachments {
log.Debugf("attaching '%s'", attach)
pathinfo, err := os.Stat(attach)
if err != nil {
log.Errorf("failed to stat file: %v", err)
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return err
} else if pathinfo.IsDir() && len(attachments) == 1 {
- aerc.PushError("Attachment must be a file, not a directory")
+ app.PushError("Attachment must be a file, not a directory")
return nil
}
@@ -121,15 +121,15 @@ func (a Attach) addPath(aerc *app.Aerc, path string) error {
}
if len(attachments) == 1 {
- aerc.PushSuccess(fmt.Sprintf("Attached %s", path))
+ app.PushSuccess(fmt.Sprintf("Attached %s", path))
} else {
- aerc.PushSuccess(fmt.Sprintf("Attached %d files", len(attachments)))
+ app.PushSuccess(fmt.Sprintf("Attached %d files", len(attachments)))
}
return nil
}
-func (a Attach) openMenu(aerc *app.Aerc, args []string) error {
+func (a Attach) openMenu(args []string) error {
filePickerCmd := config.Compose.FilePickerCmd
if filePickerCmd == "" {
return fmt.Errorf("no file-picker-cmd defined")
@@ -172,7 +172,7 @@ func (a Attach) openMenu(aerc *app.Aerc, args []string) error {
}
}()
- aerc.CloseDialog()
+ app.CloseDialog()
if err != nil {
log.Errorf("terminal closed with error: %v", err)
@@ -192,7 +192,7 @@ func (a Attach) openMenu(aerc *app.Aerc, args []string) error {
continue
}
log.Tracef("File picker attaches: %v", f)
- err := a.addPath(aerc, f)
+ err := a.addPath(f)
if err != nil {
log.Errorf("attach failed for file %s: %v", f, err)
}
@@ -200,8 +200,8 @@ func (a Attach) openMenu(aerc *app.Aerc, args []string) error {
}
}
- aerc.AddDialog(app.NewDialog(
- ui.NewBox(t, "File Picker", "", aerc.SelectedAccountUiConfig()),
+ app.AddDialog(app.NewDialog(
+ ui.NewBox(t, "File Picker", "", app.SelectedAccountUiConfig()),
// start pos on screen
func(h int) int {
return h / 8
@@ -215,7 +215,7 @@ func (a Attach) openMenu(aerc *app.Aerc, args []string) error {
return nil
}
-func (a Attach) readCommand(aerc *app.Aerc, name string, args []string) error {
+func (a Attach) readCommand(name string, args []string) error {
args = append([]string{"-c"}, args...)
cmd := exec.Command("sh", args...)
@@ -233,13 +233,13 @@ func (a Attach) readCommand(aerc *app.Aerc, name string, args []string) error {
mimeParams["name"] = name
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
err = composer.AddPartAttachment(name, mimeType, mimeParams, reader)
if err != nil {
return errors.Wrap(err, "AddPartAttachment")
}
- aerc.PushSuccess(fmt.Sprintf("Attached %s", name))
+ app.PushSuccess(fmt.Sprintf("Attached %s", name))
return nil
}
diff --git a/commands/compose/cc-bcc.go b/commands/compose/cc-bcc.go
index 8f8d4aac..e1f94c1e 100644
--- a/commands/compose/cc-bcc.go
+++ b/commands/compose/cc-bcc.go
@@ -16,16 +16,16 @@ func (CC) Aliases() []string {
return []string{"cc", "bcc"}
}
-func (CC) Complete(aerc *app.Aerc, args []string) []string {
+func (CC) Complete(args []string) []string {
return nil
}
-func (CC) Execute(aerc *app.Aerc, args []string) error {
+func (CC) Execute(args []string) error {
var addrs string
if len(args) > 1 {
addrs = strings.Join(args[1:], " ")
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
switch args[0] {
case "cc":
diff --git a/commands/compose/detach.go b/commands/compose/detach.go
index 014301f2..4847713f 100644
--- a/commands/compose/detach.go
+++ b/commands/compose/detach.go
@@ -17,14 +17,14 @@ func (Detach) Aliases() []string {
return []string{"detach"}
}
-func (Detach) Complete(aerc *app.Aerc, args []string) []string {
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+func (Detach) Complete(args []string) []string {
+ composer, _ := app.SelectedTabContent().(*app.Composer)
return composer.GetAttachments()
}
-func (Detach) Execute(aerc *app.Aerc, args []string) error {
+func (Detach) Execute(args []string) error {
var path string
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
if len(args) > 1 {
path = strings.Join(args[1:], " ")
@@ -42,7 +42,7 @@ func (Detach) Execute(aerc *app.Aerc, args []string) error {
return err
}
- aerc.PushSuccess(fmt.Sprintf("Detached %s", path))
+ app.PushSuccess(fmt.Sprintf("Detached %s", path))
return nil
}
diff --git a/commands/compose/edit.go b/commands/compose/edit.go
index 485b3098..2948e964 100644
--- a/commands/compose/edit.go
+++ b/commands/compose/edit.go
@@ -18,12 +18,12 @@ func (Edit) Aliases() []string {
return []string{"edit"}
}
-func (Edit) Complete(aerc *app.Aerc, args []string) []string {
+func (Edit) Complete(args []string) []string {
return nil
}
-func (Edit) Execute(aerc *app.Aerc, args []string) error {
- composer, ok := aerc.SelectedTabContent().(*app.Composer)
+func (Edit) Execute(args []string) error {
+ composer, ok := app.SelectedTabContent().(*app.Composer)
if !ok {
return errors.New("only valid while composing")
}
diff --git a/commands/compose/encrypt.go b/commands/compose/encrypt.go
index 3c852dc4..b9094c5e 100644
--- a/commands/compose/encrypt.go
+++ b/commands/compose/encrypt.go
@@ -16,16 +16,16 @@ func (Encrypt) Aliases() []string {
return []string{"encrypt"}
}
-func (Encrypt) Complete(aerc *app.Aerc, args []string) []string {
+func (Encrypt) Complete(args []string) []string {
return nil
}
-func (Encrypt) Execute(aerc *app.Aerc, args []string) error {
+func (Encrypt) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: encrypt")
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
composer.SetEncrypt(!composer.Encrypt())
return nil
diff --git a/commands/compose/header.go b/commands/compose/header.go
index e66df149..5c13fde5 100644
--- a/commands/compose/header.go
+++ b/commands/compose/header.go
@@ -33,11 +33,11 @@ func (Header) Options() string {
return "fd"
}
-func (Header) Complete(aerc *app.Aerc, args []string) []string {
- return commands.CompletionFromList(aerc, headers, args)
+func (Header) Complete(args []string) []string {
+ return commands.CompletionFromList(headers, args)
}
-func (h Header) Execute(aerc *app.Aerc, args []string) error {
+func (h Header) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, h.Options())
args = args[optind:]
if err == nil && len(args) < 1 {
@@ -58,7 +58,7 @@ func (h Header) Execute(aerc *app.Aerc, args []string) error {
}
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
name := strings.TrimRight(args[0], ":")
diff --git a/commands/compose/multipart.go b/commands/compose/multipart.go
index 13ee69e5..0ad1dc4d 100644
--- a/commands/compose/multipart.go
+++ b/commands/compose/multipart.go
@@ -20,17 +20,17 @@ func (Multipart) Aliases() []string {
return []string{"multipart"}
}
-func (Multipart) Complete(aerc *app.Aerc, args []string) []string {
+func (Multipart) Complete(args []string) []string {
var completions []string
completions = append(completions, "-d")
for mime := range config.Converters {
completions = append(completions, mime)
}
- return commands.CompletionFromList(aerc, completions, args)
+ return commands.CompletionFromList(completions, args)
}
-func (a Multipart) Execute(aerc *app.Aerc, args []string) error {
- composer, ok := aerc.SelectedTabContent().(*app.Composer)
+func (a Multipart) Execute(args []string) error {
+ composer, ok := app.SelectedTabContent().(*app.Composer)
if !ok {
return fmt.Errorf(":multipart is only available on the compose::review screen")
}
diff --git a/commands/compose/next-field.go b/commands/compose/next-field.go
index d029b50a..be5f8e53 100644
--- a/commands/compose/next-field.go
+++ b/commands/compose/next-field.go
@@ -16,15 +16,15 @@ func (NextPrevField) Aliases() []string {
return []string{"next-field", "prev-field"}
}
-func (NextPrevField) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevField) Complete(args []string) []string {
return nil
}
-func (NextPrevField) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevField) Execute(args []string) error {
if len(args) > 2 {
return nextPrevFieldUsage(args[0])
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
if args[0] == "prev-field" {
composer.PrevField()
} else {
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index e33c9ab7..ac16d904 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -29,29 +29,29 @@ func (Postpone) Options() string {
return "t:"
}
-func (Postpone) CompleteOption(aerc *app.Aerc, r rune, arg string) []string {
+func (Postpone) CompleteOption(r rune, arg string) []string {
var valid []string
if r == 't' {
- valid = commands.GetFolders(aerc, []string{arg})
+ valid = commands.GetFolders([]string{arg})
}
- return commands.CompletionFromList(aerc, valid, []string{arg})
+ return commands.CompletionFromList(valid, []string{arg})
}
-func (Postpone) Complete(aerc *app.Aerc, args []string) []string {
+func (Postpone) Complete(args []string) []string {
return nil
}
-func (p Postpone) Execute(aerc *app.Aerc, args []string) error {
+func (p Postpone) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, p.Options())
if err != nil {
return err
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
- tab := aerc.SelectedTab()
+ tab := app.SelectedTab()
if tab == nil {
return errors.New("No tab selected")
}
@@ -104,17 +104,17 @@ func (p Postpone) Execute(aerc *app.Aerc, args []string) error {
errStr := <-errChan
if errStr != "" {
- aerc.PushError(errStr)
+ app.PushError(errStr)
return
}
handleErr := func(err error) {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
log.Errorf("Postponing failed: %v", err)
- aerc.NewTab(composer, tabName)
+ app.NewTab(composer, tabName)
}
- aerc.RemoveTab(composer, false)
+ app.RemoveTab(composer, false)
buf := &bytes.Buffer{}
err = composer.WriteMessage(header, buf)
@@ -131,7 +131,7 @@ func (p Postpone) Execute(aerc *app.Aerc, args []string) error {
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Message postponed.", 10*time.Second)
+ app.PushStatus("Message postponed.", 10*time.Second)
composer.SetPostponed()
composer.Close()
case *types.Error:
diff --git a/commands/compose/send.go b/commands/compose/send.go
index c9b843a7..6e104529 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -36,11 +36,11 @@ func (Send) Aliases() []string {
return []string{"send"}
}
-func (Send) Complete(aerc *app.Aerc, args []string) []string {
+func (Send) Complete(args []string) []string {
return nil
}
-func (Send) Execute(aerc *app.Aerc, args []string) error {
+func (Send) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, "a:")
if err != nil {
return err
@@ -54,7 +54,7 @@ func (Send) Execute(aerc *app.Aerc, args []string) error {
archive = opt.Value
}
}
- tab := aerc.SelectedTab()
+ tab := app.SelectedTab()
if tab == nil {
return errors.New("No selected tab")
}
@@ -129,7 +129,7 @@ func (Send) Execute(aerc *app.Aerc, args []string) error {
msg+" Abort send? [Y/n] ",
func(text string) {
if text == "n" || text == "N" {
- send(aerc, composer, ctx, header, tabName, archive)
+ send(composer, ctx, header, tabName, archive)
}
}, func(cmd string) ([]string, string) {
if cmd == "" {
@@ -140,21 +140,21 @@ func (Send) Execute(aerc *app.Aerc, args []string) error {
},
)
- aerc.PushPrompt(prompt)
+ app.PushPrompt(prompt)
} else {
- send(aerc, composer, ctx, header, tabName, archive)
+ send(composer, ctx, header, tabName, archive)
}
return nil
}
-func send(aerc *app.Aerc, composer *app.Composer, ctx sendCtx,
+func send(composer *app.Composer, ctx sendCtx,
header *mail.Header, tabName string, archive string,
) {
// we don't want to block the UI thread while we are sending
// so we do everything in a goroutine and hide the composer from the user
- aerc.RemoveTab(composer, false)
- aerc.PushStatus("Sending...", 10*time.Second)
+ app.RemoveTab(composer, false)
+ app.PushStatus("Sending...", 10*time.Second)
log.Debugf("send uri: %s", ctx.uri.String())
// enter no-quit mode
@@ -211,12 +211,12 @@ func send(aerc *app.Aerc, composer *app.Composer, ctx sendCtx,
err := <-failCh
if err != nil {
- aerc.PushError(strings.ReplaceAll(err.Error(), "\n", " "))
- aerc.NewTab(composer, tabName)
+ app.PushError(strings.ReplaceAll(err.Error(), "\n", " "))
+ app.NewTab(composer, tabName)
return
}
if config.CopyTo != "" && ctx.scheme != "jmap" {
- aerc.PushStatus("Copying to "+config.CopyTo, 10*time.Second)
+ app.PushStatus("Copying to "+config.CopyTo, 10*time.Second)
errch := copyToSent(composer.Worker(), config.CopyTo,
copyBuf.Len(), &copyBuf)
err = <-errch
@@ -224,13 +224,13 @@ func send(aerc *app.Aerc, composer *app.Composer, ctx sendCtx,
errmsg := fmt.Sprintf(
"message sent, but copying to %v failed: %v",
config.CopyTo, err.Error())
- aerc.PushError(errmsg)
+ app.PushError(errmsg)
composer.SetSent(archive)
composer.Close()
return
}
}
- aerc.PushStatus("Message sent.", 10*time.Second)
+ app.PushStatus("Message sent.", 10*time.Second)
composer.SetSent(archive)
composer.Close()
}()
diff --git a/commands/compose/sign.go b/commands/compose/sign.go
index f44c33ec..ae7c3417 100644
--- a/commands/compose/sign.go
+++ b/commands/compose/sign.go
@@ -17,16 +17,16 @@ func (Sign) Aliases() []string {
return []string{"sign"}
}
-func (Sign) Complete(aerc *app.Aerc, args []string) []string {
+func (Sign) Complete(args []string) []string {
return nil
}
-func (Sign) Execute(aerc *app.Aerc, args []string) error {
+func (Sign) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: sign")
}
- composer, _ := aerc.SelectedTabContent().(*app.Composer)
+ composer, _ := app.SelectedTabContent().(*app.Composer)
err := composer.SetSign(!composer.Sign())
if err != nil {
@@ -41,7 +41,7 @@ func (Sign) Execute(aerc *app.Aerc, args []string) error {
statusline = "Message will not be signed."
}
- aerc.PushStatus(statusline, 10*time.Second)
+ app.PushStatus(statusline, 10*time.Second)
return nil
}
diff --git a/commands/compose/switch.go b/commands/compose/switch.go
index f442d6b0..1cc388f1 100644
--- a/commands/compose/switch.go
+++ b/commands/compose/switch.go
@@ -22,11 +22,11 @@ func (SwitchAccount) Aliases() []string {
return []string{"switch-account"}
}
-func (SwitchAccount) Complete(aerc *app.Aerc, args []string) []string {
- return aerc.AccountNames()
+func (SwitchAccount) Complete(args []string) []string {
+ return app.AccountNames()
}
-func (SwitchAccount) Execute(aerc *app.Aerc, args []string) error {
+func (SwitchAccount) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, "np")
if err != nil {
return err
@@ -46,13 +46,13 @@ func (SwitchAccount) Execute(aerc *app.Aerc, args []string) error {
// NOT ((prev || next) XOR (len(posargs) == 1))
if (prev || next) == (len(posargs) == 1) {
name := ""
- if acct := aerc.SelectedAccount(); acct != nil {
+ if acct := app.SelectedAccount(); acct != nil {
name = fmt.Sprintf("Current account: %s. ", acct.Name())
}
return errors.New(name + "Usage: switch-account [-np] <account-name>")
}
- switcher, ok := aerc.SelectedTabContent().(AccountSwitcher)
+ switcher, ok := app.SelectedTabContent().(AccountSwitcher)
if !ok {
return errors.New("this tab cannot switch accounts")
}
@@ -61,11 +61,11 @@ func (SwitchAccount) Execute(aerc *app.Aerc, args []string) error {
switch {
case prev:
- acct, err = aerc.PrevAccount()
+ acct, err = app.PrevAccount()
case next:
- acct, err = aerc.NextAccount()
+ acct, err = app.NextAccount()
default:
- acct, err = aerc.Account(posargs[0])
+ acct, err = app.Account(posargs[0])
}
if err != nil {
return err
diff --git a/commands/ct.go b/commands/ct.go
index e6b29b58..1b5659c7 100644
--- a/commands/ct.go
+++ b/commands/ct.go
@@ -19,21 +19,21 @@ func (ChangeTab) Aliases() []string {
return []string{"ct", "change-tab"}
}
-func (ChangeTab) Complete(aerc *app.Aerc, args []string) []string {
+func (ChangeTab) Complete(args []string) []string {
if len(args) == 0 {
- return aerc.TabNames()
+ return app.TabNames()
}
joinedArgs := strings.Join(args, " ")
- return FilterList(aerc.TabNames(), joinedArgs, "", aerc.SelectedAccountUiConfig().FuzzyComplete)
+ return FilterList(app.TabNames(), joinedArgs, "", app.SelectedAccountUiConfig().FuzzyComplete)
}
-func (ChangeTab) Execute(aerc *app.Aerc, args []string) error {
+func (ChangeTab) Execute(args []string) error {
if len(args) == 1 {
return fmt.Errorf("Usage: %s <tab>", args[0])
}
joinedArgs := strings.Join(args[1:], " ")
if joinedArgs == "-" {
- ok := aerc.SelectPreviousTab()
+ ok := app.SelectPreviousTab()
if !ok {
return errors.New("No previous tab to return to")
}
@@ -43,21 +43,21 @@ func (ChangeTab) Execute(aerc *app.Aerc, args []string) error {
switch {
case strings.HasPrefix(joinedArgs, "+"):
for ; n > 0; n-- {
- aerc.NextTab()
+ app.NextTab()
}
case strings.HasPrefix(joinedArgs, "-"):
for ; n < 0; n++ {
- aerc.PrevTab()
+ app.PrevTab()
}
default:
- ok := aerc.SelectTabIndex(n)
+ ok := app.SelectTabIndex(n)
if !ok {
return errors.New(
"No tab with that index")
}
}
} else {
- ok := aerc.SelectTab(joinedArgs)
+ ok := app.SelectTab(joinedArgs)
if !ok {
return errors.New("No tab with that name")
}
diff --git a/commands/eml.go b/commands/eml.go
index 81e578d3..e03792ef 100644
--- a/commands/eml.go
+++ b/commands/eml.go
@@ -21,12 +21,12 @@ func (Eml) Aliases() []string {
return []string{"eml", "preview"}
}
-func (Eml) Complete(aerc *app.Aerc, args []string) []string {
+func (Eml) Complete(args []string) []string {
return CompletePath(strings.Join(args, " "))
}
-func (Eml) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (Eml) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return fmt.Errorf("no account selected")
}
@@ -34,23 +34,23 @@ func (Eml) Execute(aerc *app.Aerc, args []string) error {
showEml := func(r io.Reader) {
data, err := io.ReadAll(r)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
- lib.NewEmlMessageView(data, aerc.Crypto, aerc.DecryptKeys,
+ lib.NewEmlMessageView(data, app.CryptoProvider(), app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
msgView := app.NewMessageViewer(acct, view)
- aerc.NewTab(msgView,
+ app.NewTab(msgView,
view.MessageInfo().Envelope.Subject)
})
}
if len(args) == 1 {
- switch tab := aerc.SelectedTabContent().(type) {
+ switch tab := app.SelectedTabContent().(type) {
case *app.MessageViewer:
part := tab.SelectedMessagePart()
tab.MessageView().FetchBodyPart(part.Index, showEml)
diff --git a/commands/exec.go b/commands/exec.go
index a38c8789..a34f54e7 100644
--- a/commands/exec.go
+++ b/commands/exec.go
@@ -21,11 +21,11 @@ func (ExecCmd) Aliases() []string {
return []string{"exec"}
}
-func (ExecCmd) Complete(aerc *app.Aerc, args []string) []string {
+func (ExecCmd) Complete(args []string) []string {
return nil
}
-func (ExecCmd) Execute(aerc *app.Aerc, args []string) error {
+func (ExecCmd) Execute(args []string) error {
if len(args) < 2 {
return errors.New("Usage: exec [cmd...]")
}
@@ -33,7 +33,7 @@ func (ExecCmd) Execute(aerc *app.Aerc, args []string) error {
cmd := exec.Command(args[1], args[2:]...)
env := os.Environ()
- switch view := aerc.SelectedTabContent().(type) {
+ switch view := app.SelectedTabContent().(type) {
case *app.AccountView:
env = append(env, fmt.Sprintf("account=%s", view.AccountConfig().Name))
env = append(env, fmt.Sprintf("folder=%s", view.Directories().Selected()))
@@ -50,14 +50,14 @@ func (ExecCmd) Execute(aerc *app.Aerc, args []string) error {
err := cmd.Run()
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
} else {
if cmd.ProcessState.ExitCode() != 0 {
- aerc.PushError(fmt.Sprintf(
+ app.PushError(fmt.Sprintf(
"%s: completed with status %d", args[0],
cmd.ProcessState.ExitCode()))
} else {
- aerc.PushStatus(fmt.Sprintf(
+ app.PushStatus(fmt.Sprintf(
"%s: completed with status %d", args[0],
cmd.ProcessState.ExitCode()), 10*time.Second)
}
diff --git a/commands/help.go b/commands/help.go
index 312c3318..5cc0aacc 100644
--- a/commands/help.go
+++ b/commands/help.go
@@ -33,11 +33,11 @@ func (Help) Aliases() []string {
return []string{"help"}
}
-func (Help) Complete(aerc *app.Aerc, args []string) []string {
- return CompletionFromList(aerc, pages, args)
+func (Help) Complete(args []string) []string {
+ return CompletionFromList(pages, args)
}
-func (Help) Execute(aerc *app.Aerc, args []string) error {
+func (Help) Execute(args []string) error {
page := "aerc"
if len(args) == 2 && args[1] != "aerc" {
page = "aerc-" + args[1]
@@ -46,14 +46,14 @@ func (Help) Execute(aerc *app.Aerc, args []string) error {
}
if page == "aerc-keys" {
- aerc.AddDialog(app.NewDialog(
+ app.AddDialog(app.NewDialog(
app.NewListBox(
"Bindings: Press <Esc> or <Enter> to close. "+
"Start typing to filter bindings.",
- aerc.HumanReadableBindings(),
- aerc.SelectedAccountUiConfig(),
+ app.HumanReadableBindings(),
+ app.SelectedAccountUiConfig(),
func(_ string) {
- aerc.CloseDialog()
+ app.CloseDialog()
},
),
func(h int) int { return h / 4 },
@@ -62,5 +62,5 @@ func (Help) Execute(aerc *app.Aerc, args []string) error {
return nil
}
- return TermCore(aerc, []string{"term", "man", page})
+ return TermCore([]string{"term", "man", page})
}
diff --git a/commands/move-tab.go b/commands/move-tab.go
index d85f3b2f..1aa20880 100644
--- a/commands/move-tab.go
+++ b/commands/move-tab.go
@@ -18,11 +18,11 @@ func (MoveTab) Aliases() []string {
return []string{"move-tab"}
}
-func (MoveTab) Complete(aerc *app.Aerc, args []string) []string {
+func (MoveTab) Complete(args []string) []string {
return nil
}
-func (MoveTab) Execute(aerc *app.Aerc, args []string) error {
+func (MoveTab) Execute(args []string) error {
if len(args) == 1 {
return fmt.Errorf("Usage: %s [+|-]<index>", args[0])
}
@@ -38,7 +38,7 @@ func (MoveTab) Execute(aerc *app.Aerc, args []string) error {
if strings.HasPrefix(joinedArgs, "+") || strings.HasPrefix(joinedArgs, "-") {
relative = true
}
- aerc.MoveTab(n, relative)
+ app.MoveTab(n, relative)
return nil
}
diff --git a/commands/msg/archive.go b/commands/msg/archive.go
index 9753f664..f326d0c6 100644
--- a/commands/msg/archive.go
+++ b/commands/msg/archive.go
@@ -29,26 +29,26 @@ func (Archive) Aliases() []string {
return []string{"archive"}
}
-func (Archive) Complete(aerc *app.Aerc, args []string) []string {
+func (Archive) Complete(args []string) []string {
valid := []string{"flat", "year", "month"}
- return commands.CompletionFromList(aerc, valid, args)
+ return commands.CompletionFromList(valid, args)
}
-func (Archive) Execute(aerc *app.Aerc, args []string) error {
+func (Archive) Execute(args []string) error {
if len(args) != 2 {
return errors.New("Usage: archive <flat|year|month>")
}
- h := newHelper(aerc)
+ h := newHelper()
msgs, err := h.messages()
if err != nil {
return err
}
- err = archive(aerc, msgs, args[1])
+ err = archive(msgs, args[1])
return err
}
-func archive(aerc *app.Aerc, msgs []*models.MessageInfo, archiveType string) error {
- h := newHelper(aerc)
+func archive(msgs []*models.MessageInfo, archiveType string) error {
+ h := newHelper()
acct, err := h.account()
if err != nil {
return err
@@ -74,7 +74,7 @@ func archive(aerc *app.Aerc, msgs []*models.MessageInfo, archiveType string) err
archiveDir,
fmt.Sprintf("%d", msg.Envelope.Date.Year()),
fmt.Sprintf("%02d", msg.Envelope.Date.Month()),
- }, aerc.SelectedAccount().Worker().PathSeparator(),
+ }, app.SelectedAccount().Worker().PathSeparator(),
)
return dir
})
@@ -83,7 +83,7 @@ func archive(aerc *app.Aerc, msgs []*models.MessageInfo, archiveType string) err
dir := strings.Join([]string{
archiveDir,
fmt.Sprintf("%v", msg.Envelope.Date.Year()),
- }, aerc.SelectedAccount().Worker().PathSeparator(),
+ }, app.SelectedAccount().Worker().PathSeparator(),
)
return dir
})
@@ -104,7 +104,7 @@ func archive(aerc *app.Aerc, msgs []*models.MessageInfo, archiveType string) err
case *types.Done:
wg.Done()
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
success = false
wg.Done()
marker.Remark()
@@ -117,7 +117,7 @@ func archive(aerc *app.Aerc, msgs []*models.MessageInfo, archiveType string) err
wg.Wait()
if success {
- handleDone(aerc, acct, next, "Messages archived.", store)
+ handleDone(acct, next, "Messages archived.", store)
}
}()
return nil
diff --git a/commands/msg/copy.go b/commands/msg/copy.go
index 3f3498a2..1a902772 100644
--- a/commands/msg/copy.go
+++ b/commands/msg/copy.go
@@ -22,11 +22,11 @@ func (Copy) Aliases() []string {
return []string{"cp", "copy"}
}
-func (Copy) Complete(aerc *app.Aerc, args []string) []string {
- return commands.GetFolders(aerc, args)
+func (Copy) Complete(args []string) []string {
+ return commands.GetFolders(args)
}
-func (Copy) Execute(aerc *app.Aerc, args []string) error {
+func (Copy) Execute(args []string) error {
if len(args) == 1 {
return errors.New("Usage: cp [-p] <folder>")
}
@@ -40,7 +40,7 @@ func (Copy) Execute(aerc *app.Aerc, args []string) error {
createParents = true
}
}
- h := newHelper(aerc)
+ h := newHelper()
uids, err := h.markedOrSelectedUids()
if err != nil {
return err
@@ -55,10 +55,10 @@ func (Copy) Execute(aerc *app.Aerc, args []string) error {
) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Messages copied.", 10*time.Second)
+ app.PushStatus("Messages copied.", 10*time.Second)
store.Marker().ClearVisualMark()
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
return nil
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index 37103da3..107c8a3f 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -22,16 +22,16 @@ func (Delete) Aliases() []string {
return []string{"delete", "delete-message"}
}
-func (Delete) Complete(aerc *app.Aerc, args []string) []string {
+func (Delete) Complete(args []string) []string {
return nil
}
-func (Delete) Execute(aerc *app.Aerc, args []string) error {
+func (Delete) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: :delete")
}
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
return err
@@ -52,28 +52,28 @@ func (Delete) Execute(aerc *app.Aerc, args []string) error {
store.Delete(uids, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Messages deleted.", 10*time.Second)
+ app.PushStatus("Messages deleted.", 10*time.Second)
mv, isMsgView := h.msgProvider.(*app.MessageViewer)
if isMsgView {
if !config.Ui.NextMessageOnDelete {
- aerc.RemoveTab(h.msgProvider, true)
+ app.RemoveTab(h.msgProvider, true)
} else {
// no more messages in the list
if next == nil {
- aerc.RemoveTab(h.msgProvider, true)
+ app.RemoveTab(h.msgProvider, true)
acct.Messages().Select(-1)
ui.Invalidate()
return
}
lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(),
- store, aerc.Crypto, aerc.DecryptKeys,
+ store, app.CryptoProvider(), app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
nextMv := app.NewMessageViewer(acct, view)
- aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
+ app.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
})
}
} else {
@@ -86,12 +86,12 @@ func (Delete) Execute(aerc *app.Aerc, args []string) error {
case *types.Error:
marker.Remark()
store.Select(sel.Uid)
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
case *types.Unsupported:
marker.Remark()
store.Select(sel.Uid)
// notmuch doesn't support it, we want the user to know
- aerc.PushError(" error, unsupported for this worker")
+ app.PushError(" error, unsupported for this worker")
}
})
return nil
diff --git a/commands/msg/envelope.go b/commands/msg/envelope.go
index f5e50358..3a388c12 100644
--- a/commands/msg/envelope.go
+++ b/commands/msg/envelope.go
@@ -23,11 +23,11 @@ func (Envelope) Aliases() []string {
return []string{"envelope"}
}
-func (Envelope) Complete(aerc *app.Aerc, args []string) []string {
+func (Envelope) Complete(args []string) []string {
return nil
}
-func (Envelope) Execute(aerc *app.Aerc, args []string) error {
+func (Envelope) Execute(args []string) error {
header := false
fmtStr := "%-20.20s: %s"
opts, _, err := getopt.Getopts(args, "hs:")
@@ -43,7 +43,7 @@ func (Envelope) Execute(aerc *app.Aerc, args []string) error {
}
}
- acct := aerc.SelectedAccount()
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
@@ -65,14 +65,14 @@ func (Envelope) Execute(aerc *app.Aerc, args []string) error {
}
n := len(list)
- aerc.AddDialog(app.NewDialog(
+ app.AddDialog(app.NewDialog(
app.NewListBox(
"Message Envelope. Press <Esc> or <Enter> to close. "+
"Start typing to filter.",
list,
- aerc.SelectedAccountUiConfig(),
+ app.SelectedAccountUiConfig(),
func(_ string) {
- aerc.CloseDialog()
+ app.CloseDialog()
},
),
// start pos on screen
diff --git a/commands/msg/fold.go b/commands/msg/fold.go
index 755a292f..1d40b90a 100644
--- a/commands/msg/fold.go
+++ b/commands/msg/fold.go
@@ -5,7 +5,6 @@ import (
"fmt"
"strings"
- "git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
@@ -19,15 +18,15 @@ func (Fold) Aliases() []string {
return []string{"fold", "unfold"}
}
-func (Fold) Complete(aerc *app.Aerc, args []string) []string {
+func (Fold) Complete(args []string) []string {
return nil
}
-func (Fold) Execute(aerc *app.Aerc, args []string) error {
+func (Fold) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("Usage: %s", args[0])
}
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
return err
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index d1abbc5b..68f162cc 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -34,11 +34,11 @@ func (forward) Aliases() []string {
return []string{"forward"}
}
-func (forward) Complete(aerc *app.Aerc, args []string) []string {
+func (forward) Complete(args []string) []string {
return nil
}
-func (forward) Execute(aerc *app.Aerc, args []string) error {
+func (forward) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, "AFT:eE")
if err != nil {
return err
@@ -69,7 +69,7 @@ func (forward) Execute(aerc *app.Aerc, args []string) error {
return errors.New("Options -A and -F are mutually exclusive")
}
- widget := aerc.SelectedTabContent().(app.ProvidesMessage)
+ widget := app.SelectedTabContent().(app.ProvidesMessage)
acct := widget.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
@@ -107,15 +107,15 @@ func (forward) Execute(aerc *app.Aerc, args []string) error {
}
addTab := func() (*app.Composer, error) {
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
template, h, &original, nil)
if err != nil {
- aerc.PushError("Error: " + err.Error())
+ app.PushError("Error: " + err.Error())
return nil, err
}
- composer.Tab = aerc.NewTab(composer, subject)
+ composer.Tab = app.NewTab(composer, subject)
if !h.Has("to") {
composer.FocusEditor("to")
} else {
@@ -210,7 +210,7 @@ func (forward) Execute(aerc *app.Aerc, args []string) error {
mu.Unlock()
if err != nil {
log.Errorf(err.Error())
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
}
})
}
diff --git a/commands/msg/invite.go b/commands/msg/invite.go
index ceb043bb..76864f9a 100644
--- a/commands/msg/invite.go
+++ b/commands/msg/invite.go
@@ -26,12 +26,12 @@ func (invite) Aliases() []string {
return []string{"accept", "accept-tentative", "decline"}
}
-func (invite) Complete(aerc *app.Aerc, args []string) []string {
+func (invite) Complete(args []string) []string {
return nil
}
-func (invite) Execute(aerc *app.Aerc, args []string) error {
- acct := aerc.SelectedAccount()
+func (invite) Execute(args []string) error {
+ acct := app.SelectedAccount()
if acct == nil {
return errors.New("no account selected")
}
@@ -128,7 +128,7 @@ func (invite) Execute(aerc *app.Aerc, args []string) error {
h.SetMsgIDList("in-reply-to", []string{msg.Envelope.MessageId})
err = setReferencesHeader(h, msg.RFC822Headers)
if err != nil {
- aerc.PushError(fmt.Sprintf("could not set references: %v", err))
+ app.PushError(fmt.Sprintf("could not set references: %v", err))
}
original := models.OriginalMail{
From: format.FormatAddresses(msg.Envelope.From),
@@ -155,11 +155,11 @@ func (invite) Execute(aerc *app.Aerc, args []string) error {
}
addTab := func(cr *calendar.Reply) error {
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
"", h, &original, cr.PlainText)
if err != nil {
- aerc.PushError("Error: " + err.Error())
+ app.PushError("Error: " + err.Error())
return err
}
err = composer.AppendPart(cr.MimeType, cr.Params, cr.CalendarText)
@@ -168,7 +168,7 @@ func (invite) Execute(aerc *app.Aerc, args []string) error {
}
composer.FocusTerminal()
- composer.Tab = aerc.NewTab(composer, subject)
+ composer.Tab = app.NewTab(composer, subject)
composer.OnClose(func(c *app.Composer) {
if c.Sent() {
@@ -181,7 +181,7 @@ func (invite) Execute(aerc *app.Aerc, args []string) error {
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
if cr, err := handleInvite(reader); err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
} else {
err := addTab(cr)
diff --git a/commands/msg/mark.go b/commands/msg/mark.go
index 27677609..eeaa5485 100644
--- a/commands/msg/mark.go
+++ b/commands/msg/mark.go
@@ -3,7 +3,6 @@ package msg
import (
"fmt"
- "git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -17,12 +16,12 @@ func (Mark) Aliases() []string {
return []string{"mark", "unmark", "remark"}
}
-func (Mark) Complete(aerc *app.Aerc, args []string) []string {
+func (Mark) Complete(args []string) []string {
return nil
}
-func (Mark) Execute(aerc *app.Aerc, args []string) error {
- h := newHelper(aerc)
+func (Mark) Execute(args []string) error {
+ h := newHelper()
OnSelectedMessage := func(fn func(uint32)) error {
if fn == nil {
return fmt.Errorf("no operation selected")
diff --git a/commands/msg/modify-labels.go b/commands/msg/modify-labels.go
index d61dc23b..d219a57e 100644
--- a/commands/msg/modify-labels.go
+++ b/commands/msg/modify-labels.go
@@ -19,17 +19,17 @@ func (ModifyLabels) Aliases() []string {
return []string{"modify-labels", "tag"}
}
-func (ModifyLabels) Complete(aerc *app.Aerc, args []string) []string {
- return commands.GetLabels(aerc, args)
+func (ModifyLabels) Complete(args []string) []string {
+ return commands.GetLabels(args)
}
-func (ModifyLabels) Execute(aerc *app.Aerc, args []string) error {
+func (ModifyLabels) Execute(args []string) error {
changes := args[1:]
if len(changes) == 0 {
return errors.New("Usage: modify-labels <[+-]label> ...")
}
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
return err
@@ -56,10 +56,10 @@ func (ModifyLabels) Execute(aerc *app.Aerc, args []string) error {
) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("labels updated", 10*time.Second)
+ app.PushStatus("labels updated", 10*time.Second)
store.Marker().ClearVisualMark()
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
return nil
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 847fa549..5ef9390a 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -25,11 +25,11 @@ func (Move) Aliases() []string {
return []string{"mv", "move"}
}
-func (Move) Complete(aerc *app.Aerc, args []string) []string {
- return commands.GetFolders(aerc, args)
+func (Move) Complete(args []string) []string {
+ return commands.GetFolders(args)
}
-func (Move) Execute(aerc *app.Aerc, args []string) error {
+func (Move) Execute(args []string) error {
if len(args) == 1 {
return errors.New("Usage: mv [-p] <folder>")
}
@@ -44,7 +44,7 @@ func (Move) Execute(aerc *app.Aerc, args []string) error {
}
}
- h := newHelper(aerc)
+ h := newHelper()
acct, err := h.account()
if err != nil {
return err
@@ -71,9 +71,9 @@ func (Move) Execute(aerc *app.Aerc, args []string) error {
) {
switch msg := msg.(type) {
case *types.Done:
- handleDone(aerc, acct, next, "Messages moved to "+joinedArgs, store)
+ handleDone(acct, next, "Messages moved to "+joinedArgs, store)
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
marker.Remark()
}
})
@@ -82,34 +82,33 @@ func (Move) Execute(aerc *app.Aerc, args []string) error {
}
func handleDone(
- aerc *app.Aerc,
acct *app.AccountView,
next *models.MessageInfo,
message string,
store *lib.MessageStore,
) {
- h := newHelper(aerc)
- aerc.PushStatus(message, 10*time.Second)
+ h := newHelper()
+ app.PushStatus(message, 10*time.Second)
mv, isMsgView := h.msgProvider.(*app.MessageViewer)
switch {
case isMsgView && !config.Ui.NextMessageOnDelete:
- aerc.RemoveTab(h.msgProvider, true)
+ app.RemoveTab(h.msgProvider, true)
case isMsgView:
if next == nil {
- aerc.RemoveTab(h.msgProvider, true)
+ app.RemoveTab(h.msgProvider, true)
acct.Messages().Select(-1)
ui.Invalidate()
return
}
lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(),
- store, aerc.Crypto, aerc.DecryptKeys,
+ store, app.CryptoProvider(), app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
nextMv := app.NewMessageViewer(acct, view)
- aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
+ app.ReplaceTab(mv, nextMv, next.Envelope.Subject, true)
})
default:
if next == nil {
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index e8c1e277..c9d88f40 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -28,11 +28,11 @@ func (Pipe) Aliases() []string {
return []string{"pipe"}
}
-func (Pipe) Complete(aerc *app.Aerc, args []string) []string {
+func (Pipe) Complete(args []string) []string {
return nil
}
-func (Pipe) Execute(aerc *app.Aerc, args []string) error {
+func (Pipe) Execute(args []string) error {
var (
background bool
pipeFull bool
@@ -64,7 +64,7 @@ func (Pipe) Execute(aerc *app.Aerc, args []string) error {
return errors.New("Usage: pipe [-mp] <cmd> [args...]")
}
- provider := aerc.SelectedTabContent().(app.ProvidesMessage)
+ provider := app.SelectedTabContent().(app.ProvidesMessage)
if !pipeFull && !pipePart {
if _, ok := provider.(*app.MessageViewer); ok {
pipePart = true
@@ -77,12 +77,12 @@ func (Pipe) Execute(aerc *app.Aerc, args []string) error {
}
doTerm := func(reader io.Reader, name string) {
- term, err := commands.QuickTerm(aerc, cmd, reader)
+ term, err := commands.QuickTerm(cmd, reader)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
- aerc.NewTab(term, name)
+ app.NewTab(term, name)
}
doExec := func(reader io.Reader) {
@@ -102,14 +102,14 @@ func (Pipe) Execute(aerc *app.Aerc, args []string) error {
}()
err = ecmd.Run()
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
} else {
if ecmd.ProcessState.ExitCode() != 0 {
- aerc.PushError(fmt.Sprintf(
+ app.PushError(fmt.Sprintf(
"%s: completed with status %d", cmd[0],
ecmd.ProcessState.ExitCode()))
} else {
- aerc.PushStatus(fmt.Sprintf(
+ app.PushStatus(fmt.Sprintf(
"%s: completed with status %d", cmd[0],
ecmd.ProcessState.ExitCode()), 10*time.Second)
}
@@ -120,7 +120,7 @@ func (Pipe) Execute(aerc *app.Aerc, args []string) error {
var uids []uint32
var title string
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
if mv, ok := provider.(*app.MessageViewer); ok {
@@ -174,7 +174,7 @@ func (Pipe) Execute(aerc *app.Aerc, args []string) error {
case <-time.After(30 * time.Second):
// TODO: find a better way to determine if store.FetchFull()
// has finished with some errors.
- aerc.PushError("Failed to fetch all messages")
+ app.PushError("Failed to fetch all messages")
if len(messages) == 0 {
return
}
diff --git a/commands/msg/read.go b/commands/msg/read.go
index 10a874e3..bac2ceb3 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -21,7 +21,7 @@ func (FlagMsg) Aliases() []string {
return []string{"flag", "unflag", "read", "unread"}
}
-func (FlagMsg) Complete(aerc *app.Aerc, args []string) []string {
+func (FlagMsg) Complete(args []string) []string {
return nil
}
@@ -32,7 +32,7 @@ func (FlagMsg) Complete(aerc *app.Aerc, args []string) []string {
//
// If this was called as 'read' or 'unread', it has the same effect as
// 'flag' or 'unflag', respectively, but the 'Seen' flag is affected.
-func (FlagMsg) Execute(aerc *app.Aerc, args []string) error {
+func (FlagMsg) Execute(args []string) error {
// The flag to change
var flag models.Flags
// User-readable name of the flag to change
@@ -112,7 +112,7 @@ func (FlagMsg) Execute(aerc *app.Aerc, args []string) error {
return fmt.Errorf(helpMessage)
}
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
return err
@@ -152,10 +152,10 @@ func (FlagMsg) Execute(aerc *app.Aerc, args []string) error {
store.Flag(toEnable, flag, true, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
+ app.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
store.Marker().ClearVisualMark()
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
}
@@ -163,10 +163,10 @@ func (FlagMsg) Execute(aerc *app.Aerc, args []string) error {
store.Flag(toDisable, flag, false, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
+ app.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
store.Marker().ClearVisualMark()
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
}
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 4a08df29..2d999b1d 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -28,11 +28,11 @@ func (Recall) Aliases() []string {
return []string{"recall"}
}
-func (Recall) Complete(aerc *app.Aerc, args []string) []string {
+func (Recall) Complete(args []string) []string {
return nil
}
-func (Recall) Execute(aerc *app.Aerc, args []string) error {
+func (Recall) Execute(args []string) error {
force := false
editHeaders := config.Compose.EditHeaders
@@ -54,7 +54,7 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
return errors.New("Usage: recall [-f] [-e|-E]")
}
- widget := aerc.SelectedTabContent().(app.ProvidesMessage)
+ widget := app.SelectedTabContent().(app.ProvidesMessage)
acct := widget.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
@@ -79,7 +79,7 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
if subject == "" {
subject = "Recalled email"
}
- composer.Tab = aerc.NewTab(composer, subject)
+ composer.Tab = app.NewTab(composer, subject)
composer.OnClose(func(composer *app.Composer) {
worker := composer.Worker()
uids := []uint32{msgInfo.Uid}
@@ -90,9 +90,9 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
- aerc.PushStatus("Recalled message deleted", 10*time.Second)
+ app.PushStatus("Recalled message deleted", 10*time.Second)
case *types.Error:
- aerc.PushError(msg.Error.Error())
+ app.PushError(msg.Error.Error())
}
})
}
@@ -104,10 +104,10 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
}
lib.NewMessageStoreView(msgInfo, acct.UiConfig().AutoMarkRead,
- store, aerc.Crypto, aerc.DecryptKeys,
+ store, app.CryptoProvider(), app.DecryptKeys,
func(msg lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
var path []int
@@ -116,11 +116,11 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
}
msg.FetchBodyPart(path, func(reader io.Reader) {
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
"", msgInfo.RFC822Headers, nil, reader)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
if md := msg.MessageDetails(); md != nil {
@@ -159,7 +159,7 @@ func (Recall) Execute(aerc *app.Aerc, args []string) error {
mu.Unlock()
if err != nil {
log.Errorf(err.Error())
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
}
})
}
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 035e6aa3..b9ee050a 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -33,11 +33,11 @@ func (reply) Aliases() []string {
return []string{"reply"}
}
-func (reply) Complete(aerc *app.Aerc, args []string) []string {
+func (reply) Complete(args []string) []string {
return nil
}
-func (reply) Execute(aerc *app.Aerc, args []string) error {
+func (reply) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, "acqT:eE")
if err != nil {
return err
@@ -69,7 +69,7 @@ func (reply) Execute(aerc *app.Aerc, args []string) error {
}
}
- widget := aerc.SelectedTabContent().(app.ProvidesMessage)
+ widget := app.SelectedTabContent().(app.ProvidesMessage)
acct := widget.SelectedAccount()
if acct == nil {
@@ -169,7 +169,7 @@ func (reply) Execute(aerc *app.Aerc, args []string) error {
h.SetMsgIDList("in-reply-to", []string{msg.Envelope.MessageId})
err = setReferencesHeader(h, msg.RFC822Headers)
if err != nil {
- aerc.PushError(fmt.Sprintf("could not set references: %v", err))
+ app.PushError(fmt.Sprintf("could not set references: %v", err))
}
original := models.OriginalMail{
From: format.FormatAddresses(msg.Envelope.From),
@@ -177,38 +177,38 @@ func (reply) Execute(aerc *app.Aerc, args []string) error {
RFC822Headers: msg.RFC822Headers,
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
addTab := func() error {
- composer, err := app.NewComposer(aerc, acct,
+ composer, err := app.NewComposer(acct,
acct.AccountConfig(), acct.Worker(), editHeaders,
template, h, &original, nil)
if err != nil {
- aerc.PushError("Error: " + err.Error())
+ app.PushError("Error: " + err.Error())
return err
}
if mv != nil && closeOnReply {
- aerc.RemoveTab(mv, true)
+ app.RemoveTab(mv, true)
}
if args[0] == "reply" {
composer.FocusTerminal()
}
- composer.Tab = aerc.NewTab(composer, subject)
+ composer.Tab = app.NewTab(composer, subject)
composer.OnClose(func(c *app.Composer) {
switch {
case c.Sent() && c.Archive() != "":
store.Answered([]uint32{msg.Uid}, true, nil)
- err := archive(aerc, []*models.MessageInfo{msg}, c.Archive())
+ err := archive([]*models.MessageInfo{msg}, c.Archive())
if err != nil {
- aerc.PushStatus("Archive failed", 10*time.Second)
+ app.PushStatus("Archive failed", 10*time.Second)
}
case c.Sent():
store.Answered([]uint32{msg.Uid}, true, nil)
case mv != nil && closeOnReply:
//nolint:errcheck // who cares?
- account.ViewMessage{}.Execute(aerc, []string{"-p"})
+ account.ViewMessage{}.Execute([]string{"-p"})
}
})
@@ -221,7 +221,7 @@ func (reply) Execute(aerc *app.Aerc, args []string) error {
}
if crypto.IsEncrypted(msg.BodyStructure) {
- provider := aerc.SelectedTabContent().(app.ProvidesMessage)
+ provider := app.SelectedTabContent().(app.ProvidesMessage)
mv, ok := provider.(*app.MessageViewer)
if !ok {
return fmt.Errorf("message is encrypted. can only quote reply while message is open")
diff --git a/commands/msg/toggle-thread-context.go b/commands/msg/toggle-thread-context.go
index 6f8b7bbb..7530bc9e 100644
--- a/commands/msg/toggle-thread-context.go
+++ b/commands/msg/toggle-thread-context.go
@@ -3,7 +3,6 @@ package msg
import (
"errors"
- "git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
@@ -17,15 +16,15 @@ func (ToggleThreadContext) Aliases() []string {
return []string{"toggle-thread-context"}
}
-func (ToggleThreadContext) Complete(aerc *app.Aerc, args []string) []string {
+func (ToggleThreadContext) Complete(args []string) []string {
return nil
}
-func (ToggleThreadContext) Execute(aerc *app.Aerc, args []string) error {
+func (ToggleThreadContext) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: toggle-entire-thread")
}
- h := newHelper(aerc)
+ h := newHelper()
store, err := h.store()
if err != nil {
return err
diff --git a/commands/msg/toggle-threads.go b/commands/msg/toggle-threads.go
index 0b85e510..1d38685a 100644
--- a/commands/msg/toggle-threads.go
+++ b/commands/msg/toggle-threads.go
@@ -3,7 +3,6 @@ package msg
import (
"errors"
- "git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
@@ -18,15 +17,15 @@ func (ToggleThreads) Aliases() []string {
return []string{"toggle-threads"}
}
-func (ToggleThreads) Complete(aerc *app.Aerc, args []string) []string {
+func (ToggleThreads) Complete(args []string) []string {
return nil
}
-func (ToggleThreads) Execute(aerc *app.Aerc, args []string) error {
+func (ToggleThreads) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: toggle-threads")
}
- h := newHelper(aerc)
+ h := newHelper()
acct, err := h.account()
if err != nil {
return err
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 23029244..069aedab 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -30,12 +30,12 @@ func (Unsubscribe) Aliases() []string {
}
// Complete returns a list of completions
-func (Unsubscribe) Complete(aerc *app.Aerc, args []string) []string {
+func (Unsubscribe) Complete(args []string) []string {
return nil
}
// Execute runs the Unsubscribe command
-func (Unsubscribe) Execute(aerc *app.Aerc, args []string) error {
+func (Unsubscribe) Execute(args []string) error {
editHeaders := config.Compose.EditHeaders
opts, optind, err := getopt.Getopts(args, "eE")
if err != nil {
@@ -52,7 +52,7 @@ func (Unsubscribe) Execute(aerc *app.Aerc, args []string) error {
editHeaders = false
}
}
- widget := aerc.SelectedTabContent().(app.ProvidesMessage)
+ widget := app.SelectedTabContent().(app.ProvidesMessage)
msg, err := widget.SelectedMessage()
if err != nil {
return err
@@ -76,14 +76,14 @@ func (Unsubscribe) Execute(aerc *app.Aerc, args []string) error {
var err error
switch strings.ToLower(method.Scheme) {
case "mailto":
- err = unsubscribeMailto(aerc, method, editHeaders)
+ err = unsubscribeMailto(method, editHeaders)
case "http", "https":
- err = unsubscribeHTTP(aerc, method)
+ err = unsubscribeHTTP(method)
default:
err = fmt.Errorf("unsubscribe: skipping unrecognized scheme: %s", method.Scheme)
}
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
}
}
@@ -100,15 +100,15 @@ func (Unsubscribe) Execute(aerc *app.Aerc, args []string) error {
dialog := app.NewSelectorDialog(
title,
"Press <Enter> to confirm or <ESC> to cancel",
- options, 0, aerc.SelectedAccountUiConfig(),
+ options, 0, app.SelectedAccountUiConfig(),
func(option string, err error) {
- aerc.CloseDialog()
+ app.CloseDialog()
if err != nil {
if errors.Is(err, app.ErrNoOptionSelected) {
- aerc.PushStatus("Unsubscribe: "+err.Error(),
+ app.PushStatus("Unsubscribe: "+err.Error(),
5*time.Second)
} else {
- aerc.PushError("Unsubscribe: " + err.Error())
+ app.PushError("Unsubscribe: " + err.Error())
}
return
}
@@ -118,10 +118,10 @@ func (Unsubscribe) Execute(aerc *app.Aerc, args []string) error {
return
}
}
- aerc.PushError("Unsubscribe: selected method not found")
+ app.PushError("Unsubscribe: selected method not found")
},
)
- aerc.AddDialog(dialog)
+ app.AddDialog(dialog)
return nil
}
@@ -148,8 +148,8 @@ func parseUnsubscribeMethods(header string) (methods []*url.URL) {
}
}
-func unsubscribeMailto(aerc *app.Aerc, u *url.URL, editHeaders bool) error {
- widget := aerc.SelectedTabContent().(app.ProvidesMessage)
+func unsubscribeMailto(u *url.URL, editHeaders bool) error {
+ widget := app.SelectedTabContent().(app.ProvidesMessage)
acct := widget.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
@@ -162,7 +162,7 @@ func unsubscribeMailto(aerc *app.Aerc, u *url.URL, editHeaders bool) error {
}
composer, err := app.NewComposer(
- aerc,
+
acct,
acct.AccountConfig(),
acct.Worker(),
@@ -175,32 +175,32 @@ func unsubscribeMailto(aerc *app.Aerc, u *url.URL, editHeaders bool) error {
if err != nil {
return err
}
- composer.Tab = aerc.NewTab(composer, "unsubscribe")
+ composer.Tab = app.NewTab(composer, "unsubscribe")
composer.FocusTerminal()
return nil
}
-func unsubscribeHTTP(aerc *app.Aerc, u *url.URL) error {
+func unsubscribeHTTP(u *url.URL) error {
confirm := app.NewSelectorDialog(
"Do you want to open this link?",
u.String(),
- []string{"No", "Yes"}, 0, aerc.SelectedAccountUiConfig(),
+ []string{"No", "Yes"}, 0, app.SelectedAccountUiConfig(),
func(option string, _ error) {
- aerc.CloseDialog()
+ app.CloseDialog()
switch option {
case "Yes":
go func() {
defer log.PanicHandler()
mime := fmt.Sprintf("x-scheme-handler/%s", u.Scheme)
if err := lib.XDGOpenMime(u.String(), mime, nil); err != nil {
- aerc.PushError("Unsubscribe:" + err.Error())
+ app.PushError("Unsubscribe:" + err.Error())
}
}()
default:
- aerc.PushError("Unsubscribe: link will not be opened")
+ app.PushError("Unsubscribe: link will not be opened")
}
},
)
- aerc.AddDialog(confirm)
+ app.AddDialog(confirm)
return nil
}
diff --git a/commands/msg/utils.go b/commands/msg/utils.go
index 423be37d..42693348 100644
--- a/commands/msg/utils.go
+++ b/commands/msg/utils.go
@@ -15,15 +15,15 @@ type helper struct {
statusInfo func(string)
}
-func newHelper(aerc *app.Aerc) *helper {
- msgProvider, ok := aerc.SelectedTabContent().(app.ProvidesMessages)
+func newHelper() *helper {
+ msgProvider, ok := app.SelectedTabContent().(app.ProvidesMessages)
if !ok {
- msgProvider = aerc.SelectedAccount()
+ msgProvider = app.SelectedAccount()
}
return &helper{
msgProvider: msgProvider,
statusInfo: func(s string) {
- aerc.PushStatus(s, 10*time.Second)
+ app.PushStatus(s, 10*time.Second)
},
}
}
diff --git a/commands/msgview/close.go b/commands/msgview/close.go
index 428dc51f..e0ad6040 100644
--- a/commands/msgview/close.go
+++ b/commands/msgview/close.go
@@ -16,15 +16,15 @@ func (Close) Aliases() []string {
return []string{"close"}
}
-func (Close) Complete(aerc *app.Aerc, args []string) []string {
+func (Close) Complete(args []string) []string {
return nil
}
-func (Close) Execute(aerc *app.Aerc, args []string) error {
+func (Close) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: close")
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
- aerc.RemoveTab(mv, true)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
+ app.RemoveTab(mv, true)
return nil
}
diff --git a/commands/msgview/next-part.go b/commands/msgview/next-part.go
index 6f314991..951842d7 100644
--- a/commands/msgview/next-part.go
+++ b/commands/msgview/next-part.go
@@ -17,11 +17,11 @@ func (NextPrevPart) Aliases() []string {
return []string{"next-part", "prev-part"}
}
-func (NextPrevPart) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevPart) Complete(args []string) []string {
return nil
}
-func (NextPrevPart) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevPart) Execute(args []string) error {
if len(args) > 2 {
return nextPrevPartUsage(args[0])
}
@@ -35,7 +35,7 @@ func (NextPrevPart) Execute(aerc *app.Aerc, args []string) error {
return nextPrevPartUsage(args[0])
}
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
for ; n > 0; n-- {
if args[0] == "prev-part" {
mv.PreviousPart()
diff --git a/commands/msgview/next.go b/commands/msgview/next.go
index e647cc0d..a69cb8ee 100644
--- a/commands/msgview/next.go
+++ b/commands/msgview/next.go
@@ -21,16 +21,16 @@ func (NextPrevMsg) Aliases() []string {
return []string{"next", "next-message", "prev", "prev-message"}
}
-func (NextPrevMsg) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevMsg) Complete(args []string) []string {
return nil
}
-func (NextPrevMsg) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevMsg) Execute(args []string) error {
n, pct, err := account.ParseNextPrevMessage(args)
if err != nil {
return err
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
acct := mv.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
@@ -45,14 +45,14 @@ func (NextPrevMsg) Execute(aerc *app.Aerc, args []string) error {
}
executeNextPrev := func(nextMsg *models.MessageInfo) {
lib.NewMessageStoreView(nextMsg, mv.MessageView().SeenFlagSet(),
- store, aerc.Crypto, aerc.DecryptKeys,
+ store, app.CryptoProvider(), app.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
nextMv := app.NewMessageViewer(acct, view)
- aerc.ReplaceTab(mv, nextMv,
+ app.ReplaceTab(mv, nextMv,
nextMsg.Envelope.Subject, true)
})
}
diff --git a/commands/msgview/open-link.go b/commands/msgview/open-link.go
index 4052e3a6..7241fb40 100644
--- a/commands/msgview/open-link.go
+++ b/commands/msgview/open-link.go
@@ -21,17 +21,17 @@ func (OpenLink) Aliases() []string {
return []string{"open-link"}
}
-func (OpenLink) Complete(aerc *app.Aerc, args []string) []string {
- mv := aerc.SelectedTabContent().(*app.MessageViewer)
+func (OpenLink) Complete(args []string) []string {
+ mv := app.SelectedTabContent().(*app.MessageViewer)
if mv != nil {
if p := mv.SelectedMessagePart(); p != nil {
- return commands.CompletionFromList(aerc, p.Links, args)
+ return commands.CompletionFromList(p.Links, args)
}
}
return nil
}
-func (OpenLink) Execute(aerc *app.Aerc, args []string) error {
+func (OpenLink) Execute(args []string) error {
if len(args) < 2 {
return errors.New("Usage: open-link <url> [program [args...]]")
}
@@ -43,7 +43,7 @@ func (OpenLink) Execute(aerc *app.Aerc, args []string) error {
go func() {
defer log.PanicHandler()
if err := lib.XDGOpenMime(args[1], mime, args[2:]); err != nil {
- aerc.PushError("open-link: " + err.Error())
+ app.PushError("open-link: " + err.Error())
}
}()
return nil
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 1f74bc7a..6c806c7c 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -28,11 +28,11 @@ func (Open) Aliases() []string {
return []string{"open"}
}
-func (Open) Complete(aerc *app.Aerc, args []string) []string {
+func (Open) Complete(args []string) []string {
return nil
}
-func (o Open) Execute(aerc *app.Aerc, args []string) error {
+func (o Open) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, o.Options())
if err != nil {
return err
@@ -46,7 +46,7 @@ func (o Open) Execute(aerc *app.Aerc, args []string) error {
}
}
- mv := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv := app.SelectedTabContent().(*app.MessageViewer)
if mv == nil {
return errors.New("open only supported selected message parts")
}
@@ -71,14 +71,14 @@ func (o Open) Execute(aerc *app.Aerc, args []string) error {
tmpFile, err := os.CreateTemp(os.TempDir(), "aerc-*"+extension)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
_, err = io.Copy(tmpFile, reader)
tmpFile.Close()
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
return
}
@@ -89,7 +89,7 @@ func (o Open) Execute(aerc *app.Aerc, args []string) error {
}
err = lib.XDGOpenMime(tmpFile.Name(), mimeType, args[optind:])
if err != nil {
- aerc.PushError("open: " + err.Error())
+ app.PushError("open: " + err.Error())
}
}()
})
diff --git a/commands/msgview/save.go b/commands/msgview/save.go
index 4d914e3e..c8e00e4f 100644
--- a/commands/msgview/save.go
+++ b/commands/msgview/save.go
@@ -33,7 +33,7 @@ func (Save) Aliases() []string {
return []string{"save"}
}
-func (s Save) Complete(aerc *app.Aerc, args []string) []string {
+func (s Save) Complete(args []string) []string {
trimmed := commands.Operands(args, s.Options())
path := strings.Join(trimmed, " ")
defaultPath := config.General.DefaultSavePath
@@ -51,7 +51,7 @@ type saveParams struct {
allAttachments bool
}
-func (s Save) Execute(aerc *app.Aerc, args []string) error {
+func (s Save) Execute(args []string) error {
opts, optind, err := getopt.Getopts(args, s.Options())
if err != nil {
return err
@@ -100,7 +100,7 @@ func (s Save) Execute(aerc *app.Aerc, args []string) error {
path = xdg.ExpandHome(path)
- mv, ok := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, ok := app.SelectedTabContent().(*app.MessageViewer)
if !ok {
return fmt.Errorf("SelectedTabContent is not a MessageViewer")
}
@@ -113,7 +113,7 @@ func (s Save) Execute(aerc *app.Aerc, args []string) error {
params.trailingSlash = true
names := make(map[string]struct{})
for _, pi := range parts {
- if err := savePart(pi, path, mv, aerc, &params, names); err != nil {
+ if err := savePart(pi, path, mv, &params, names); err != nil {
return err
}
}
@@ -121,14 +121,13 @@ func (s Save) Execute(aerc *app.Aerc, args []string) error {
}
pi := mv.SelectedMessagePart()
- return savePart(pi, path, mv, aerc, &params, make(map[string]struct{}))
+ return savePart(pi, path, mv, &params, make(map[string]struct{}))
}
func savePart(
pi *app.PartInfo,
path string,
mv *app.MessageViewer,
- aerc *app.Aerc,
params *saveParams,
names map[string]struct{},
) error {
@@ -174,10 +173,10 @@ func savePart(
err := <-ch
if err != nil {
- aerc.PushError(fmt.Sprintf("Save failed: %v", err))
+ app.PushError(fmt.Sprintf("Save failed: %v", err))
return
}
- aerc.PushStatus("Saved to "+path, 10*time.Second)
+ app.PushStatus("Saved to "+path, 10*time.Second)
}()
return nil
}
diff --git a/commands/msgview/toggle-headers.go b/commands/msgview/toggle-headers.go
index 0bb834a9..746692fd 100644
--- a/commands/msgview/toggle-headers.go
+++ b/commands/msgview/toggle-headers.go
@@ -16,15 +16,15 @@ func (ToggleHeaders) Aliases() []string {
return []string{"toggle-headers"}
}
-func (ToggleHeaders) Complete(aerc *app.Aerc, args []string) []string {
+func (ToggleHeaders) Complete(args []string) []string {
return nil
}
-func (ToggleHeaders) Execute(aerc *app.Aerc, args []string) error {
+func (ToggleHeaders) Execute(args []string) error {
if len(args) > 1 {
return toggleHeadersUsage(args[0])
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
mv.ToggleHeaders()
return nil
}
diff --git a/commands/msgview/toggle-key-passthrough.go b/commands/msgview/toggle-key-passthrough.go
index 7e24329a..1524b420 100644
--- a/commands/msgview/toggle-key-passthrough.go
+++ b/commands/msgview/toggle-key-passthrough.go
@@ -17,15 +17,15 @@ func (ToggleKeyPassthrough) Aliases() []string {
return []string{"toggle-key-passthrough"}
}
-func (ToggleKeyPassthrough) Complete(aerc *app.Aerc, args []string) []string {
+func (ToggleKeyPassthrough) Complete(args []string) []string {
return nil
}
-func (ToggleKeyPassthrough) Execute(aerc *app.Aerc, args []string) error {
+func (ToggleKeyPassthrough) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: toggle-key-passthrough")
}
- mv, _ := aerc.SelectedTabContent().(*app.MessageViewer)
+ mv, _ := app.SelectedTabContent().(*app.MessageViewer)
keyPassthroughEnabled := mv.ToggleKeyPassthrough()
if acct := mv.SelectedAccount(); acct != nil {
acct.SetStatus(state.Passthrough(keyPassthroughEnabled))
diff --git a/commands/new-account.go b/commands/new-account.go
index 3170c75c..0f84141f 100644
--- a/commands/new-account.go
+++ b/commands/new-account.go
@@ -17,22 +17,22 @@ func (NewAccount) Aliases() []string {
return []string{"new-account"}
}
-func (NewAccount) Complete(aerc *app.Aerc, args []string) []string {
+func (NewAccount) Complete(args []string) []string {
return nil
}
-func (NewAccount) Execute(aerc *app.Aerc, args []string) error {
+func (NewAccount) Execute(args []string) error {
opts, _, err := getopt.Getopts(args, "t")
if err != nil {
return errors.New("Usage: new-account [-t]")
}
- wizard := app.NewAccountWizard(aerc)
+ wizard := app.NewAccountWizard()
for _, opt := range opts {
if opt.Option == 't' {
wizard.ConfigureTemporaryAccount(true)
}
}
wizard.Focus(true)
- aerc.NewTab(wizard, "New account")
+ app.NewTab(wizard, "New account")
return nil
}
diff --git a/commands/next-tab.go b/commands/next-tab.go
index 247e7534..eb7b1ed1 100644
--- a/commands/next-tab.go
+++ b/commands/next-tab.go
@@ -17,11 +17,11 @@ func (NextPrevTab) Aliases() []string {
return []string{"next-tab", "prev-tab"}
}
-func (NextPrevTab) Complete(aerc *app.Aerc, args []string) []string {
+func (NextPrevTab) Complete(args []string) []string {
return nil
}
-func (NextPrevTab) Execute(aerc *app.Aerc, args []string) error {
+func (NextPrevTab) Execute(args []string) error {
if len(args) > 2 {
return nextPrevTabUsage(args[0])
}
@@ -37,12 +37,12 @@ func (NextPrevTab) Execute(aerc *app.Aerc, args []string) error {
}
for ; n > 0; n-- {
if args[0] == "prev-tab" {
- aerc.PrevTab()
+ app.PrevTab()
} else {
- aerc.NextTab()
+ app.NextTab()
}
}
- aerc.UpdateStatus()
+ app.UpdateStatus()
return nil
}
diff --git a/commands/pin-tab.go b/commands/pin-tab.go
index e2e897ed..7a3258d4 100644
--- a/commands/pin-tab.go
+++ b/commands/pin-tab.go
@@ -16,20 +16,20 @@ func (PinTab) Aliases() []string {
return []string{"pin-tab", "unpin-tab"}
}
-func (PinTab) Complete(aerc *app.Aerc, args []string) []string {
+func (PinTab) Complete(args []string) []string {
return nil
}
-func (PinTab) Execute(aerc *app.Aerc, args []string) error {
+func (PinTab) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("Usage: %s", args[0])
}
switch args[0] {
case "pin-tab":
- aerc.PinTab()
+ app.PinTab()
case "unpin-tab":
- aerc.UnpinTab()
+ app.UnpinTab()
}
return nil
diff --git a/commands/prompt.go b/commands/prompt.go
index d3a9411c..f9f5fcc0 100644
--- a/commands/prompt.go
+++ b/commands/prompt.go
@@ -17,7 +17,7 @@ func (Prompt) Aliases() []string {
return []string{"prompt"}
}
-func (Prompt) Complete(aerc *app.Aerc, args []string) []string {
+func (Prompt) Complete(args []string) []string {
argc := len(args)
if argc == 0 {
return nil
@@ -30,13 +30,13 @@ func (Prompt) Complete(aerc *app.Aerc, args []string) []string {
cmd := GlobalCommands.ByName(args[1])
var cs []string
if cmd != nil {
- cs = cmd.Complete(aerc, args[2:])
+ cs = cmd.Complete(args[2:])
hascommand = true
} else {
if hascommand {
return nil
}
- cs, _ = GlobalCommands.GetCompletions(aerc, args[1])
+ cs, _ = GlobalCommands.GetCompletions(args[1])
}
if cs == nil {
return nil
@@ -69,13 +69,13 @@ func (Prompt) Complete(aerc *app.Aerc, args []string) []string {
return rs
}
-func (Prompt) Execute(aerc *app.Aerc, args []string) error {
+func (Prompt) Execute(args []string) error {
if len(args) < 3 {
return fmt.Errorf("Usage: %s <prompt> <cmd>", args[0])
}
prompt := args[1]
cmd := args[2:]
- aerc.RegisterPrompt(prompt, cmd)
+ app.RegisterPrompt(prompt, cmd)
return nil
}
diff --git a/commands/pwd.go b/commands/pwd.go
index 9082a469..9b562313 100644
--- a/commands/pwd.go
+++ b/commands/pwd.go
@@ -18,11 +18,11 @@ func (PrintWorkDir) Aliases() []string {
return []string{"pwd"}
}
-func (PrintWorkDir) Complete(aerc *app.Aerc, args []string) []string {
+func (PrintWorkDir) Complete(args []string) []string {
return nil
}
-func (PrintWorkDir) Execute(aerc *app.Aerc, args []string) error {
+func (PrintWorkDir) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: pwd")
}
@@ -30,6 +30,6 @@ func (PrintWorkDir) Execute(aerc *app.Aerc, args []string) error {
if err != nil {
return err
}
- aerc.PushStatus(pwd, 10*time.Second)
+ app.PushStatus(pwd, 10*time.Second)
return nil
}
diff --git a/commands/quit.go b/commands/quit.go
index 73054f86..42e8fc95 100644
--- a/commands/quit.go
+++ b/commands/quit.go
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
- "git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands/mode"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -19,7 +18,7 @@ func (Quit) Aliases() []string {
return []string{"quit", "exit"}
}
-func (Quit) Complete(aerc *app.Aerc, args []string) []string {
+func (Quit) Complete(args []string) []string {
return nil
}
@@ -29,7 +28,7 @@ func (err ErrorExit) Error() string {
return "exit"
}
-func (Quit) Execute(aerc *app.Aerc, args []string) error {
+func (Quit) Execute(args []string) error {
force := false
opts, optind, err := getopt.Getopts(args, "f")
if err != nil {
diff --git a/commands/term.go b/commands/term.go
index c5fa5cbd..26e277db 100644
--- a/commands/term.go
+++ b/commands/term.go
@@ -19,12 +19,12 @@ func (Term) Aliases() []string {
return []string{"terminal", "term"}
}
-func (Term) Complete(aerc *app.Aerc, args []string) []string {
+func (Term) Complete(args []string) []string {
return nil
}
// The help command is an alias for `term man` thus Term requires a simple func
-func TermCore(aerc *app.Aerc, args []string) error {
+func TermCore(args []string) error {
if len(args) == 1 {
shell, err := loginshell.Shell()
if err != nil {
@@ -36,7 +36,7 @@ func TermCore(aerc *app.Aerc, args []string) error {
if err != nil {
return err
}
- tab := aerc.NewTab(term, args[1])
+ tab := app.NewTab(term, args[1])
term.OnTitle = func(title string) {
if title == "" {
title = args[1]
@@ -47,14 +47,14 @@ func TermCore(aerc *app.Aerc, args []string) error {
}
}
term.OnClose = func(err error) {
- aerc.RemoveTab(term, false)
+ app.RemoveTab(term, false)
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
}
}
return nil
}
-func (Term) Execute(aerc *app.Aerc, args []string) error {
- return TermCore(aerc, args)
+func (Term) Execute(args []string) error {
+ return TermCore(args)
}
diff --git a/commands/terminal/close.go b/commands/terminal/close.go
index 0f72292e..5d52bbc5 100644
--- a/commands/terminal/close.go
+++ b/commands/terminal/close.go
@@ -16,15 +16,15 @@ func (Close) Aliases() []string {
return []string{"close"}
}
-func (Close) Complete(aerc *app.Aerc, args []string) []string {
+func (Close) Complete(args []string) []string {
return nil
}
-func (Close) Execute(aerc *app.Aerc, args []string) error {
+func (Close) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Usage: close")
}
- term, _ := aerc.SelectedTabContent().(*app.Terminal)
+ term, _ := app.SelectedTabContent().(*app.Terminal)
term.Close()
return nil
}
diff --git a/commands/util.go b/commands/util.go
index fbb20433..e9a377a6 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -22,7 +22,7 @@ import (
)
// QuickTerm is an ephemeral terminal for running a single command and quitting.
-func QuickTerm(aerc *app.Aerc, args []string, stdin io.Reader) (*app.Terminal, error) {
+func QuickTerm(args []string, stdin io.Reader) (*app.Terminal, error) {
cmd := exec.Command(args[0], args[1:]...)
pipe, err := cmd.StdinPipe()
if err != nil {
@@ -36,14 +36,14 @@ func QuickTerm(aerc *app.Aerc, args []string, stdin io.Reader) (*app.Terminal, e
term.OnClose = func(err error) {
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
// remove the tab on error, otherwise it gets stuck
- aerc.RemoveTab(term, false)
+ app.RemoveTab(term, false)
} else {
- aerc.PushStatus("Process complete, press any key to close.",
+ app.PushStatus("Process complete, press any key to close.",
10*time.Second)
term.OnEvent = func(event tcell.Event) bool {
- aerc.RemoveTab(term, true)
+ app.RemoveTab(term, true)
return true
}
}
@@ -62,7 +62,7 @@ func QuickTerm(aerc *app.Aerc, args []string, stdin io.Reader) (*app.Terminal, e
err := <-status
if err != nil {
- aerc.PushError(err.Error())
+ app.PushError(err.Error())
}
}
diff --git a/commands/z.go b/commands/z.go
index aa903738..966e2ce9 100644
--- a/commands/z.go
+++ b/commands/z.go
@@ -5,8 +5,6 @@ import (
"os"
"os/exec"
"strings"
-
- "git.sr.ht/~rjarry/aerc/app"
)
type Zoxide struct{}
@@ -36,20 +34,20 @@ func (Zoxide) Aliases() []string {
return []string{"z"}
}
-func (Zoxide) Complete(aerc *app.Aerc, args []string) []string {
- return ChangeDirectory{}.Complete(aerc, args)
+func (Zoxide) Complete(args []string) []string {
+ return ChangeDirectory{}.Complete(args)
}
// Execute calls zoxide add and query and delegates actually changing the
// directory to ChangeDirectory
-func (Zoxide) Execute(aerc *app.Aerc, args []string) error {
+func (Zoxide) Execute(args []string) error {
if len(args) < 1 {
return errors.New("Usage: z [directory or zoxide query]")
}
target := strings.Join(args[1:], " ")
switch target {
case "":
- return ChangeDirectory{}.Execute(aerc, args)
+ return ChangeDirectory{}.Execute(args)
case "-":
if previousDir != "" {
err := ZoxideAdd(previousDir)
@@ -57,7 +55,7 @@ func (Zoxide) Execute(aerc *app.Aerc, args []string) error {
return err
}
}
- return ChangeDirectory{}.Execute(aerc, args)
+ return ChangeDirectory{}.Execute(args)
default:
_, err := os.Stat(target)
if err != nil {
@@ -70,7 +68,7 @@ func (Zoxide) Execute(aerc *app.Aerc, args []string) error {
if err != nil {
return err
}
- return ChangeDirectory{}.Execute(aerc, []string{"z", res})
+ return ChangeDirectory{}.Execute([]string{"z", res})
}
} else {
@@ -78,7 +76,7 @@ func (Zoxide) Execute(aerc *app.Aerc, args []string) error {
if err != nil {
return err
}
- return ChangeDirectory{}.Execute(aerc, args)
+ return ChangeDirectory{}.Execute(args)
}
}
diff --git a/main.go b/main.go
index 1210783f..8e449aea 100644
--- a/main.go
+++ b/main.go
@@ -104,13 +104,13 @@ func expandAbbreviations(cmd []string, sets []*commands.Commands) []string {
}
func execCommand(
- aerc *app.Aerc, ui *libui.UI, cmd []string,
+ ui *libui.UI, cmd []string,
acct *config.AccountConfig, msg *models.MessageInfo,
) error {
- cmds := getCommands(aerc.SelectedTabContent())
+ cmds := getCommands(app.SelectedTabContent())
cmd = expandAbbreviations(cmd, cmds)
for i, set := range cmds {
- err := set.ExecuteCommand(aerc, cmd, acct, msg)
+ err := set.ExecuteCommand(cmd, acct, msg)
if err != nil {
if errors.As(err, new(commands.NoSuchCommand)) {
if i == len(cmds)-1 {
@@ -129,14 +129,14 @@ func execCommand(
return nil
}
-func getCompletions(aerc *app.Aerc, cmd string) ([]string, string) {
- if options, prefix, ok := commands.GetTemplateCompletion(aerc, cmd); ok {
+func getCompletions(cmd string) ([]string, string) {
+ if options, prefix, ok := commands.GetTemplateCompletion(cmd); ok {
return options, prefix
}
var completions []string
var prefix string
- for _, set := range getCommands(aerc.SelectedTabContent()) {
- options, s := set.GetCompletions(aerc, cmd)
+ for _, set := range getCommands(app.SelectedTabContent()) {
+ options, s := set.GetCompletions(cmd)
if s != "" {
prefix = s
}
@@ -228,10 +228,7 @@ func main() {
log.Infof("Starting up version %s", log.BuildInfo)
- var (
- aerc *app.Aerc
- ui *libui.UI
- )
+ var ui *libui.UI
deferLoop := make(chan struct{})
@@ -242,16 +239,14 @@ func main() {
}
defer c.Close()
- aerc = app.NewAerc(c, func(
+ app.Init(c, func(
cmd []string, acct *config.AccountConfig,
msg *models.MessageInfo,
) error {
- return execCommand(aerc, ui, cmd, acct, msg)
- }, func(cmd string) ([]string, string) {
- return getCompletions(aerc, cmd)
- }, &commands.CmdHistory, deferLoop)
+ return execCommand(ui, cmd, acct, msg)
+ }, getCompletions, &commands.CmdHistory, deferLoop)
- ui, err = libui.Initialize(aerc)
+ ui, err = libui.Initialize(app.Drawable())
if err != nil {
panic(err)
}
@@ -265,7 +260,7 @@ func main() {
ui.EnableMouse()
}
- as, err := ipc.StartServer(aerc)
+ as, err := ipc.StartServer(app.IPCHandler())
if err != nil {
log.Warnf("Failed to start Unix server: %v", err)
} else {
@@ -280,7 +275,7 @@ func main() {
err := ipc.ConnectAndExec(args)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to communicate to aerc: %v\n", err)
- err = aerc.CloseBackends()
+ err = app.CloseBackends()
if err != nil {
log.Warnf("failed to close backends: %v", err)
}
@@ -297,7 +292,7 @@ func main() {
err := hooks.RunHook(&hooks.AercStartup{Version: Version})
if err != nil {
msg := fmt.Sprintf("aerc-startup hook: %s", err)
- aerc.PushError(msg)
+ app.PushError(msg)
}
}()
defer func(start time.Time) {
@@ -314,13 +309,13 @@ loop:
case event := <-ui.Events:
ui.HandleEvent(event)
case msg := <-types.WorkerMessages:
- aerc.HandleMessage(msg)
+ app.HandleMessage(msg)
case callback := <-libui.Callbacks:
callback()
case <-libui.Redraw:
ui.Render()
case <-ui.Quit:
- err = aerc.CloseBackends()
+ err = app.CloseBackends()
if err != nil {
log.Warnf("failed to close backends: %v", err)
}