@@ -1,10 +1,11 @@
1+{-# LANGUAGE BangPatterns #-}
12module Graphics.Vty.DisplayAttributes
23 where
34
45import Graphics.Vty.Attributes
56
67import Data.Bits ( (.&.) )
7−import Data.Monoid ( mconcat )
8+import Data.Monoid ( Monoid(..), mconcat )
89
910-- | Given the previously applied display attributes as a FixedAttr and the current display
1011-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
@@ -29,6 +30,21 @@ data DisplayAttrDiff = DisplayAttrDiff
2930 , back_color_diff :: DisplayColorDiff
3031 }
3132
33+instance Monoid DisplayAttrDiff where
34+ mempty = DisplayAttrDiff [] NoColorChange NoColorChange
35+ mappend d_0 d_1 =
36+ let ds = simplify_style_diffs ( style_diffs d_0 ) ( style_diffs d_1 )
37+ fcd = simplify_color_diffs ( fore_color_diff d_0 ) ( fore_color_diff d_1 )
38+ bcd = simplify_color_diffs ( back_color_diff d_0 ) ( back_color_diff d_1 )
39+ in DisplayAttrDiff ds fcd bcd
40+
41+simplify_style_diffs :: [ StyleStateChange ] -> [ StyleStateChange ] -> [ StyleStateChange ]
42+simplify_style_diffs cs_0 cs_1 = cs_0 `mappend` cs_1
43+
44+simplify_color_diffs _cd ColorToDefault = ColorToDefault
45+simplify_color_diffs cd NoColorChange = cd
46+simplify_color_diffs _cd ( SetColor !c ) = SetColor c
47+
3248data DisplayColorDiff
3349 = ColorToDefault
3450 | NoColorChange