on master help sign in
Add Generic and NFData instances for some types
commit612a091ee8e5bfdc2e82abf54a7e42e19bf93a96 authorJonathan Daugherty <cygnus@foobox.com> dateMon 27 Aug 2018, 16:04 (8 years ago) parent4953368
2 files changed+15−2
src/Graphics/Vty/Attributes.hs+10−1 src/Graphics/Vty/Attributes/Color.hs+5−1
src/Graphics/Vty/Attributes.hs+10−1
@@ -2,6 +2,8 @@
22{-# LANGUAGE StandaloneDeriving #-}
33{-# LANGUAGE GADTs #-}
44{-# LANGUAGE RankNTypes #-}
5+{-# LANGUAGE DeriveGeneric #-}
6+{-# LANGUAGE DeriveAnyClass #-}
57
68-- | Display attributes
79--
@@ -61,12 +63,14 @@ module Graphics.Vty.Attributes
6163 )
6264where
6365
66+import Control.DeepSeq
6467import Data.Bits
6568#if !(MIN_VERSION_base(4,11,0))
6669import Data.Semigroup
6770#endif
6871import Data.Text (Text)
6972import Data.Word
73+import GHC.Generics
7074
7175import Graphics.Vty.Attributes.Color
7276import Graphics.Vty.Attributes.Color240
@@ -83,7 +87,7 @@ data Attr = Attr
8387 , attrForeColor :: !(MaybeDefault Color)
8488 , attrBackColor :: !(MaybeDefault Color)
8589 , attrURL :: !(MaybeDefault Text)
86− } deriving ( Eq, Show, Read )
90+ } deriving ( Eq, Show, Read, Generic, NFData )
8791
8892-- This could be encoded into a single 32 bit word. The 32 bit word is
8993-- first divided into 4 groups of 8 bits where: The first group codes
@@ -149,6 +153,11 @@ data MaybeDefault v where
149153 KeepCurrent :: MaybeDefault v
150154 SetTo :: forall v . ( Eq v, Show v, Read v ) => !v -> MaybeDefault v
151155
156+instance (NFData v) => NFData (MaybeDefault v) where
157+ rnf Default = ()
158+ rnf KeepCurrent = ()
159+ rnf (SetTo v) = rnf v
160+
152161deriving instance Eq v => Eq (MaybeDefault v)
153162deriving instance Eq v => Show (MaybeDefault v)
154163deriving instance (Eq v, Show v, Read v) => Read (MaybeDefault v)
src/Graphics/Vty/Attributes/Color.hs+5−1
@@ -1,3 +1,5 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE DeriveAnyClass #-}
13module Graphics.Vty.Attributes.Color
24 ( Color(..)
35 , black
@@ -20,6 +22,8 @@ module Graphics.Vty.Attributes.Color
2022where
2123
2224import Data.Word
25+import GHC.Generics
26+import Control.DeepSeq
2327
2428-- | Abstract data type representing a color.
2529--
@@ -74,7 +78,7 @@ import Data.Word
7478--
7579-- Seriously, terminal color support is INSANE.
7680data Color = ISOColor !Word8 | Color240 !Word8
77− deriving ( Eq, Show, Read )
81+ deriving ( Eq, Show, Read, Generic, NFData )
7882
7983-- | Standard 8-color ANSI terminal color codes.
8084black, red, green, yellow, blue, magenta, cyan, white :: Color