diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2023-01-26 10:16:43 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-29 21:47:11 +0100 |
commit | 6b39c0dae1e1c42445a2d8557e48135b02fc729b (patch) | |
tree | d65d2898424178203c0be52c56c255f96f8d51ee /widgets | |
parent | db60d7edeceaec075f91a802968c397698798d50 (diff) | |
download | aerc-6b39c0dae1e1c42445a2d8557e48135b02fc729b.tar.gz |
tabs: use template for account tab name
Use a go template to render the account tab display. Add config option
for setting a specific template for the account. Add a method on Tab to
allow setting a title, which may be different than the tab Name.
The default template is {{.Account}}.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/account.go | 29 | ||||
-rw-r--r-- | widgets/aerc.go | 2 | ||||
-rw-r--r-- | widgets/dirlist.go | 14 |
3 files changed, 44 insertions, 1 deletions
diff --git a/widgets/account.go b/widgets/account.go index c2b8b8e9..6c9ab3eb 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -1,6 +1,7 @@ package widgets import ( + "bytes" "errors" "fmt" "sync" @@ -30,6 +31,7 @@ type AccountView struct { labels []string grid *ui.Grid host TabHost + tab *ui.Tab msglist *MessageList worker *types.Worker state *statusline.State @@ -351,6 +353,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.PushError(msg.Error) } acct.UpdateStatus() + acct.setTitle() } func (acct *AccountView) updateDirCounts(destination string, uids []uint32) { @@ -588,3 +591,29 @@ func (acct *AccountView) Vsplit(n int) error { acct.updateSplitView(acct.msglist.Selected()) return nil } + +// setTitle executes the title template and sets the tab title +func (acct *AccountView) setTitle() { + data := struct { + Account string + Recent int + Unread int + Exists int + Folder string + }{} + data.Account = acct.Name() + data.Folder = acct.SelectedDirectory() + for _, name := range acct.dirlist.List() { + r, u, e := acct.dirlist.GetRUECount(name) + data.Recent += r + data.Unread += u + data.Exists += e + } + buf := bytes.NewBuffer(nil) + err := acct.uiConf.TabTitleAccount.Execute(buf, data) + if err != nil { + acct.PushError(err) + return + } + acct.tab.SetTitle(buf.String()) +} diff --git a/widgets/aerc.go b/widgets/aerc.go index 59944cc6..f1e512f3 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -94,7 +94,7 @@ func NewAerc( tabs.Add(errorScreen(err.Error()), acct.Name, nil) } else { aerc.accounts[acct.Name] = view - tabs.Add(view, acct.Name, view.UiConfig()) + view.tab = tabs.Add(view, acct.Name, view.UiConfig()) } } diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 09a1155a..8e6fa751 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -42,6 +42,7 @@ type DirectoryLister interface { SetMsgStore(string, *lib.MessageStore) FilterDirs([]string, []string, bool) []string + GetRUECount(string) (int, int, int) UiConfig(string) *config.UIConfig } @@ -254,6 +255,19 @@ func (dirlist *DirectoryList) getRUEString(name string) string { return rueString } +// Returns the Recent, Unread, and Exist counts for the named directory +func (dirlist *DirectoryList) GetRUECount(name string) (int, int, int) { + msgStore, ok := dirlist.MsgStore(name) + if !ok { + return 0, 0, 0 + } + if !msgStore.DirInfo.AccurateCounts { + msgStore.DirInfo.Recent, msgStore.DirInfo.Unseen = countRUE(msgStore) + } + di := msgStore.DirInfo + return di.Recent, di.Unseen, di.Exists +} + func (dirlist *DirectoryList) Draw(ctx *ui.Context) { ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', dirlist.UiConfig("").GetStyle(config.STYLE_DIRLIST_DEFAULT)) |