diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-10 00:08:31 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-10 11:38:01 +0200 |
commit | bc176bd61ba726351a489cabf4da16a47dc5ec3b (patch) | |
tree | bbf06f731592d072f3d6f76f1648d61989375f2e /commands/msg/move.go | |
parent | 598e4a5803578ab3e291f232d6aad31b4efd8ea4 (diff) | |
download | aerc-bc176bd61ba726351a489cabf4da16a47dc5ec3b.tar.gz |
app: export global functions
The single Aerc object is passed around in almost all command functions.
This hinders readability.
Store the single Aerc instance as a global variable. Export public
functions from the app package to access methods of that object. Remove
all explicit references to *app.Aerc and replace them with calls to
these functions. For references to private/unexported fields and
functions from within the app package, directly access the global aerc
object.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands/msg/move.go')
-rw-r--r-- | commands/msg/move.go | 27 |
1 files changed, 13 insertions, 14 deletions
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 { |