module Colourista.Pure
( formatWith
, red
, green
, blue
, yellow
, black
, white
, magenta
, cyan
, redBg
, greenBg
, blueBg
, yellowBg
, blackBg
, whiteBg
, magentaBg
, cyanBg
, bold
, italic
, underline
, doubleUnderline
, noUnderline
, indent
, reset
) where
import Data.ByteString (ByteString)
import Data.List.NonEmpty (NonEmpty (..))
import Data.Semigroup (Semigroup (..))
import Data.String (IsString (..))
import Data.Text (Text)
import System.Console.ANSI (Color (..), ColorIntensity (Vivid), ConsoleIntensity (BoldIntensity),
ConsoleLayer (Background, Foreground), SGR (..), Underlining (..),
setSGRCode)
formatWith
:: (IsString str, Semigroup str)
=> [str]
-> str
-> str
formatWith :: [str] -> str -> str
formatWith [str]
formatting str
str = case [str]
formatting of
[] -> str
str
str
x:[str]
xs -> NonEmpty str -> str
forall a. Semigroup a => NonEmpty a -> a
sconcat (str
x str -> [str] -> NonEmpty str
forall a. a -> [a] -> NonEmpty a
:| [str]
xs) str -> str -> str
forall a. Semigroup a => a -> a -> a
<> str
str str -> str -> str
forall a. Semigroup a => a -> a -> a
<> str
forall str. IsString str => str
reset
{-# SPECIALIZE formatWith :: [String] -> String -> String #-}
{-# SPECIALIZE formatWith :: [Text] -> Text -> Text #-}
{-# SPECIALIZE formatWith :: [ByteString] -> ByteString -> ByteString #-}
red :: IsString str => str
red :: str
red = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Red]
{-# SPECIALIZE red :: String #-}
{-# SPECIALIZE red :: Text #-}
{-# SPECIALIZE red :: ByteString #-}
green :: IsString str => str
green :: str
green = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Green]
{-# SPECIALIZE green :: String #-}
{-# SPECIALIZE green :: Text #-}
{-# SPECIALIZE green :: ByteString #-}
blue :: IsString str => str
blue :: str
blue = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Blue]
{-# SPECIALIZE blue :: String #-}
{-# SPECIALIZE blue :: Text #-}
{-# SPECIALIZE blue :: ByteString #-}
yellow :: IsString str => str
yellow :: str
yellow = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Yellow]
{-# SPECIALIZE yellow :: String #-}
{-# SPECIALIZE yellow :: Text #-}
{-# SPECIALIZE yellow :: ByteString #-}
black :: IsString str => str
black :: str
black = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Black]
{-# SPECIALIZE black :: String #-}
{-# SPECIALIZE black :: Text #-}
{-# SPECIALIZE black :: ByteString #-}
white :: IsString str => str
white :: str
white = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
White]
{-# SPECIALIZE white :: String #-}
{-# SPECIALIZE white :: Text #-}
{-# SPECIALIZE white :: ByteString #-}
magenta :: IsString str => str
magenta :: str
magenta = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Magenta]
{-# SPECIALIZE magenta :: String #-}
{-# SPECIALIZE magenta :: Text #-}
{-# SPECIALIZE magenta :: ByteString #-}
cyan :: IsString str => str
cyan :: str
cyan = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Vivid Color
Cyan]
{-# SPECIALIZE cyan :: String #-}
{-# SPECIALIZE cyan :: Text #-}
{-# SPECIALIZE cyan :: ByteString #-}
redBg :: IsString str => str
redBg :: str
redBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Red]
{-# SPECIALIZE redBg :: String #-}
{-# SPECIALIZE redBg :: Text #-}
{-# SPECIALIZE redBg :: ByteString #-}
greenBg :: IsString str => str
greenBg :: str
greenBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Green]
{-# SPECIALIZE greenBg :: String #-}
{-# SPECIALIZE greenBg :: Text #-}
{-# SPECIALIZE greenBg :: ByteString #-}
blueBg :: IsString str => str
blueBg :: str
blueBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Blue]
{-# SPECIALIZE blueBg :: String #-}
{-# SPECIALIZE blueBg :: Text #-}
{-# SPECIALIZE blueBg :: ByteString #-}
yellowBg :: IsString str => str
yellowBg :: str
yellowBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Yellow]
{-# SPECIALIZE yellowBg :: String #-}
{-# SPECIALIZE yellowBg :: Text #-}
{-# SPECIALIZE yellowBg :: ByteString #-}
blackBg :: IsString str => str
blackBg :: str
blackBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Black]
{-# SPECIALIZE blackBg :: String #-}
{-# SPECIALIZE blackBg :: Text #-}
{-# SPECIALIZE blackBg :: ByteString #-}
whiteBg :: IsString str => str
whiteBg :: str
whiteBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
White]
{-# SPECIALIZE whiteBg :: String #-}
{-# SPECIALIZE whiteBg :: Text #-}
{-# SPECIALIZE whiteBg :: ByteString #-}
magentaBg :: IsString str => str
magentaBg :: str
magentaBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Magenta]
{-# SPECIALIZE magentaBg :: String #-}
{-# SPECIALIZE magentaBg :: Text #-}
{-# SPECIALIZE magentaBg :: ByteString #-}
cyanBg :: IsString str => str
cyanBg :: str
cyanBg = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Background ColorIntensity
Vivid Color
Cyan]
{-# SPECIALIZE cyanBg :: String #-}
{-# SPECIALIZE cyanBg :: Text #-}
{-# SPECIALIZE cyanBg :: ByteString #-}
bold :: IsString str => str
bold :: str
bold = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [ConsoleIntensity -> SGR
SetConsoleIntensity ConsoleIntensity
BoldIntensity]
{-# SPECIALIZE bold :: String #-}
{-# SPECIALIZE bold :: Text #-}
{-# SPECIALIZE bold :: ByteString #-}
italic :: IsString str => str
italic :: str
italic = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [Bool -> SGR
SetItalicized Bool
True]
{-# SPECIALIZE italic :: String #-}
{-# SPECIALIZE italic :: Text #-}
{-# SPECIALIZE italic :: ByteString #-}
underline :: IsString str => str
underline :: str
underline = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [Underlining -> SGR
SetUnderlining Underlining
SingleUnderline]
{-# SPECIALIZE underline :: String #-}
{-# SPECIALIZE underline :: Text #-}
{-# SPECIALIZE underline :: ByteString #-}
doubleUnderline :: IsString str => str
doubleUnderline :: str
doubleUnderline = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [Underlining -> SGR
SetUnderlining Underlining
DoubleUnderline]
{-# SPECIALIZE doubleUnderline :: String #-}
{-# SPECIALIZE doubleUnderline :: Text #-}
{-# SPECIALIZE doubleUnderline :: ByteString #-}
noUnderline :: IsString str => str
noUnderline :: str
noUnderline = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [Underlining -> SGR
SetUnderlining Underlining
NoUnderline]
{-# SPECIALIZE noUnderline :: String #-}
{-# SPECIALIZE noUnderline :: Text #-}
{-# SPECIALIZE noUnderline :: ByteString #-}
indent :: (IsString str, Semigroup str) => Int -> str
indent :: Int -> str
indent Int
n
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = str
""
| Bool
otherwise = Int -> str -> str
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes Int
n str
" "
{-# SPECIALIZE indent :: Int -> String #-}
{-# SPECIALIZE indent :: Int -> Text #-}
{-# SPECIALIZE indent :: Int -> ByteString #-}
reset :: IsString str => str
reset :: str
reset = String -> str
forall a. IsString a => String -> a
fromString (String -> str) -> String -> str
forall a b. (a -> b) -> a -> b
$ [SGR] -> String
setSGRCode [SGR
Reset]
{-# SPECIALIZE reset :: String #-}
{-# SPECIALIZE reset :: Text #-}
{-# SPECIALIZE reset :: ByteString #-}