1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00
semantic/app/Console.hs

44 lines
1.0 KiB
Haskell
Raw Normal View History

2015-11-20 04:39:21 +03:00
module Console where
2015-11-20 05:00:03 +03:00
2015-11-20 10:07:43 +03:00
import Data.Char
2015-11-20 05:00:03 +03:00
data Colour = Black | Red | Green | Yellow | Blue | Purple | Cyan | White
2015-11-20 05:01:50 +03:00
deriving Bounded
2015-11-20 05:01:56 +03:00
instance Enum Colour where
fromEnum Black = 30
fromEnum Red = 31
fromEnum Green = 32
fromEnum Yellow = 33
fromEnum Blue = 34
fromEnum Purple = 35
fromEnum Cyan = 36
fromEnum White = 37
toEnum 30 = Black
toEnum 31 = Red
toEnum 32 = Green
toEnum 33 = Yellow
toEnum 34 = Blue
toEnum 35 = Purple
toEnum 36 = Cyan
toEnum 37 = White
toEnum _ = error "unknown colour code"
2015-11-20 05:02:02 +03:00
data Style = Normal | Bold | Underline
2015-11-20 05:02:11 +03:00
deriving Bounded
2015-11-20 05:02:21 +03:00
instance Enum Style where
fromEnum Normal = 0
fromEnum Bold = 1
fromEnum Underline = 4
toEnum 0 = Normal
toEnum 1 = Bold
toEnum 4 = Underline
data Attribute = Attribute { colour :: Colour, style :: Style }
2015-11-20 10:07:43 +03:00
applyAttribute :: Attribute -> String -> String
applyAttribute attribute string = "\x001b[" ++ [ chr . fromEnum $ style attribute ] ++ ";" ++ [ chr . fromEnum $ colour attribute ] ++ "m" ++ string ++ "\x001b[0m"