module Rainbow.Colors where
import Rainbow.Types
import Data.Monoid
import Data.Word (Word8)
noColor8 :: Color8
noColor8 = Color8 Nothing
black8 :: Color8
black8 = Color8 (Just E0)
red8 :: Color8
red8 = Color8 (Just E1)
green8 :: Color8
green8 = Color8 (Just E2)
yellow8 :: Color8
yellow8 = Color8 (Just E3)
blue8 :: Color8
blue8 = Color8 (Just E4)
magenta8 :: Color8
magenta8 = Color8 (Just E5)
cyan8 :: Color8
cyan8 = Color8 (Just E6)
white8 :: Color8
white8 = Color8 (Just E7)
noColor256 :: Color256
noColor256 = Color256 Nothing
grey :: Color256
grey = Color256 (Just 8)
brightRed :: Color256
brightRed = Color256 (Just 9)
brightGreen :: Color256
brightGreen = Color256 (Just 10)
brightYellow :: Color256
brightYellow = Color256 (Just 11)
brightBlue :: Color256
brightBlue = Color256 (Just 12)
brightMagenta :: Color256
brightMagenta = Color256 (Just 13)
brightCyan :: Color256
brightCyan = Color256 (Just 14)
brightWhite :: Color256
brightWhite = Color256 (Just 15)
newtype Both = Both Color8
deriving (Eq, Ord, Show)
both :: Color8 -> Both
both = Both
black :: Both
black = both black8
red :: Both
red = both red8
green :: Both
green = both green8
yellow :: Both
yellow = both yellow8
blue :: Both
blue = both blue8
magenta :: Both
magenta = both magenta8
cyan :: Both
cyan = both cyan8
white :: Both
white = both white8
class Color a where
back :: a -> Chunk
fore :: a -> Chunk
instance Color Color8 where
back c = Chunk ts []
where
ts = TextSpec s8 mempty
s8 = Style8 mempty b8 mempty
b8 = Last (Just c)
fore c = Chunk ts []
where
ts = TextSpec s8 mempty
s8 = Style8 f8 mempty mempty
f8 = Last (Just c)
instance Color Color256 where
back c = Chunk ts []
where
ts = TextSpec mempty s256
s256 = Style256 mempty b256 mempty
b256 = Last (Just c)
fore c = Chunk ts []
where
ts = TextSpec mempty s256
s256 = Style256 f256 mempty mempty
f256 = Last (Just c)
instance Color Both where
fore (Both c) = fore c <> fore (to256 c)
back (Both c) = back c <> back (to256 c)
instance Color Enum8 where
back = back . Color8 . Just
fore = fore . Color8 . Just
instance Color Word8 where
back = back . Color256 . Just
fore = fore . Color256 . Just