aboutsummaryrefslogtreecommitdiffstats
path: root/lib/state/templates.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-06-08 22:16:31 +0200
committerRobin Jarry <robin@jarry.cc>2023-06-10 23:54:06 +0200
commit9479513ec138b0e4b2ad2c53a0566c00c7035845 (patch)
tree98ce844e82eeebf2151a3c0fa1ac1b530964f344 /lib/state/templates.go
parent8162c5be8f251e985a18928ed1a8cb571df40945 (diff)
downloadaerc-9479513ec138b0e4b2ad2c53a0566c00c7035845.tar.gz
templates: add map functions
Similar to switch and .StyleSwitch, add map and .StyleMap to work on lists. An extra "exclude" item is available to filter elements out of the list. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'lib/state/templates.go')
-rw-r--r--lib/state/templates.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/state/templates.go b/lib/state/templates.go
index 8c7df3e8..36f7b725 100644
--- a/lib/state/templates.go
+++ b/lib/state/templates.go
@@ -560,3 +560,23 @@ func (d *templateData) StyleSwitch(content string, cases ...models.Case) string
}
return content
}
+
+func (d *templateData) StyleMap(elems []string, cases ...models.Case) []string {
+ mapped := make([]string, 0, len(elems))
+top:
+ for _, e := range elems {
+ for _, c := range cases {
+ if c.Matches(e) {
+ if c.Skip() {
+ continue top
+ }
+ cfg := config.Ui.ForAccount(d.Account())
+ style := cfg.GetUserStyle(c.Value())
+ e = parse.ApplyStyle(style, e)
+ break
+ }
+ }
+ mapped = append(mapped, e)
+ }
+ return mapped
+}