commands: handle case where no account selected

This commit is contained in:
Drew DeVault 2019-03-17 14:57:05 -04:00
parent bd71787e3f
commit 9e28a02f6a
5 changed files with 17 additions and 1 deletions

View File

@ -20,6 +20,9 @@ func ChangeFolder(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: cf <folder>") return errors.New("Usage: cf <folder>")
} }
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
previous := acct.Directories().Selected() previous := acct.Directories().Selected()
if args[1] == "-" { if args[1] == "-" {
if dir, ok := history[acct.Name()]; ok { if dir, ok := history[acct.Name()]; ok {

View File

@ -32,6 +32,9 @@ func NextPrevFolder(aerc *widgets.Aerc, args []string) error {
} }
} }
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
for ; n > 0; n-- { for ; n > 0; n-- {
if args[0] == "prev-folder" { if args[0] == "prev-folder" {
acct.Directories().Prev() acct.Directories().Prev()

View File

@ -38,6 +38,9 @@ func NextPrevMessage(aerc *widgets.Aerc, args []string) error {
} }
} }
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
if pct { if pct {
n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0))
} }

View File

@ -26,6 +26,9 @@ func SelectMessage(aerc *widgets.Aerc, args []string) error {
} }
} }
acct := aerc.SelectedAccount() acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
acct.Messages().Select(n) acct.Messages().Select(n)
return nil return nil
} }

View File

@ -80,5 +80,9 @@ func (aerc *Aerc) Event(event tcell.Event) bool {
} }
func (aerc *Aerc) SelectedAccount() *AccountView { 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
} }