aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-12 15:03:30 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:22:58 +0100
commitc05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch)
tree13a3a84eb74fdea77996161f01bec5596f67f39f /commands
parent9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff)
downloadaerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc widget. Everywhere we need to access configuration options, we need somehow to get a reference either to the Aerc widget or to a pointer to the AercConfig instance. This makes the code cluttered. Remove the AercConfig structure and every place where it is referenced. Instead, declare global variables for every configuration section and access them directly from the `config` module. Since bindings and ui sections can be "contextual" (i.e. per account, per folder or per subject), leave most local references intact. Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would make this patch even more unreadable. This is something that may be addressed in the future. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/compose.go5
-rw-r--r--commands/account/recover.go2
-rw-r--r--commands/account/view.go2
-rw-r--r--commands/compose/attach.go3
-rw-r--r--commands/compose/multipart.go5
-rw-r--r--commands/compose/send.go2
-rw-r--r--commands/eml.go3
-rw-r--r--commands/msg/delete.go5
-rw-r--r--commands/msg/forward.go5
-rw-r--r--commands/msg/invite.go5
-rw-r--r--commands/msg/move.go5
-rw-r--r--commands/msg/recall.go2
-rw-r--r--commands/msg/reply.go13
-rw-r--r--commands/msg/unsubscribe.go1
-rw-r--r--commands/msgview/next.go3
-rw-r--r--commands/msgview/open.go3
-rw-r--r--commands/msgview/save.go5
-rw-r--r--commands/new-account.go2
18 files changed, 38 insertions, 33 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go
index 3d3d9afb..fb37b231 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -10,6 +10,7 @@ import (
"github.com/emersion/go-message/mail"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
@@ -41,7 +42,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("No account selected")
}
if template == "" {
- template = aerc.Config().Templates.NewMessage
+ template = config.Templates.NewMessage
}
msg, err := gomail.ReadMessage(strings.NewReader(body))
@@ -53,7 +54,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
headers := mail.HeaderFromMap(msg.Header)
composer, err := widgets.NewComposer(aerc, acct,
- aerc.Config(), acct.AccountConfig(), acct.Worker(),
+ acct.AccountConfig(), acct.Worker(),
template, &headers, models.OriginalMail{})
if err != nil {
return err
diff --git a/commands/account/recover.go b/commands/account/recover.go
index 9bb73316..8ce878ee 100644
--- a/commands/account/recover.go
+++ b/commands/account/recover.go
@@ -102,7 +102,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
}
composer, err := widgets.NewComposer(aerc, acct,
- aerc.Config(), acct.AccountConfig(), acct.Worker(),
+ acct.AccountConfig(), acct.Worker(),
"", nil, models.OriginalMail{})
if err != nil {
return err
diff --git a/commands/account/view.go b/commands/account/view.go
index f30ac61b..f48d3bc3 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -65,7 +65,7 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(err.Error())
return
}
- viewer := widgets.NewMessageViewer(acct, aerc.Config(), view)
+ viewer := widgets.NewMessageViewer(acct, view)
aerc.NewTab(viewer, msg.Envelope.Subject)
})
return nil
diff --git a/commands/compose/attach.go b/commands/compose/attach.go
index 62ae0291..7e50ea85 100644
--- a/commands/compose/attach.go
+++ b/commands/compose/attach.go
@@ -11,6 +11,7 @@ import (
"strings"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/widgets"
@@ -85,7 +86,7 @@ func (a Attach) addPath(aerc *widgets.Aerc, path string) error {
}
func (a Attach) openMenu(aerc *widgets.Aerc, args []string) error {
- filePickerCmd := aerc.Config().Compose.FilePickerCmd
+ filePickerCmd := config.Compose.FilePickerCmd
if filePickerCmd == "" {
return fmt.Errorf("no file-picker-cmd defined")
}
diff --git a/commands/compose/multipart.go b/commands/compose/multipart.go
index 5a6dd770..32801965 100644
--- a/commands/compose/multipart.go
+++ b/commands/compose/multipart.go
@@ -5,6 +5,7 @@ import (
"fmt"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~sircmpwn/getopt"
)
@@ -22,7 +23,7 @@ func (Multipart) Aliases() []string {
func (Multipart) Complete(aerc *widgets.Aerc, args []string) []string {
var completions []string
completions = append(completions, "-d")
- for mime := range aerc.Config().Converters {
+ for mime := range config.Converters {
completions = append(completions, mime)
}
return commands.CompletionFromList(aerc, completions, args)
@@ -53,7 +54,7 @@ func (a Multipart) Execute(aerc *widgets.Aerc, args []string) error {
if remove {
return composer.RemovePart(mime)
} else {
- _, found := aerc.Config().Converters[mime]
+ _, found := config.Converters[mime]
if !found {
return fmt.Errorf("no command defined for MIME type: %s", mime)
}
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 6d9bfe25..7306bef8 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -108,7 +108,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
msg = "Failed to check for a forgotten attachment."
}
- prompt := widgets.NewPrompt(aerc.Config(),
+ prompt := widgets.NewPrompt(
msg+" Abort send? [Y/n] ",
func(text string) {
if text == "n" || text == "N" {
diff --git a/commands/eml.go b/commands/eml.go
index 864145ce..00380763 100644
--- a/commands/eml.go
+++ b/commands/eml.go
@@ -43,8 +43,7 @@ func (Eml) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(err.Error())
return
}
- msgView := widgets.NewMessageViewer(acct,
- aerc.Config(), view)
+ msgView := widgets.NewMessageViewer(acct, view)
aerc.NewTab(msgView,
view.MessageInfo().Envelope.Subject)
})
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index 066476d8..6c786257 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -4,6 +4,7 @@ import (
"errors"
"time"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
@@ -54,7 +55,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushStatus("Messages deleted.", 10*time.Second)
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
if isMsgView {
- if !aerc.Config().Ui.NextMessageOnDelete {
+ if !config.Ui.NextMessageOnDelete {
aerc.RemoveTab(h.msgProvider)
} else {
// no more messages in the list
@@ -71,7 +72,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(err.Error())
return
}
- nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
+ nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
})
}
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index c0215aee..9a4f3d41 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -12,6 +12,7 @@ import (
"strings"
"sync"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/format"
"git.sr.ht/~rjarry/aerc/lib/ui"
@@ -99,7 +100,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
addTab := func() (*widgets.Composer, error) {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
@@ -158,7 +159,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
})
} else {
if template == "" {
- template = aerc.Config().Templates.Forwards
+ template = config.Templates.Forwards
}
part := lib.FindPlaintext(msg.BodyStructure, nil)
diff --git a/commands/msg/invite.go b/commands/msg/invite.go
index 32251643..2dca259b 100644
--- a/commands/msg/invite.go
+++ b/commands/msg/invite.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/calendar"
"git.sr.ht/~rjarry/aerc/lib/format"
@@ -99,7 +100,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error {
to = msg.Envelope.From
}
- if !aerc.Config().Compose.ReplyToSelf {
+ if !config.Compose.ReplyToSelf {
for i, v := range to {
if v.Address == from.Address {
to = append(to[:i], to[i+1:]...)
@@ -147,7 +148,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error {
}
addTab := func(cr *calendar.Reply) error {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), "", h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 15494364..6e77a88c 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -6,6 +6,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
@@ -91,7 +92,7 @@ func handleDone(
aerc.PushStatus(message, 10*time.Second)
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
switch {
- case isMsgView && !aerc.Config().Ui.NextMessageOnDelete:
+ case isMsgView && !config.Ui.NextMessageOnDelete:
aerc.RemoveTab(h.msgProvider)
case isMsgView:
if next == nil {
@@ -107,7 +108,7 @@ func handleDone(
aerc.PushError(err.Error())
return
}
- nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
+ nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
})
default:
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index d39f4daf..f106e8bd 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -72,7 +72,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}
log.Debugf("Recalling message <%s>", msgInfo.Envelope.MessageId)
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), "", msgInfo.RFC822Headers,
models.OriginalMail{})
if err != nil {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 12eba928..5aad4fc9 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -11,6 +11,7 @@ import (
"git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~rjarry/aerc/commands/account"
+ "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/format"
@@ -118,7 +119,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
to = msg.Envelope.From
}
- if !aerc.Config().Compose.ReplyToSelf {
+ if !config.Compose.ReplyToSelf {
for i, v := range to {
if v.Address == from.Address {
to = append(to[:i], to[i+1:]...)
@@ -179,13 +180,13 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
addTab := func() error {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
return err
}
- if (mv != nil) && aerc.Config().Viewer.CloseOnReply {
+ if (mv != nil) && config.Viewer.CloseOnReply {
mv.Close()
aerc.RemoveTab(mv)
}
@@ -208,7 +209,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
switch {
case c.Sent():
store.Answered([]uint32{msg.Uid}, true, nil)
- case mv != nil && aerc.Config().Viewer.CloseOnReply:
+ case mv != nil && config.Viewer.CloseOnReply:
//nolint:errcheck // who cares?
account.ViewMessage{}.Execute(aerc, []string{"-p"})
}
@@ -219,7 +220,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
if quote {
if template == "" {
- template = aerc.Config().Templates.QuotedReply
+ template = config.Templates.QuotedReply
}
if crypto.IsEncrypted(msg.BodyStructure) {
@@ -275,7 +276,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
return nil
} else {
if template == "" {
- template = aerc.Config().Templates.NewMessage
+ template = config.Templates.NewMessage
}
return addTab()
}
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 0538b2f2..a334e827 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -151,7 +151,6 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
composer, err := widgets.NewComposer(
aerc,
acct,
- aerc.Config(),
acct.AccountConfig(),
acct.Worker(),
"",
diff --git a/commands/msgview/next.go b/commands/msgview/next.go
index a32e358f..d4c02123 100644
--- a/commands/msgview/next.go
+++ b/commands/msgview/next.go
@@ -51,8 +51,7 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(err.Error())
return
}
- nextMv := widgets.NewMessageViewer(acct,
- aerc.Config(), view)
+ nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv,
nextMsg.Envelope.Subject)
})
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 637fceeb..1b9efb38 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -57,8 +57,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
}
go func() {
- openers := aerc.Config().Openers
- err = lib.XDGOpenMime(tmpFile.Name(), mimeType, openers, args[1:])
+ err = lib.XDGOpenMime(tmpFile.Name(), mimeType, args[1:])
if err != nil {
aerc.PushError("open: " + err.Error())
}
diff --git a/commands/msgview/save.go b/commands/msgview/save.go
index 3cb48c2b..ef31988b 100644
--- a/commands/msgview/save.go
+++ b/commands/msgview/save.go
@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/go-homedir"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
@@ -34,7 +35,7 @@ func (Save) Complete(aerc *widgets.Aerc, args []string) []string {
args = args[optind:]
}
path := strings.Join(args, " ")
- defaultPath := aerc.Config().General.DefaultSavePath
+ defaultPath := config.General.DefaultSavePath
if defaultPath != "" && !isAbsPath(path) {
path = filepath.Join(defaultPath, path)
}
@@ -68,7 +69,7 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
}
}
- defaultPath := aerc.Config().General.DefaultSavePath
+ defaultPath := config.General.DefaultSavePath
// we either need a path or a defaultPath
if defaultPath == "" && len(args) == optind {
return errors.New("Usage: :save [-fpa] <path>")
diff --git a/commands/new-account.go b/commands/new-account.go
index 2b28a1b1..2747b159 100644
--- a/commands/new-account.go
+++ b/commands/new-account.go
@@ -26,7 +26,7 @@ func (NewAccount) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return errors.New("Usage: new-account [-t]")
}
- wizard := widgets.NewAccountWizard(aerc.Config(), aerc)
+ wizard := widgets.NewAccountWizard(aerc)
for _, opt := range opts {
if opt.Option == 't' {
wizard.ConfigureTemporaryAccount(true)