module Rainbow.Colors where
import Data.Maybe (fromMaybe)
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)
data Radiant = Radiant
{ rad8 :: Color8
, rad256 :: Maybe Color256
} deriving (Eq, Ord, Show)
both :: Color8 -> Radiant
both c8 = Radiant c8 Nothing
black :: Radiant
black = both black8
red :: Radiant
red = both red8
green :: Radiant
green = both green8
yellow :: Radiant
yellow = both yellow8
blue :: Radiant
blue = both blue8
magenta :: Radiant
magenta = both magenta8
cyan :: Radiant
cyan = both cyan8
white :: Radiant
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 Radiant where
fore (Radiant c8 mc256) = fore c8
<> fore (fromMaybe (to256 c8) mc256)
back (Radiant c8 mc256) = back c8
<> back (fromMaybe (to256 c8) mc256)
instance Color Enum8 where
back = back . Color8 . Just
fore = fore . Color8 . Just
instance Color Word8 where
back = back . Color256 . Just
fore = fore . Color256 . Just