aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/msglist.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-07-14 20:37:32 +0200
committerRobin Jarry <robin@jarry.cc>2023-07-16 10:13:12 +0200
commitb267de83e38c09d34215e7a33991ae5c111fe649 (patch)
treeadeb2619459228d43475d4efd92324ba82ad4e38 /widgets/msglist.go
parent94b1c778dbe691a75b0d918e9c40cc34f8523768 (diff)
downloadaerc-b267de83e38c09d34215e7a33991ae5c111fe649.tar.gz
templates: add ThreadCount and ThreadFolded
Add the number of threads and a flag to indicated folded threads to the template data. Use {{.ThreadCount}} and {{.ThreadFolded}} in template expression for the message list. column-subject = {{.ThreadPrefix}}{{if .ThreadFolded}}[{{.ThreadCount}}] {{end}}{{.Subject}} Update default configuration accordingly. Signed-off-by: Koni Marti <koni.marti@gmail.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: inwit <inwit@sindominio.net>
Diffstat (limited to 'widgets/msglist.go')
-rw-r--r--widgets/msglist.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 548735d3..9ce60756 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -384,6 +384,17 @@ func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) {
uiConfig.GetStyle(config.STYLE_MSGLIST_DEFAULT), "%s", msg)
}
+func countThreads(thread *types.Thread) (ctr int) {
+ if thread == nil {
+ return
+ }
+ _ = thread.Walk(func(t *types.Thread, _ int, _ error) error {
+ ctr++
+ return nil
+ })
+ return
+}
+
func threadPrefix(t *types.Thread, reverse bool, point bool) string {
var arrow string
if t.Parent != nil {
@@ -457,7 +468,7 @@ func newThreadView(store *lib.MessageStore) *threadView {
}
func (t *threadView) Update(data state.DataSetter, uid uint32) {
- prefix, same := "", false
+ prefix, same, count, folded := "", false, 0, false
thread, err := t.store.Thread(uid)
if thread != nil && err == nil {
prefix = threadPrefix(thread, t.reverse, true)
@@ -465,6 +476,8 @@ func (t *threadView) Update(data state.DataSetter, uid uint32) {
same = subject == t.prevSubj && sameParent(thread, t.prev) && !isParent(thread)
t.prev = thread
t.prevSubj = subject
+ count = countThreads(thread)
+ folded = thread.FirstChild != nil && thread.FirstChild.Hidden
}
- data.SetThreading(prefix, same)
+ data.SetThreading(prefix, same, count, folded)
}