diff options
author | Chris Vittal <chris@vittal.dev> | 2020-10-27 14:56:44 -0400 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-11-01 09:50:58 +0100 |
commit | f9bba3d17d4ac8c12e01adccc06566a46546e995 (patch) | |
tree | 3d96a7e74f668739544ffe45b70cc96696dd4f99 /config/style.go | |
parent | 743683a0c19c75ba87d65b6d0c9be117d0224a3e (diff) | |
download | aerc-f9bba3d17d4ac8c12e01adccc06566a46546e995.tar.gz |
Apply relevant msglist styles in order
Allow styles to be layered over a base style. The list of styles to apply is layered over the base style in order, such that if the layer does not differ from the base it is not used. The order that these styles are applied in is, from first to last: msglist_default msglist_unread msglist_read (exclusive with unread, so technically the same level) msglist_flagged msglist_deleted msglist_marked So, msglist_marked style dominates. This fixes an issue where the msglist_deleted style was not being applied.
Diffstat (limited to 'config/style.go')
-rw-r--r-- | config/style.go | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/config/style.go b/config/style.go index caf9e4f..af7241d 100644 --- a/config/style.go +++ b/config/style.go @@ -31,9 +31,9 @@ const ( STYLE_MSGLIST_DEFAULT STYLE_MSGLIST_UNREAD STYLE_MSGLIST_READ + STYLE_MSGLIST_FLAGGED STYLE_MSGLIST_DELETED STYLE_MSGLIST_MARKED - STYLE_MSGLIST_FLAGGED STYLE_DIRLIST_DEFAULT @@ -67,9 +67,9 @@ var StyleNames = map[string]StyleObject{ "msglist_default": STYLE_MSGLIST_DEFAULT, "msglist_unread": STYLE_MSGLIST_UNREAD, "msglist_read": STYLE_MSGLIST_READ, + "msglist_flagged": STYLE_MSGLIST_FLAGGED, "msglist_deleted": STYLE_MSGLIST_DELETED, "msglist_marked": STYLE_MSGLIST_MARKED, - "msglist_flagged": STYLE_MSGLIST_FLAGGED, "dirlist_default": STYLE_DIRLIST_DEFAULT, @@ -180,6 +180,31 @@ func (s *Style) Set(attr, val string) error { return nil } +func (s Style) composeWith(styles []*Style) Style { + newStyle := s + for _, st := range styles { + if st.Fg != s.Fg { + newStyle.Fg = st.Fg + } + if st.Bg != s.Bg { + newStyle.Bg = st.Bg + } + if st.Bold != s.Bold { + newStyle.Bold = st.Bold + } + if st.Blink != s.Blink { + newStyle.Blink = st.Blink + } + if st.Underline != s.Underline { + newStyle.Underline = st.Underline + } + if st.Reverse != s.Reverse { + newStyle.Reverse = st.Reverse + } + } + return newStyle +} + type StyleSet struct { objects map[StyleObject]*Style selected map[StyleObject]*Style @@ -213,6 +238,27 @@ func (ss StyleSet) Selected(so StyleObject) tcell.Style { return ss.selected[so].Get() } +func (ss StyleSet) Compose(so StyleObject, sos []StyleObject) tcell.Style { + base := *ss.objects[so] + styles := make([]*Style, len(sos)) + for i, so := range sos { + styles[i] = ss.objects[so] + } + + return base.composeWith(styles).Get() +} + +func (ss StyleSet) ComposeSelected(so StyleObject, + sos []StyleObject) tcell.Style { + base := *ss.selected[so] + styles := make([]*Style, len(sos)) + for i, so := range sos { + styles[i] = ss.selected[so] + } + + return base.composeWith(styles).Get() +} + func findStyleSet(stylesetName string, stylesetsDir []string) (string, error) { for _, dir := range stylesetsDir { stylesetPath, err := homedir.Expand(path.Join(dir, stylesetName)) |