@@ -1,10 +1,11 @@
1+{-# LANGUAGE BangPatterns #-}
1module Graphics.Vty.DisplayAttributes
2module Graphics.Vty.DisplayAttributes
4import Graphics.Vty.Attributes
5import Graphics.Vty.Attributes
6import Data.Bits ( (.&.) )
7import Data.Bits ( (.&.) )
7−import Data.Monoid ( mconcat )
8+import Data.Monoid ( Monoid(..), mconcat )
9-- | Given the previously applied display attributes as a FixedAttr and the current display
10-- | Given the previously applied display attributes as a FixedAttr and the current display
10-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
11-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
@@ -29,6 +30,21 @@ data DisplayAttrDiff = DisplayAttrDiff
29 , back_color_diff :: DisplayColorDiff
30 , back_color_diff :: DisplayColorDiff
33+instance Monoid DisplayAttrDiff where
34+ mempty = DisplayAttrDiff [] NoColorChange NoColorChange
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
41+simplify_style_diffs :: [ StyleStateChange ] -> [ StyleStateChange ] -> [ StyleStateChange ]
42+simplify_style_diffs cs_0 cs_1 = cs_0 `mappend` cs_1
44+simplify_color_diffs _cd ColorToDefault = ColorToDefault
45+simplify_color_diffs cd NoColorChange = cd
46+simplify_color_diffs _cd ( SetColor !c ) = SetColor c
32data DisplayColorDiff
48data DisplayColorDiff
33 = ColorToDefault
49 = ColorToDefault
34 | NoColorChange
50 | NoColorChange