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/msgview/save.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/msgview/save.go')
-rw-r--r-- | commands/msgview/save.go | 15 |
1 files changed, 7 insertions, 8 deletions
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, ¶ms, names); err != nil { + if err := savePart(pi, path, mv, ¶ms, 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, ¶ms, make(map[string]struct{})) + return savePart(pi, path, mv, ¶ms, 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 } |