on master help sign in
style fixup
commitadf2e871ccd402092015b0e08294563c5499abd5 authorCorey O'Connor <corey@ooyala.com> dateSun 15 Dec 2013, 22:28 (13 years ago) parent92ff677
1 file changed+42−43
src/Graphics/Vty/DisplayAttributes.hs+42−43
src/Graphics/Vty/DisplayAttributes.hs+42−43
@@ -5,25 +5,25 @@ module Graphics.Vty.DisplayAttributes
55
66import Graphics.Vty.Attributes
77
8−import Data.Bits ( (.&.) )
9−import Data.Monoid ( Monoid(..), mconcat )
8+import Data.Bits ((.&.))
9+import Data.Monoid (Monoid(..), mconcat)
1010
1111-- | Given the previously applied display attributes as a FixedAttr and the current display
1212-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
1313-- is done by using the previously applied display attributes to remove the "KeepCurrent"
1414-- abstraction.
1515fix_display_attr :: FixedAttr -> Attr -> FixedAttr
16−fix_display_attr fattr attr
17− = FixedAttr ( fix_style (fixed_style fattr) (attr_style attr) )
18− ( fix_color (fixed_fore_color fattr) (attr_fore_color attr) )
19− ( fix_color (fixed_back_color fattr) (attr_back_color attr) )
16+fix_display_attr fattr attr
17+ = FixedAttr (fix_style (fixed_style fattr) (attr_style attr))
18+ (fix_color (fixed_fore_color fattr) (attr_fore_color attr))
19+ (fix_color (fixed_back_color fattr) (attr_back_color attr))
2020 where
21− fix_style _s Default = default_style_mask
22− fix_style s KeepCurrent = s
21+ fix_style _s Default = default_style_mask
22+ fix_style s KeepCurrent = s
2323 fix_style _s (SetTo new_style) = new_style
24− fix_color _c Default = Nothing
25− fix_color c KeepCurrent = c
26− fix_color _c (SetTo c) = Just c
24+ fix_color _c Default = Nothing
25+ fix_color c KeepCurrent = c
26+ fix_color _c (SetTo c) = Just c
2727
2828-- | difference between two display attributes. Used in the calculation of the operations required
2929-- to go from one display attribute to the next.
@@ -32,24 +32,24 @@ fix_display_attr fattr attr
3232-- This turned out to be very expensive: A *lot* more data would be sent to the terminal than
3333-- required.
3434data DisplayAttrDiff = DisplayAttrDiff
35− { style_diffs :: [ StyleStateChange ]
35+ { style_diffs :: [StyleStateChange]
3636 , fore_color_diff :: DisplayColorDiff
3737 , back_color_diff :: DisplayColorDiff
3838 }
39− deriving ( Show )
39+ deriving (Show)
4040
4141instance Monoid DisplayAttrDiff where
4242 mempty = DisplayAttrDiff [] NoColorChange NoColorChange
43− mappend d_0 d_1 =
44− let ds = simplify_style_diffs ( style_diffs d_0 ) ( style_diffs d_1 )
45− fcd = simplify_color_diffs ( fore_color_diff d_0 ) ( fore_color_diff d_1 )
46− bcd = simplify_color_diffs ( back_color_diff d_0 ) ( back_color_diff d_1 )
43+ mappend d_0 d_1 =
44+ let ds = simplify_style_diffs (style_diffs d_0) (style_diffs d_1)
45+ fcd = simplify_color_diffs (fore_color_diff d_0) (fore_color_diff d_1)
46+ bcd = simplify_color_diffs (back_color_diff d_0) (back_color_diff d_1)
4747 in DisplayAttrDiff ds fcd bcd
4848
4949-- | Used in the computation of a final style attribute change.
5050--
5151-- TODO(corey): not really a simplify but a monoid instance.
52−simplify_style_diffs :: [ StyleStateChange ] -> [ StyleStateChange ] -> [ StyleStateChange ]
52+simplify_style_diffs :: [StyleStateChange] -> [StyleStateChange] -> [StyleStateChange]
5353simplify_style_diffs cs_0 cs_1 = cs_0 `mappend` cs_1
5454
5555-- | Consider two display color attributes diffs. What display color attribute diff are these
@@ -57,16 +57,16 @@ simplify_style_diffs cs_0 cs_1 = cs_0 `mappend` cs_1
5757--
5858-- TODO(corey): not really a simplify but a monoid instance.
5959simplify_color_diffs :: DisplayColorDiff -> DisplayColorDiff -> DisplayColorDiff
60−simplify_color_diffs _cd ColorToDefault = ColorToDefault
61−simplify_color_diffs cd NoColorChange = cd
62−simplify_color_diffs _cd ( SetColor !c ) = SetColor c
60+simplify_color_diffs _cd ColorToDefault = ColorToDefault
61+simplify_color_diffs cd NoColorChange = cd
62+simplify_color_diffs _cd (SetColor !c) = SetColor c
6363
6464-- | Difference between two display color attribute changes.
65−data DisplayColorDiff
65+data DisplayColorDiff
6666 = ColorToDefault
6767 | NoColorChange
6868 | SetColor !Color
69− deriving ( Show, Eq )
69+ deriving (Show, Eq)
7070
7171-- | Style attribute changes are transformed into a sequence of apply/removes of the individual
7272-- attributes.
@@ -83,44 +83,43 @@ data StyleStateChange
8383 | RemoveDim
8484 | ApplyBold
8585 | RemoveBold
86− deriving ( Show, Eq )
86+ deriving (Show, Eq)
8787
8888-- | Determines the diff between two display&color attributes. This diff determines the operations
8989-- that actually get output to the terminal.
9090display_attr_diffs :: FixedAttr -> FixedAttr -> DisplayAttrDiff
9191display_attr_diffs attr attr' = DisplayAttrDiff
92− { style_diffs = diff_styles ( fixed_style attr ) ( fixed_style attr' )
93− , fore_color_diff = diff_color ( fixed_fore_color attr ) ( fixed_fore_color attr' )
94− , back_color_diff = diff_color ( fixed_back_color attr ) ( fixed_back_color attr' )
92+ { style_diffs = diff_styles (fixed_style attr) (fixed_style attr')
93+ , fore_color_diff = diff_color (fixed_fore_color attr) (fixed_fore_color attr')
94+ , back_color_diff = diff_color (fixed_back_color attr) (fixed_back_color attr')
9595 }
9696
9797diff_color :: Maybe Color -> Maybe Color -> DisplayColorDiff
9898diff_color Nothing (Just c') = SetColor c'
99−diff_color (Just c) (Just c')
99+diff_color (Just c) (Just c')
100100 | c == c' = NoColorChange
101101 | otherwise = SetColor c'
102102diff_color Nothing Nothing = NoColorChange
103103diff_color (Just _) Nothing = ColorToDefault
104104
105105diff_styles :: Style -> Style -> [StyleStateChange]
106−diff_styles prev cur
107− = mconcat
108− [ style_diff standout ApplyStandout RemoveStandout
109− , style_diff underline ApplyUnderline RemoveUnderline
106+diff_styles prev cur
107+ = mconcat
108+ [ style_diff standout ApplyStandout RemoveStandout
109+ , style_diff underline ApplyUnderline RemoveUnderline
110110 , style_diff reverse_video ApplyReverseVideo RemoveReverseVideo
111− , style_diff blink ApplyBlink RemoveBlink
112− , style_diff dim ApplyDim RemoveDim
113− , style_diff bold ApplyBold RemoveBold
111+ , style_diff blink ApplyBlink RemoveBlink
112+ , style_diff dim ApplyDim RemoveDim
113+ , style_diff bold ApplyBold RemoveBold
114114 ]
115− where
116− style_diff s sm rm
117− = case ( 0 == prev .&. s, 0 == cur .&. s ) of
115+ where
116+ style_diff s sm rm
117+ = case (0 == prev .&. s, 0 == cur .&. s) of
118118 -- not set in either
119− ( True, True ) -> []
119+ (True, True) -> []
120120 -- set in both
121− ( False, False ) -> []
121+ (False, False) -> []
122122 -- now set
123− ( True, False) -> [ sm ]
123+ (True, False) -> [sm]
124124 -- now unset
125− ( False, True) -> [ rm ]
126−
125+ (False, True) -> [rm]