From 2d7a8707257eec2b9f0ff41772cfd8dab4f1201e Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sat, 8 Aug 2020 11:38:38 +0200 Subject: show error if account view creation fails This can happen for example if aerc is compiled without notmuch support but the notmuch worker is requested. Pushing a status message isn't good enough, as this gets overridden pretty quickly if one has multiple accounts configured. So we show a fullscreen error instead. --- widgets/aerc.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'widgets/aerc.go') diff --git a/widgets/aerc.go b/widgets/aerc.go index 692e00d2..acdd8b4a 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -84,9 +84,13 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger, conf.Triggers.ExecuteCommand = cmd for i, acct := range conf.Accounts { - view := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc) - aerc.accounts[acct.Name] = view - tabs.Add(view, acct.Name) + view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc) + if err != nil { + tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name) + } else { + aerc.accounts[acct.Name] = view + tabs.Add(view, acct.Name) + } } if len(conf.Accounts) == 0 { @@ -609,3 +613,20 @@ func (aerc *Aerc) DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err } return nil, err } + +// errorScreen is a widget that draws an error in the middle of the context +func errorScreen(s string, conf config.UIConfig) ui.Drawable { + errstyle := conf.GetStyle(config.STYLE_ERROR) + text := ui.NewText(s, errstyle).Strategy(ui.TEXT_CENTER) + grid := ui.NewGrid().Rows([]ui.GridSpec{ + {ui.SIZE_WEIGHT, ui.Const(1)}, + {ui.SIZE_EXACT, ui.Const(1)}, + {ui.SIZE_WEIGHT, ui.Const(1)}, + }).Columns([]ui.GridSpec{ + {ui.SIZE_WEIGHT, ui.Const(1)}, + }) + grid.AddChild(ui.NewFill(' ')).At(0, 0) + grid.AddChild(text).At(1, 0) + grid.AddChild(ui.NewFill(' ')).At(2, 0) + return grid +} -- cgit