module Termbox.Attr
( Attr,
black,
blue,
bold,
cyan,
green,
magenta,
red,
reverse,
underline,
white,
yellow,
attrToWord,
wordToAttr,
)
where
import Data.Bits ((.&.), (.|.))
import Data.Semigroup (Semigroup (..))
import Data.Word (Word16)
import Termbox.Internal
import Prelude hiding (reverse)
data Attr
= Attr !Word16 !Word16
deriving (Eq, Show)
instance Monoid Attr where
mempty :: Attr
mempty =
Attr tB_DEFAULT 0
mappend :: Attr -> Attr -> Attr
mappend =
(<>)
instance Num Attr where
fromInteger :: Integer -> Attr
fromInteger n =
Attr (fromIntegral (n `rem` 256)) 0
(+) = (<>)
(*) = (<>)
(-) = (<>)
abs = id
signum = id
instance Semigroup Attr where
(<>) :: Attr -> Attr -> Attr
Attr 0 ax <> Attr cy ay = Attr cy (ax .|. ay)
Attr cx ax <> Attr 0 ay = Attr cx (ax .|. ay)
Attr _ ax <> Attr cy ay = Attr cy (ax .|. ay)
wordToAttr :: Word16 -> Attr
wordToAttr w =
Attr (w .&. 0x00FF) (w .&. 0xFF00)
attrToWord :: Attr -> Word16
attrToWord (Attr x y) =
x .|. y
black :: Attr
black =
Attr tB_BLACK 0
red :: Attr
red =
Attr tB_RED 0
green :: Attr
green =
Attr tB_GREEN 0
yellow :: Attr
yellow =
Attr tB_YELLOW 0
blue :: Attr
blue =
Attr tB_BLUE 0
magenta :: Attr
magenta =
Attr tB_MAGENTA 0
cyan :: Attr
cyan =
Attr tB_CYAN 0
white :: Attr
white =
Attr tB_WHITE 0
bold :: Attr
bold =
Attr tB_DEFAULT tB_BOLD
underline :: Attr
underline =
Attr tB_DEFAULT tB_UNDERLINE
reverse :: Attr
reverse =
Attr tB_DEFAULT tB_REVERSE