{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Text.Pretty.Simple.Internal.Color
where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Data.Text.Lazy.Builder (Builder, fromString)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import System.Console.ANSI
(Color(..), ColorIntensity(..), ConsoleIntensity(..),
ConsoleLayer(..), SGR(..), setSGRCode)
data ColorOptions = ColorOptions
{ colorQuote :: Builder
, colorString :: Builder
, colorError :: Builder
, colorNum :: Builder
, colorRainbowParens :: [Builder]
} deriving (Eq, Generic, Show, Typeable)
defaultColorOptionsDarkBg :: ColorOptions
defaultColorOptionsDarkBg =
ColorOptions
{ colorQuote = defaultColorQuoteDarkBg
, colorString = defaultColorStringDarkBg
, colorError = defaultColorErrorDarkBg
, colorNum = defaultColorNumDarkBg
, colorRainbowParens = defaultColorRainbowParensDarkBg
}
defaultColorQuoteDarkBg :: Builder
defaultColorQuoteDarkBg = colorVividWhiteBold
defaultColorStringDarkBg :: Builder
defaultColorStringDarkBg = colorVividBlueBold
defaultColorErrorDarkBg :: Builder
defaultColorErrorDarkBg = colorVividRedBold
defaultColorNumDarkBg :: Builder
defaultColorNumDarkBg = colorVividGreenBold
defaultColorRainbowParensDarkBg :: [Builder]
defaultColorRainbowParensDarkBg =
[ colorVividMagentaBold
, colorVividCyanBold
, colorVividYellowBold
, colorDullMagenta
, colorDullCyan
, colorDullYellow
, colorDullMagentaBold
, colorDullCyanBold
, colorDullYellowBold
, colorVividMagenta
, colorVividCyan
, colorVividYellow
]
defaultColorOptionsLightBg :: ColorOptions
defaultColorOptionsLightBg =
ColorOptions
{ colorQuote = defaultColorQuoteLightBg
, colorString = defaultColorStringLightBg
, colorError = defaultColorErrorLightBg
, colorNum = defaultColorNumLightBg
, colorRainbowParens = defaultColorRainbowParensLightBg
}
defaultColorQuoteLightBg :: Builder
defaultColorQuoteLightBg = colorVividBlackBold
defaultColorStringLightBg :: Builder
defaultColorStringLightBg = colorVividBlueBold
defaultColorErrorLightBg :: Builder
defaultColorErrorLightBg = colorVividRedBold
defaultColorNumLightBg :: Builder
defaultColorNumLightBg = colorVividGreenBold
defaultColorRainbowParensLightBg :: [Builder]
defaultColorRainbowParensLightBg =
[ colorVividMagentaBold
, colorVividCyanBold
, colorDullMagenta
, colorDullCyan
, colorDullMagentaBold
, colorDullCyanBold
, colorVividMagenta
, colorVividCyan
]
colorVividBlackBold :: Builder
colorVividBlackBold = colorBold `mappend` colorVividBlack
colorVividBlueBold :: Builder
colorVividBlueBold = colorBold `mappend` colorVividBlue
colorVividCyanBold :: Builder
colorVividCyanBold = colorBold `mappend` colorVividCyan
colorVividGreenBold :: Builder
colorVividGreenBold = colorBold `mappend` colorVividGreen
colorVividMagentaBold :: Builder
colorVividMagentaBold = colorBold `mappend` colorVividMagenta
colorVividRedBold :: Builder
colorVividRedBold = colorBold `mappend` colorVividRed
colorVividWhiteBold :: Builder
colorVividWhiteBold = colorBold `mappend` colorVividWhite
colorVividYellowBold :: Builder
colorVividYellowBold = colorBold `mappend` colorVividYellow
colorDullBlackBold :: Builder
colorDullBlackBold = colorBold `mappend` colorDullBlack
colorDullBlueBold :: Builder
colorDullBlueBold = colorBold `mappend` colorDullBlue
colorDullCyanBold :: Builder
colorDullCyanBold = colorBold `mappend` colorDullCyan
colorDullGreenBold :: Builder
colorDullGreenBold = colorBold `mappend` colorDullGreen
colorDullMagentaBold :: Builder
colorDullMagentaBold = colorBold `mappend` colorDullMagenta
colorDullRedBold :: Builder
colorDullRedBold = colorBold `mappend` colorDullRed
colorDullWhiteBold :: Builder
colorDullWhiteBold = colorBold `mappend` colorDullWhite
colorDullYellowBold :: Builder
colorDullYellowBold = colorBold `mappend` colorDullYellow
colorVividBlack :: Builder
colorVividBlack = colorHelper Vivid Black
colorVividBlue :: Builder
colorVividBlue = colorHelper Vivid Blue
colorVividCyan :: Builder
colorVividCyan = colorHelper Vivid Cyan
colorVividGreen :: Builder
colorVividGreen = colorHelper Vivid Green
colorVividMagenta :: Builder
colorVividMagenta = colorHelper Vivid Magenta
colorVividRed :: Builder
colorVividRed = colorHelper Vivid Red
colorVividWhite :: Builder
colorVividWhite = colorHelper Vivid White
colorVividYellow :: Builder
colorVividYellow = colorHelper Vivid Yellow
colorDullBlack :: Builder
colorDullBlack = colorHelper Dull Black
colorDullBlue :: Builder
colorDullBlue = colorHelper Dull Blue
colorDullCyan :: Builder
colorDullCyan = colorHelper Dull Cyan
colorDullGreen :: Builder
colorDullGreen = colorHelper Dull Green
colorDullMagenta :: Builder
colorDullMagenta = colorHelper Dull Magenta
colorDullRed :: Builder
colorDullRed = colorHelper Dull Red
colorDullWhite :: Builder
colorDullWhite = colorHelper Dull White
colorDullYellow :: Builder
colorDullYellow = colorHelper Dull Yellow
colorBold :: Builder
colorBold = setSGRCodeBuilder [SetConsoleIntensity BoldIntensity]
colorReset :: Builder
colorReset = setSGRCodeBuilder [Reset]
colorNull :: Builder
colorNull = ""
colorHelper :: ColorIntensity -> Color -> Builder
colorHelper colorIntensity color =
setSGRCodeBuilder [SetColor Foreground colorIntensity color]
setSGRCodeBuilder :: [SGR] -> Builder
setSGRCodeBuilder = fromString . setSGRCode