1{-# LANGUAGE BangPatterns #-}
2module Graphics.Vty.DisplayAttributes
5import Graphics.Vty.Attributes
7import Data.Bits ( (.&.) )
8import Data.Monoid ( Monoid(..), mconcat )
10-- | Given the previously applied display attributes as a FixedAttr and the current display
11-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
12-- is done by using the previously applied display attributes to remove the "KeepCurrent"
14fix_display_attr :: FixedAttr -> Attr -> FixedAttr
15fix_display_attr fattr attr
16 = FixedAttr ( fix_style (fixed_style fattr) (attr_style attr) )
17 ( fix_color (fixed_fore_color fattr) (attr_fore_color attr) )
18 ( fix_color (fixed_back_color fattr) (attr_back_color attr) )
20 fix_style _s Default = default_style_mask
21 fix_style s KeepCurrent = s
22 fix_style _s (SetTo new_style) = new_style
23 fix_color _c Default = Nothing
24 fix_color c KeepCurrent = c
25 fix_color _c (SetTo c) = Just c
27data DisplayAttrDiff = DisplayAttrDiff
28 { style_diffs :: [ StyleStateChange ]
29 , fore_color_diff :: DisplayColorDiff
30 , back_color_diff :: DisplayColorDiff
34instance Monoid DisplayAttrDiff where
35 mempty = DisplayAttrDiff [] NoColorChange NoColorChange
37 let ds = simplify_style_diffs ( style_diffs d_0 ) ( style_diffs d_1 )
38 fcd = simplify_color_diffs ( fore_color_diff d_0 ) ( fore_color_diff d_1 )
39 bcd = simplify_color_diffs ( back_color_diff d_0 ) ( back_color_diff d_1 )
40 in DisplayAttrDiff ds fcd bcd
42simplify_style_diffs :: [ StyleStateChange ] -> [ StyleStateChange ] -> [ StyleStateChange ]
43simplify_style_diffs cs_0 cs_1 = cs_0 `mappend` cs_1
45simplify_color_diffs :: DisplayColorDiff -> DisplayColorDiff -> DisplayColorDiff
46simplify_color_diffs _cd ColorToDefault = ColorToDefault
47simplify_color_diffs cd NoColorChange = cd
48simplify_color_diffs _cd ( SetColor !c ) = SetColor c
71display_attr_diffs :: FixedAttr -> FixedAttr -> DisplayAttrDiff
72display_attr_diffs attr attr' = DisplayAttrDiff
73 { style_diffs = diff_styles ( fixed_style attr ) ( fixed_style attr' )
74 , fore_color_diff = diff_color ( fixed_fore_color attr ) ( fixed_fore_color attr' )
75 , back_color_diff = diff_color ( fixed_back_color attr ) ( fixed_back_color attr' )
78diff_color :: Maybe Color -> Maybe Color -> DisplayColorDiff
79diff_color Nothing (Just c') = SetColor c'
80diff_color (Just c) (Just c')
81 | c == c' = NoColorChange
82 | otherwise = SetColor c'
83diff_color Nothing Nothing = NoColorChange
84diff_color (Just _) Nothing = ColorToDefault
86diff_styles :: Style -> Style -> [StyleStateChange]
89 [ style_diff standout ApplyStandout RemoveStandout
90 , style_diff underline ApplyUnderline RemoveUnderline
91 , style_diff reverse_video ApplyReverseVideo RemoveReverseVideo
92 , style_diff blink ApplyBlink RemoveBlink
93 , style_diff dim ApplyDim RemoveDim
94 , style_diff bold ApplyBold RemoveBold
98 = case ( 0 == prev .&. s, 0 == cur .&. s ) of
102 ( False, False ) -> []
104 ( True, False) -> [ sm ]
106 ( False, True) -> [ rm ]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list