{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
module Graphics.Vty.Attributes
( module Graphics.Vty.Attributes.Color
, Attr(..)
, FixedAttr(..)
, MaybeDefault(..)
, defAttr
, currentAttr
, Style
, withStyle
, standout
, italic
, strikethrough
, underline
, reverseVideo
, blink
, dim
, bold
, defaultStyleMask
, styleMask
, hasStyle
, withForeColor
, withBackColor
, withURL
)
where
import Control.DeepSeq
import Data.Bits
import Data.Text (Text)
import Data.Word
import GHC.Generics
import Graphics.Vty.Attributes.Color
data Attr = Attr
{ Attr -> MaybeDefault Style
attrStyle :: !(MaybeDefault Style)
, Attr -> MaybeDefault Color
attrForeColor :: !(MaybeDefault Color)
, Attr -> MaybeDefault Color
attrBackColor :: !(MaybeDefault Color)
, Attr -> MaybeDefault Text
attrURL :: !(MaybeDefault Text)
} deriving ( Attr -> Attr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attr -> Attr -> Bool
$c/= :: Attr -> Attr -> Bool
== :: Attr -> Attr -> Bool
$c== :: Attr -> Attr -> Bool
Eq, Int -> Attr -> ShowS
[Attr] -> ShowS
Attr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attr] -> ShowS
$cshowList :: [Attr] -> ShowS
show :: Attr -> String
$cshow :: Attr -> String
showsPrec :: Int -> Attr -> ShowS
$cshowsPrec :: Int -> Attr -> ShowS
Show, ReadPrec [Attr]
ReadPrec Attr
Int -> ReadS Attr
ReadS [Attr]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Attr]
$creadListPrec :: ReadPrec [Attr]
readPrec :: ReadPrec Attr
$creadPrec :: ReadPrec Attr
readList :: ReadS [Attr]
$creadList :: ReadS [Attr]
readsPrec :: Int -> ReadS Attr
$creadsPrec :: Int -> ReadS Attr
Read, forall x. Rep Attr x -> Attr
forall x. Attr -> Rep Attr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Attr x -> Attr
$cfrom :: forall x. Attr -> Rep Attr x
Generic, Attr -> ()
forall a. (a -> ()) -> NFData a
rnf :: Attr -> ()
$crnf :: Attr -> ()
NFData )
data FixedAttr = FixedAttr
{ FixedAttr -> Style
fixedStyle :: !Style
, FixedAttr -> Maybe Color
fixedForeColor :: !(Maybe Color)
, FixedAttr -> Maybe Color
fixedBackColor :: !(Maybe Color)
, FixedAttr -> Maybe Text
fixedURL :: !(Maybe Text)
} deriving ( FixedAttr -> FixedAttr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FixedAttr -> FixedAttr -> Bool
$c/= :: FixedAttr -> FixedAttr -> Bool
== :: FixedAttr -> FixedAttr -> Bool
$c== :: FixedAttr -> FixedAttr -> Bool
Eq, Int -> FixedAttr -> ShowS
[FixedAttr] -> ShowS
FixedAttr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FixedAttr] -> ShowS
$cshowList :: [FixedAttr] -> ShowS
show :: FixedAttr -> String
$cshow :: FixedAttr -> String
showsPrec :: Int -> FixedAttr -> ShowS
$cshowsPrec :: Int -> FixedAttr -> ShowS
Show )
data MaybeDefault v = Default | KeepCurrent | SetTo !v
deriving (MaybeDefault v -> MaybeDefault v -> Bool
forall v. Eq v => MaybeDefault v -> MaybeDefault v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaybeDefault v -> MaybeDefault v -> Bool
$c/= :: forall v. Eq v => MaybeDefault v -> MaybeDefault v -> Bool
== :: MaybeDefault v -> MaybeDefault v -> Bool
$c== :: forall v. Eq v => MaybeDefault v -> MaybeDefault v -> Bool
Eq, ReadPrec [MaybeDefault v]
ReadPrec (MaybeDefault v)
ReadS [MaybeDefault v]
forall v. Read v => ReadPrec [MaybeDefault v]
forall v. Read v => ReadPrec (MaybeDefault v)
forall v. Read v => Int -> ReadS (MaybeDefault v)
forall v. Read v => ReadS [MaybeDefault v]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MaybeDefault v]
$creadListPrec :: forall v. Read v => ReadPrec [MaybeDefault v]
readPrec :: ReadPrec (MaybeDefault v)
$creadPrec :: forall v. Read v => ReadPrec (MaybeDefault v)
readList :: ReadS [MaybeDefault v]
$creadList :: forall v. Read v => ReadS [MaybeDefault v]
readsPrec :: Int -> ReadS (MaybeDefault v)
$creadsPrec :: forall v. Read v => Int -> ReadS (MaybeDefault v)
Read, Int -> MaybeDefault v -> ShowS
forall v. Show v => Int -> MaybeDefault v -> ShowS
forall v. Show v => [MaybeDefault v] -> ShowS
forall v. Show v => MaybeDefault v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaybeDefault v] -> ShowS
$cshowList :: forall v. Show v => [MaybeDefault v] -> ShowS
show :: MaybeDefault v -> String
$cshow :: forall v. Show v => MaybeDefault v -> String
showsPrec :: Int -> MaybeDefault v -> ShowS
$cshowsPrec :: forall v. Show v => Int -> MaybeDefault v -> ShowS
Show)
instance (NFData v) => NFData (MaybeDefault v) where
rnf :: MaybeDefault v -> ()
rnf MaybeDefault v
Default = ()
rnf MaybeDefault v
KeepCurrent = ()
rnf (SetTo v
v) = forall a. NFData a => a -> ()
rnf v
v
type Style = Word8
standout, underline, reverseVideo, blink, dim, bold, italic, strikethrough :: Style
standout :: Style
standout = Style
0x01
underline :: Style
underline = Style
0x02
reverseVideo :: Style
reverseVideo = Style
0x04
blink :: Style
blink = Style
0x08
dim :: Style
dim = Style
0x10
bold :: Style
bold = Style
0x20
italic :: Style
italic = Style
0x40
strikethrough :: Style
strikethrough = Style
0x80
defaultStyleMask :: Style
defaultStyleMask :: Style
defaultStyleMask = Style
0x00
styleMask :: Attr -> Word8
styleMask :: Attr -> Style
styleMask Attr
attr
= case Attr -> MaybeDefault Style
attrStyle Attr
attr of
MaybeDefault Style
Default -> Style
0
MaybeDefault Style
KeepCurrent -> Style
0
SetTo Style
v -> Style
v
hasStyle :: Style -> Style -> Bool
hasStyle :: Style -> Style -> Bool
hasStyle Style
s Style
bitMask = ( Style
s forall a. Bits a => a -> a -> a
.&. Style
bitMask ) forall a. Eq a => a -> a -> Bool
/= Style
0
withForeColor :: Attr -> Color -> Attr
withForeColor :: Attr -> Color -> Attr
withForeColor Attr
attr Color
c = Attr
attr { attrForeColor :: MaybeDefault Color
attrForeColor = forall v. v -> MaybeDefault v
SetTo Color
c }
withBackColor :: Attr -> Color -> Attr
withBackColor :: Attr -> Color -> Attr
withBackColor Attr
attr Color
c = Attr
attr { attrBackColor :: MaybeDefault Color
attrBackColor = forall v. v -> MaybeDefault v
SetTo Color
c }
withStyle :: Attr -> Style -> Attr
withStyle :: Attr -> Style -> Attr
withStyle Attr
attr Style
0 = Attr
attr
withStyle Attr
attr Style
styleFlag = Attr
attr { attrStyle :: MaybeDefault Style
attrStyle = forall v. v -> MaybeDefault v
SetTo forall a b. (a -> b) -> a -> b
$ Attr -> Style
styleMask Attr
attr forall a. Bits a => a -> a -> a
.|. Style
styleFlag }
withURL :: Attr -> Text -> Attr
withURL :: Attr -> Text -> Attr
withURL Attr
attr Text
url = Attr
attr { attrURL :: MaybeDefault Text
attrURL = forall v. v -> MaybeDefault v
SetTo Text
url }
defAttr :: Attr
defAttr :: Attr
defAttr = MaybeDefault Style
-> MaybeDefault Color
-> MaybeDefault Color
-> MaybeDefault Text
-> Attr
Attr forall v. MaybeDefault v
Default forall v. MaybeDefault v
Default forall v. MaybeDefault v
Default forall v. MaybeDefault v
Default
currentAttr :: Attr
currentAttr :: Attr
currentAttr = MaybeDefault Style
-> MaybeDefault Color
-> MaybeDefault Color
-> MaybeDefault Text
-> Attr
Attr forall v. MaybeDefault v
KeepCurrent forall v. MaybeDefault v
KeepCurrent forall v. MaybeDefault v
KeepCurrent forall v. MaybeDefault v
KeepCurrent