diff options
author | Robin Jarry <robin@jarry.cc> | 2023-03-04 01:15:16 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-08 00:43:08 +0100 |
commit | 41ae3639051869921b62c1bda51b88b6b71faec5 (patch) | |
tree | e983444625a5ebdacb9af32182b0ddd62160883a /lib/state | |
parent | c477d83f2493871b215aa2f8b2668b9b84fd6295 (diff) | |
download | aerc-41ae3639051869921b62c1bda51b88b6b71faec5.tar.gz |
templates: add conditional style method
Add .StyleSwitch that takes a string and an arbitrary number of cases
(regexp, style). Reuse some of the constructs introduced by previous
commit.
The style of the first regular expression that matches will be applied.
If the string does not match any of the expressions, it will be left
as-is.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/state')
-rw-r--r-- | lib/state/templates.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/state/templates.go b/lib/state/templates.go index 1e8bad00..f971b62c 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -472,3 +472,14 @@ func (d *TemplateData) Style(content, name string) string { style := cfg.GetUserStyle(name) return parse.ApplyStyle(style, content) } + +func (d *TemplateData) StyleSwitch(content string, cases ...models.Case) string { + for _, c := range cases { + if c.Matches(content) { + cfg := config.Ui.ForAccount(d.Account()) + style := cfg.GetUserStyle(c.Value()) + return parse.ApplyStyle(style, content) + } + } + return content +} |