aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-03 17:37:05 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-08 00:42:56 +0100
commit35040bec9962cac3c92039fac85a4068e148b0a0 (patch)
treeca33752e9ad3d00894468ae489497d3d168faeee
parent159ad244ee23d69f2491b139fd4384c7620b83c2 (diff)
downloadaerc-35040bec9962cac3c92039fac85a4068e148b0a0.tar.gz
templates: separate thread prefix from subject
Extract {{.ThreadPrefix}} from {{.Subject}} so that the prefix can be styled in a different color. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--config/aerc.conf2
-rw-r--r--config/templates.go3
-rw-r--r--config/ui.go4
-rw-r--r--config/ui_test.go2
-rw-r--r--doc/aerc-templates.7.scd5
-rw-r--r--lib/state/templates.go17
-rw-r--r--models/templates.go1
-rw-r--r--widgets/msglist.go9
8 files changed, 27 insertions, 16 deletions
diff --git a/config/aerc.conf b/config/aerc.conf
index 9d1f120e..cb6e8649 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -63,7 +63,7 @@
#column-date={{.DateAutoFormat .Date.Local}}
#column-name={{index (.From | names) 0}}
#column-flags={{.Flags | join ""}}
-#column-subject={{.Subject}}
+#column-subject={{.ThreadPrefix}}{{.Subject}}
#
# String separator inserted between columns. When the column width specifier is
diff --git a/config/templates.go b/config/templates.go
index d3e7cfb0..96fbccb1 100644
--- a/config/templates.go
+++ b/config/templates.go
@@ -74,7 +74,8 @@ func (d *dummyData) ReplyTo() []*mail.Address { return nil }
func (d *dummyData) Date() time.Time { return time.Now() }
func (d *dummyData) DateAutoFormat(time.Time) string { return "" }
func (d *dummyData) Header(string) string { return "" }
-func (d *dummyData) Subject() string { return "[PATCH] hey" }
+func (d *dummyData) ThreadPrefix() string { return "└─>" }
+func (d *dummyData) Subject() string { return "Re: [PATCH] hey" }
func (d *dummyData) Number() int { return 0 }
func (d *dummyData) Labels() []string { return nil }
func (d *dummyData) Flags() []string { return nil }
diff --git a/config/ui.go b/config/ui.go
index f52cf7f8..4b2a303a 100644
--- a/config/ui.go
+++ b/config/ui.go
@@ -284,7 +284,7 @@ func (*UIConfig) ParseIndexColumns(section *ini.Section, key *ini.Key) ([]*Colum
_, _ = section.NewKey("column-flags", `{{.Flags | join ""}}`)
}
if !section.HasKey("column-subject") {
- _, _ = section.NewKey("column-subject", `{{.Subject}}`)
+ _, _ = section.NewKey("column-subject", `{{.ThreadPrefix}}{{.Subject}}`)
}
return ParseColumnDefs(key, section)
}
@@ -382,7 +382,7 @@ func indexVerbToTemplate(verb rune) (f, name string) {
f = `{{.Cc | persons | join ", "}}`
name = "cc"
case 's':
- f = "{{.Subject}}"
+ f = "{{.ThreadPrefix}}{{.Subject}}"
name = "subject"
case 't':
f = "{{(index .To 0).Address}}"
diff --git a/config/ui_test.go b/config/ui_test.go
index 80373da2..188fae01 100644
--- a/config/ui_test.go
+++ b/config/ui_test.go
@@ -43,7 +43,7 @@ func TestConvertIndexFormat(t *testing.T) {
assert.Equal(t, "subject", columns[3].Name)
assert.Equal(t, 0.0, columns[3].Width)
assert.Equal(t, ALIGN_LEFT|WIDTH_AUTO, columns[3].Flags)
- assert.Equal(t, `{{.Subject}}`, templateText(columns[3].Template))
+ assert.Equal(t, `{{.ThreadPrefix}}{{.Subject}}`, templateText(columns[3].Template))
}
func TestConvertDirlistFormat(t *testing.T) {
diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd
index f3f2a568..63d9df6a 100644
--- a/doc/aerc-templates.7.scd
+++ b/doc/aerc-templates.7.scd
@@ -76,10 +76,11 @@ available always.
Refer to the *TEMPLATE FUNCTIONS* section for details.
*Subject*
- The subject of the email.
+ The subject of the email (_ThreadPrefix_ will be empty unless threading
+ is enabled).
```
- {{.Subject}}
+ {{.ThreadPrefix}}{{.Subject}}
```
*Flags*
diff --git a/lib/state/templates.go b/lib/state/templates.go
index d5631b11..2e351a7a 100644
--- a/lib/state/templates.go
+++ b/lib/state/templates.go
@@ -23,8 +23,8 @@ type TemplateData struct {
msgNum int
// message list threading
- ThreadSameSubject bool
- ThreadPrefix string
+ threadSameSubject bool
+ threadPrefix string
// selected account
account *config.AccountConfig
@@ -50,6 +50,11 @@ func (d *TemplateData) SetInfo(info *models.MessageInfo, num int, marked bool) {
d.marked = marked
}
+func (d *TemplateData) SetThreading(prefix string, same bool) {
+ d.threadPrefix = prefix
+ d.threadSameSubject = same
+}
+
func (d *TemplateData) SetAccount(acct *config.AccountConfig) {
d.account = acct
d.myAddresses = make(map[string]bool)
@@ -220,6 +225,10 @@ func (d *TemplateData) Header(name string) string {
return text
}
+func (d *TemplateData) ThreadPrefix() string {
+ return d.threadPrefix
+}
+
func (d *TemplateData) Subject() string {
var subject string
switch {
@@ -228,10 +237,10 @@ func (d *TemplateData) Subject() string {
case d.headers != nil:
subject = d.Header("subject")
}
- if d.ThreadSameSubject {
+ if d.threadSameSubject {
subject = ""
}
- return d.ThreadPrefix + subject
+ return subject
}
func (d *TemplateData) SubjectBase() string {
diff --git a/models/templates.go b/models/templates.go
index 916b3974..5ee516ac 100644
--- a/models/templates.go
+++ b/models/templates.go
@@ -19,6 +19,7 @@ type TemplateData interface {
Date() time.Time
DateAutoFormat(date time.Time) string
Header(name string) string
+ ThreadPrefix() string
Subject() string
Number() int
Labels() []string
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 24f3d3bf..4bf20b09 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -160,11 +160,10 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
}
baseSubject := threadSubject(store, thread)
- data.ThreadSameSubject = baseSubject == lastSubject &&
- sameParent(thread, prevThread) &&
- !isParent(thread)
- data.ThreadPrefix = threadPrefix(thread,
- store.ReverseThreadOrder())
+ data.SetThreading(
+ threadPrefix(thread, store.ReverseThreadOrder()),
+ baseSubject == lastSubject && sameParent(thread, prevThread) && !isParent(thread),
+ )
lastSubject = baseSubject
prevThread = thread