diff options
Diffstat (limited to 'commands')
78 files changed, 479 insertions, 492 deletions
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(), ©Buf) 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, ¶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 } 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) } } |