
module Color where

import Data.Word
import Text.ParserCombinators.Parsec
import Text.Printf

import Parse

data Color = Color Word8 Word8 Word8

red n = Color n 0x20 0x20
green n = Color 0x20 n 0x20
blue n = Color 0x20 0x20 n

formatColor (Color r g b) =
    printf "%02x%02x%02x" (toInteger r) (toInteger g) (toInteger b)

formatPair (a, b) = concat [a ++ "," ++ formatColor b]

colorPairs :: (String -> Color) -> IO ()
colorPairs f = do
    input <- getContents
    withParse parseCommaPairs input $ \pairs -> do
        let colorPair (a, b) = (a, f b)
        let printPair = putStrLn . formatPair
        sequence_ $ map (printPair . colorPair) pairs

