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 _cd ColorToDefault = ColorToDefault
46simplify_color_diffs cd NoColorChange = cd
47simplify_color_diffs _cd ( SetColor !c ) = SetColor c
70display_attr_diffs :: FixedAttr -> FixedAttr -> DisplayAttrDiff
71display_attr_diffs attr attr' = DisplayAttrDiff
72 { style_diffs = diff_styles ( fixed_style attr ) ( fixed_style attr' )
73 , fore_color_diff = diff_color ( fixed_fore_color attr ) ( fixed_fore_color attr' )
74 , back_color_diff = diff_color ( fixed_back_color attr ) ( fixed_back_color attr' )
77diff_color :: Maybe Color -> Maybe Color -> DisplayColorDiff
78diff_color Nothing (Just c') = SetColor c'
79diff_color (Just c) (Just c')
80 | c == c' = NoColorChange
81 | otherwise = SetColor c'
82diff_color Nothing Nothing = NoColorChange
83diff_color (Just _) Nothing = ColorToDefault
85diff_styles :: Style -> Style -> [StyleStateChange]
88 [ style_diff standout ApplyStandout RemoveStandout
89 , style_diff underline ApplyUnderline RemoveUnderline
90 , style_diff reverse_video ApplyReverseVideo RemoveReverseVideo
91 , style_diff blink ApplyBlink RemoveBlink
92 , style_diff dim ApplyDim RemoveDim
93 , style_diff bold ApplyBold RemoveBold
97 = case ( 0 == prev .&. s, 0 == cur .&. s ) of
101 ( False, False ) -> []
103 ( True, False) -> [ sm ]
105 ( 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