{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Core.Text.Colour
( AnsiColour
, intoEscapes
, boldColour
, dullRed
, brightRed
, pureRed
, dullGreen
, brightGreen
, pureGreen
, dullBlue
, brightBlue
, pureBlue
, dullCyan
, brightCyan
, pureCyan
, dullMagenta
, brightMagenta
, pureMagenta
, dullYellow
, brightYellow
, pureYellow
, pureBlack
, dullGrey
, brightGrey
, pureGrey
, pureWhite
, dullWhite
, brightWhite
, resetColour
) where
import Core.Text.Rope
import Data.Colour.SRGB (sRGB, sRGB24read)
import System.Console.ANSI.Codes (setSGRCode)
import System.Console.ANSI.Types (ConsoleIntensity (..), ConsoleLayer (..), SGR (..))
newtype AnsiColour = Escapes [SGR]
intoEscapes :: AnsiColour -> Rope
intoEscapes :: AnsiColour -> Rope
intoEscapes (Escapes [SGR]
codes) = forall α. Textual α => α -> Rope
intoRope ([SGR] -> String
setSGRCode [SGR]
codes)
dullRed :: AnsiColour
dullRed :: AnsiColour
dullRed =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#CC0000")]
brightRed :: AnsiColour
brightRed :: AnsiColour
brightRed =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#EF2929")]
pureRed :: AnsiColour
pureRed :: AnsiColour
pureRed =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
1 Float
0 Float
0)]
dullGreen :: AnsiColour
dullGreen :: AnsiColour
dullGreen =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#4E9A06")]
brightGreen :: AnsiColour
brightGreen :: AnsiColour
brightGreen =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#8AE234")]
pureGreen :: AnsiColour
pureGreen :: AnsiColour
pureGreen =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
0 Float
1 Float
0)]
dullBlue :: AnsiColour
dullBlue :: AnsiColour
dullBlue =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#3465A4")]
brightBlue :: AnsiColour
brightBlue :: AnsiColour
brightBlue =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#729FCF")]
pureBlue :: AnsiColour
pureBlue :: AnsiColour
pureBlue =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
0 Float
0 Float
1)]
dullCyan :: AnsiColour
dullCyan :: AnsiColour
dullCyan =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#06989A")]
brightCyan :: AnsiColour
brightCyan :: AnsiColour
brightCyan =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#34E2E2")]
pureCyan :: AnsiColour
pureCyan :: AnsiColour
pureCyan =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
0 Float
1 Float
1)]
dullMagenta :: AnsiColour
dullMagenta :: AnsiColour
dullMagenta =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#75507B")]
brightMagenta :: AnsiColour
brightMagenta :: AnsiColour
brightMagenta =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#AD7FA8")]
pureMagenta :: AnsiColour
pureMagenta :: AnsiColour
pureMagenta =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
1 Float
0 Float
1)]
dullYellow :: AnsiColour
dullYellow :: AnsiColour
dullYellow =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#C4A000")]
brightYellow :: AnsiColour
brightYellow :: AnsiColour
brightYellow =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#FCE94F")]
pureYellow :: AnsiColour
pureYellow :: AnsiColour
pureYellow =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
1 Float
1 Float
0)]
pureBlack :: AnsiColour
pureBlack :: AnsiColour
pureBlack =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
0 Float
0 Float
0)]
dullGrey :: AnsiColour
dullGrey :: AnsiColour
dullGrey =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#2E3436")]
brightGrey :: AnsiColour
brightGrey :: AnsiColour
brightGrey =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#555753")]
pureGrey :: AnsiColour
pureGrey :: AnsiColour
pureGrey =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#999999")]
pureWhite :: AnsiColour
pureWhite :: AnsiColour
pureWhite =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => b -> b -> b -> Colour b
sRGB Float
1 Float
1 Float
1)]
dullWhite :: AnsiColour
dullWhite :: AnsiColour
dullWhite =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#D3D7CF")]
brightWhite :: AnsiColour
brightWhite :: AnsiColour
brightWhite =
[SGR] -> AnsiColour
Escapes [ConsoleLayer -> Colour Float -> SGR
SetRGBColor ConsoleLayer
Foreground (forall b. (Ord b, Floating b) => String -> Colour b
sRGB24read String
"#EEEEEC")]
boldColour :: AnsiColour -> AnsiColour
boldColour :: AnsiColour -> AnsiColour
boldColour (Escapes [SGR]
list) =
[SGR] -> AnsiColour
Escapes (ConsoleIntensity -> SGR
SetConsoleIntensity ConsoleIntensity
BoldIntensity forall a. a -> [a] -> [a]
: [SGR]
list)
instance Semigroup AnsiColour where
<> :: AnsiColour -> AnsiColour -> AnsiColour
(<>) (Escapes [SGR]
list1) (Escapes [SGR]
list2) = [SGR] -> AnsiColour
Escapes ([SGR]
list1 forall a. Semigroup a => a -> a -> a
<> [SGR]
list2)
instance Monoid AnsiColour where
mempty :: AnsiColour
mempty = [SGR] -> AnsiColour
Escapes []
resetColour :: AnsiColour
resetColour :: AnsiColour
resetColour =
[SGR] -> AnsiColour
Escapes [SGR
Reset]