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/account.go | |
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/account.go')
-rw-r--r-- | widgets/account.go | 29 |
1 files changed, 29 insertions, 0 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()) +} |