module Text.Chatty.Extended.Printer (ChExtendedPrinter(..),Tone(..),Colour(..),expandClr) where
import Text.Chatty.Printer
data Tone = Green | Red | Yellow | Blue | Black | White | Cyan | Magenta
data Colour = Dull Tone | Vivid Tone
class ChPrinter m => ChExtendedPrinter m where
ebracket :: Colour -> m a -> m a
ebracket c m = do estart c; a <- m; efin; return a
eprint :: Colour -> String -> m ()
eprint c = ebracket c . mprint
eprintLn :: Colour -> String -> m ()
eprintLn c s = eprint c s >> mprintLn ""
enomask :: Colour -> String -> m ()
enomask c = ebracket c . mnomask
enomaskLn :: Colour -> String -> m ()
enomaskLn c s = enomask c s >> mprintLn ""
estart :: Colour -> m ()
efin :: m ()
takeBrace 0 ('}':ss) = ""
takeBrace n ('}':ss) = '}' : takeBrace (n1) ss
takeBrace n ('{':ss) = '{' : takeBrace (n+1) ss
takeBrace n (s:ss) = s : takeBrace n ss
takeBrace n [] = ""
splitBrace ss = let nm = takeBrace 0 ss in (nm, drop (length nm + 1) ss)
procClr c ss = let (nm,rm) = splitBrace ss in ebracket c (expandClr nm) >> expandClr rm
expandClr :: ChExtendedPrinter m => String -> m ()
expandClr ('%':'{':'V':'0':';':ss) = procClr (Vivid Black) ss
expandClr ('%':'{':'V':'1':';':ss) = procClr (Vivid Red) ss
expandClr ('%':'{':'V':'2':';':ss) = procClr (Vivid Green) ss
expandClr ('%':'{':'V':'3':';':ss) = procClr (Vivid Yellow) ss
expandClr ('%':'{':'V':'4':';':ss) = procClr (Vivid Blue) ss
expandClr ('%':'{':'V':'5':';':ss) = procClr (Vivid Magenta) ss
expandClr ('%':'{':'V':'6':';':ss) = procClr (Vivid Cyan) ss
expandClr ('%':'{':'V':'7':';':ss) = procClr (Vivid White) ss
expandClr ('%':'{':'D':'0':';':ss) = procClr (Dull Black) ss
expandClr ('%':'{':'D':'1':';':ss) = procClr (Dull Red) ss
expandClr ('%':'{':'D':'2':';':ss) = procClr (Dull Green) ss
expandClr ('%':'{':'D':'3':';':ss) = procClr (Dull Yellow) ss
expandClr ('%':'{':'D':'4':';':ss) = procClr (Dull Blue) ss
expandClr ('%':'{':'D':'5':';':ss) = procClr (Dull Magenta) ss
expandClr ('%':'{':'D':'6':';':ss) = procClr (Dull Cyan) ss
expandClr ('%':'{':'D':'7':';':ss) = procClr (Dull White) ss
expandClr (s:ss) = mprint [s] >> expandClr ss
expandClr [] = return ()