module Sos.Utils where
import Control.Applicative
import Data.ByteString (ByteString)
import System.Console.ANSI
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
(<|||>) :: Alternative f => f a -> f b -> f (Either a b)
f a
fa <|||> :: forall (f :: * -> *) a b.
Alternative f =>
f a -> f b -> f (Either a b)
<|||> f b
fb = forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f a
fa forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
fb
infixl 3 <|||>
packBS :: String -> ByteString
packBS :: String -> ByteString
packBS = Text -> ByteString
Text.encodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack
unpackBS :: ByteString -> String
unpackBS :: ByteString -> String
unpackBS = Text -> String
Text.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8
colored :: Color -> String -> String
colored :: Color -> String -> String
colored Color
c String
s = Color -> String
color Color
c forall a. Semigroup a => a -> a -> a
<> String
s forall a. Semigroup a => a -> a -> a
<> String
reset
color :: Color -> String
color :: Color -> String
color Color
c = [SGR] -> String
setSGRCode [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Dull Color
c]
reset :: String
reset :: String
reset = [SGR] -> String
setSGRCode [SGR
Reset]
cyan, green, magenta, red, yellow :: String -> String
cyan :: String -> String
cyan = Color -> String -> String
colored Color
Cyan
green :: String -> String
green = Color -> String -> String
colored Color
Green
magenta :: String -> String
magenta = Color -> String -> String
colored Color
Magenta
red :: String -> String
red = Color -> String -> String
colored Color
Red
yellow :: String -> String
yellow = Color -> String -> String
colored Color
Yellow