From 5617cceee21283e52ffdd2cad3b3604e3ee6a257 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 19 Nov 2015 23:07:43 -0800 Subject: [PATCH] Format strings with attributes. --- src/Console.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Console.hs b/src/Console.hs index ccb4e9864..99fe0dbbd 100644 --- a/src/Console.hs +++ b/src/Console.hs @@ -1,5 +1,7 @@ module Console where +import Data.Char + data Colour = Black | Red | Green | Yellow | Blue | Purple | Cyan | White deriving Bounded @@ -36,3 +38,6 @@ instance Enum Style where toEnum 4 = Underline data Attribute = Attribute { colour :: Colour, style :: Style } + +applyAttribute :: Attribute -> String -> String +applyAttribute attribute string = "\x001b[" ++ [ chr . fromEnum $ style attribute ] ++ ";" ++ [ chr . fromEnum $ colour attribute ] ++ "m" ++ string ++ "\x001b[0m"