aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

commit 9e28a02f6a4345ec7b5fdee68864610186f34e91
parent bd71787e3fa9caf53f18dab37c4f37a2631b2354
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 17 Mar 2019 14:57:05 -0400

commands: handle case where no account selected

Diffstat:
Mcommands/cf.go | 3+++
Mcommands/next-folder.go | 3+++
Mcommands/next-message.go | 3+++
Mcommands/select-message.go | 3+++
Mwidgets/aerc.go | 6+++++-
5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/commands/cf.go b/commands/cf.go @@ -20,6 +20,9 @@ func ChangeFolder(aerc *widgets.Aerc, args []string) error { return errors.New("Usage: cf <folder>") } acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } previous := acct.Directories().Selected() if args[1] == "-" { if dir, ok := history[acct.Name()]; ok { diff --git a/commands/next-folder.go b/commands/next-folder.go @@ -32,6 +32,9 @@ func NextPrevFolder(aerc *widgets.Aerc, args []string) error { } } acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } for ; n > 0; n-- { if args[0] == "prev-folder" { acct.Directories().Prev() diff --git a/commands/next-message.go b/commands/next-message.go @@ -38,6 +38,9 @@ func NextPrevMessage(aerc *widgets.Aerc, args []string) error { } } acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } if pct { n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) } diff --git a/commands/select-message.go b/commands/select-message.go @@ -26,6 +26,9 @@ func SelectMessage(aerc *widgets.Aerc, args []string) error { } } acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } acct.Messages().Select(n) return nil } diff --git a/widgets/aerc.go b/widgets/aerc.go @@ -80,5 +80,9 @@ func (aerc *Aerc) Event(event tcell.Event) bool { } func (aerc *Aerc) SelectedAccount() *AccountView { - return aerc.accounts[aerc.tabs.Tabs[aerc.tabs.Selected].Name] + acct, ok := aerc.accounts[aerc.tabs.Tabs[aerc.tabs.Selected].Name] + if !ok { + return nil + } + return acct }