@@ -15,15 +15,14 @@ import Graphics.Vty.Picture
1515import Graphics.Vty.Span
1616import Graphics.Vty.DisplayRegion
1717
18+import Graphics.Vty.DisplayAttributes
19+
1820import Control.Monad ( liftM )
19−import Control.Monad.Trans
2021
2122import Data.Array
22−import Data.Bits ( (.&.) )
2323import qualified Data.ByteString.Internal as BSCore
2424import Data.Foldable
2525import Data.IORef
26−import Data.Monoid ( mconcat )
2726import Data.Word
2827import Data.String.UTF8 hiding ( foldl )
2928
@@ -334,86 +333,6 @@ marshall_to_terminal t c f = do
334333 free start_ptr
335334 return ()
336335
337−
338−-- | Given the previously applied display attributes as a FixedAttr and the current display
339−-- attributes as an Attr produces a FixedAttr that represents the current display attributes. This
340−-- is done by using the previously applied display attributes to remove the "KeepCurrent"
341−-- abstraction.
342−fix_display_attr :: FixedAttr -> Attr -> FixedAttr
343−fix_display_attr fattr attr
344− = FixedAttr ( fix_style (fixed_style fattr) (attr_style attr) )
345− ( fix_color (fixed_fore_color fattr) (attr_fore_color attr) )
346− ( fix_color (fixed_back_color fattr) (attr_back_color attr) )
347− where
348− fix_style _s Default = default_style_mask
349− fix_style s KeepCurrent = s
350− fix_style _s (SetTo new_style) = new_style
351− fix_color _c Default = Nothing
352− fix_color c KeepCurrent = c
353− fix_color _c (SetTo c) = Just c
354−
355−data DisplayAttrDiffs = DisplayAttrDiffs
356− { style_diffs :: [ StyleStateChange ]
357− , fore_color_diff :: DisplayColorDiff
358− , back_color_diff :: DisplayColorDiff
359− }
360−
361−data DisplayColorDiff
362− = ColorToDefault
363− | NoColorChange
364− | SetColor !Color
365− deriving Eq
366−
367−data StyleStateChange
368− = ApplyStandout
369− | RemoveStandout
370− | ApplyUnderline
371− | RemoveUnderline
372− | ApplyReverseVideo
373− | RemoveReverseVideo
374− | ApplyBlink
375− | RemoveBlink
376− | ApplyDim
377− | RemoveDim
378− | ApplyBold
379− | RemoveBold
380−
381−display_attr_diffs :: FixedAttr -> FixedAttr -> DisplayAttrDiffs
382−display_attr_diffs attr attr' = DisplayAttrDiffs
383− { style_diffs = diff_styles ( fixed_style attr ) ( fixed_style attr' )
384− , fore_color_diff = diff_color ( fixed_fore_color attr ) ( fixed_fore_color attr' )
385− , back_color_diff = diff_color ( fixed_back_color attr ) ( fixed_back_color attr' )
386− }
387−
388−diff_color Nothing (Just c') = SetColor c'
389−diff_color (Just c) (Just c')
390− | c == c' = NoColorChange
391− | otherwise = SetColor c'
392−diff_color Nothing Nothing = NoColorChange
393−diff_color (Just _) Nothing = ColorToDefault
394−
395−diff_styles :: Style -> Style -> [StyleStateChange]
396−diff_styles prev cur
397− = mconcat
398− [ style_diff standout ApplyStandout RemoveStandout
399− , style_diff underline ApplyUnderline RemoveUnderline
400− , style_diff reverse_video ApplyReverseVideo RemoveReverseVideo
401− , style_diff blink ApplyBlink RemoveBlink
402− , style_diff dim ApplyDim RemoveDim
403− , style_diff bold ApplyBold RemoveBold
404− ]
405− where
406− style_diff s sm rm
407− = case ( 0 == prev .&. s, 0 == cur .&. s ) of
408− -- not set in either
409− ( True, True ) -> []
410− -- set in both
411− ( False, False ) -> []
412− -- now set
413− ( True, False) -> [ sm ]
414− -- now unset
415− ( False, True) -> [ rm ]
416−
417336data CursorOutputMap = CursorOutputMap
418337 { char_to_output_pos :: (Word, Word) -> (Word, Word)
419338 }