aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-02 23:50:50 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-08 00:42:51 +0100
commit21d0f3381e642764e8778bc909cb1fdb4cb5e7ce (patch)
tree0dfeff93bcbd51ebe26f6ef94d4dd4c3dbd30ef2
parentab8f433e1739f0c823809ddab192693e875d75df (diff)
downloadaerc-21d0f3381e642764e8778bc909cb1fdb4cb5e7ce.tar.gz
aerc-21d0f3381e642764e8778bc909cb1fdb4cb5e7ce.zip
templates: avoid error when using .Style with unknown style name
When using {{.Style "foo" bar}} and "foo" is not defined in the styleset under the [user] section, there is an obscure error: template: column-right:1:18: executing "column-right" at <.Style>: error calling Style: runtime error: invalid memory address or nil pointer dereference Which is most of the time truncated and can only be read in logs. Referencing an undefined style is not a serious problem. Return the default tcell style in that case and avoid the error. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--config/style.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/config/style.go b/config/style.go
index 317c77d0..7b13c3a2 100644
--- a/config/style.go
+++ b/config/style.go
@@ -288,7 +288,10 @@ func (ss StyleSet) Selected(so StyleObject) tcell.Style {
}
func (ss StyleSet) UserStyle(name string) tcell.Style {
- return ss.user[name].Get()
+ if style, found := ss.user[name]; found {
+ return style.Get()
+ }
+ return tcell.StyleDefault
}
func (ss StyleSet) Compose(so StyleObject, sos []StyleObject) tcell.Style {