@@ -1,3 +1,4 @@
1+{-# LANGUAGE BangPatterns #-}
1module Graphics.Vty.AttributeChange ( module Graphics.Vty.AttributeChange
2module Graphics.Vty.AttributeChange ( module Graphics.Vty.AttributeChange
@@ -8,18 +9,63 @@ import Graphics.Vty.Terminal.Generic
9import Control.Monad.State.Strict
10import Control.Monad.State.Strict
12+import Data.Bits ( (.&.), complement )
13+import Data.Monoid ( mappend )
11type AttrChange v = State DisplayAttrDiff v
15type AttrChange v = State DisplayAttrDiff v
13back_color :: Color -> AttrChange ()
17back_color :: Color -> AttrChange ()
18+back_color c = modify $ flip mappend ( DisplayAttrDiff [] NoColorChange ( SetColor c ) )
20+fore_color :: Color -> AttrChange ()
14−back_color c = modify $ \ChangeState cs -> cs `mappend` [ DisplayAttrDiff [] NoColorChange ( SetTo c ) ]
21+fore_color c = modify $ flip mappend ( DisplayAttrDiff [] ( SetColor c ) NoColorChange )
23+apply_style :: Style -> AttrChange ()
24+apply_style s = modify $ flip mappend ( DisplayAttrDiff ( diff_for_apply_styles s )
16−style :: Style -> AttrChange ()
29+remove_style :: Style -> AttrChange ()
17−style s = modify $ \ChangeState cs -> cs `mappend` [ DisplayAttrDiff NoColorChange NoColorChange ]
30+remove_style s = modify $ flip mappend ( DisplayAttrDiff ( diff_for_remove_styles s )
35+diff_for_apply_styles :: Style -> [ StyleStateChange ]
36+diff_for_apply_styles !s
38+ | ( s .&. standout ) /= 0 = ApplyStandout : ( diff_for_apply_styles $! s .&. ( complement standout ) )
39+ | ( s .&. underline ) /= 0 = ApplyUnderline : ( diff_for_apply_styles $! s .&. ( complement underline ) )
40+ | ( s .&. reverse_video ) /= 0 = ApplyReverseVideo : ( diff_for_apply_styles $! s .&. ( complement reverse_video ) )
41+ | ( s .&. blink ) /= 0 = ApplyBlink : ( diff_for_apply_styles $! s .&. ( complement blink ) )
42+ | ( s .&. dim ) /= 0 = ApplyDim : ( diff_for_apply_styles $! s .&. ( complement dim ) )
43+ | ( s .&. bold ) /= 0 = ApplyBold : ( diff_for_apply_styles $! s .&. ( complement bold ) )
44+ | otherwise = error "diff_for_apply_styles: impossible style mask"
19−diff_styles :: Style -> Style -> [StyleStateChange]
46+diff_for_remove_styles :: Style -> [ StyleStateChange ]
47+diff_for_remove_styles !s
49+ | ( s .&. standout ) /= 0 = RemoveStandout : ( diff_for_remove_styles $! s .&. ( complement standout ) )
50+ | ( s .&. underline ) /= 0 = RemoveUnderline : ( diff_for_remove_styles $! s .&. ( complement underline ) )
51+ | ( s .&. reverse_video ) /= 0 = RemoveReverseVideo : ( diff_for_remove_styles $! s .&. ( complement reverse_video ) )
52+ | ( s .&. blink ) /= 0 = RemoveBlink : ( diff_for_remove_styles $! s .&. ( complement blink ) )
53+ | ( s .&. dim ) /= 0 = RemoveDim : ( diff_for_remove_styles $! s .&. ( complement dim ) )
54+ | ( s .&. bold ) /= 0 = RemoveBold : ( diff_for_remove_styles $! s .&. ( complement bold ) )
55+ | otherwise = error "diff_for_remove_styles: impossible style mask"
21default_all :: AttrChange ()
57default_all :: AttrChange ()
22−default_all = modify $ \ChangeState cs -> cs `mappend` [ DisplayAttrDiff remove_all_styles ColorToDefault ColorToDefault ]
58+default_all = modify $ flip mappend ( DisplayAttrDiff remove_all_styles ColorToDefault ColorToDefault )
60+remove_all_styles :: [ StyleStateChange ]
24put_attr_change :: TerminalHandle -> AttrChange () -> IO ()
70put_attr_change :: TerminalHandle -> AttrChange () -> IO ()
25put_attr_change t c = do
71put_attr_change t c = do