Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (37 sloc) 1.018 kB
{-|
Stability : provisional
Portability : haskell98
Simplistic ANSI color support.
-}
module AnsiColor
( Color(..)
, bold
, inColor
) where
import Data.List
data Color = Black
| Red
| Green
| Yellow
| Blue
| Magenta
| Cyan
| White
| Default
deriving Enum
esc :: [String] -> String
esc [] = ""
esc xs = "\ESC[" ++ (concat . intersperse ";" $ xs) ++ "m"
col :: Color -> Bool -> Color -> [String]
col fg bf bg = show (fromEnum fg + 30) : bf' [show (fromEnum bg + 40)]
where bf' | bf = ("01" :)
| otherwise = id
inColor :: Color -> Bool -> Color -> String -> String
inColor c bf bg txt = esc (col c bf bg) ++ txt ++ esc ["00"]
bold :: String -> String
bold = ansi "1" "22"
-- italic = ansi "3" "23"
-- underline = ansi "4" "24"
-- inverse = ansi "7" "27"
ansi :: String -> String -> String -> String
ansi on off txt = esc [on] ++ txt ++ esc [off]
Jump to Line
Something went wrong with that request. Please try again.