escaped-1.1.0.0: Produce Text with terminal escape sequences
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Text.Escaped

Synopsis

Documentation

data Escaped Source #

Bits of escaped text

Instances

Instances details
Arbitrary Escaped Source # 
Instance details

Defined in Data.Text.Escaped

IsString Escaped Source # 
Instance details

Defined in Data.Text.Escaped

Methods

fromString :: String -> Escaped #

Monoid Escaped Source # 
Instance details

Defined in Data.Text.Escaped

Semigroup Escaped Source # 
Instance details

Defined in Data.Text.Escaped

Show Escaped Source # 
Instance details

Defined in Data.Text.Escaped

Eq Escaped Source # 
Instance details

Defined in Data.Text.Escaped

Methods

(==) :: Escaped -> Escaped -> Bool #

(/=) :: Escaped -> Escaped -> Bool #

data Color Source #

Supported colors

Instances

Instances details
Arbitrary Color Source # 
Instance details

Defined in Data.Text.Escaped

Methods

arbitrary :: Gen Color #

shrink :: Color -> [Color] #

Show Color Source # 
Instance details

Defined in Data.Text.Escaped

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color Source # 
Instance details

Defined in Data.Text.Escaped

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

fg :: Color -> Escaped -> Escaped Source #

Escape with foreground Color, then Reset

>>> fg Red "red"
Many [FG Red,Plain "red",Reset]

bg :: Color -> Escaped -> Escaped Source #

Escape with background Color, then Reset

>>> bg Red "red"
Many [BG Red,Plain "red",Reset]

esc :: Escaped -> Escaped -> Escaped Source #

Apply the given escape, then Reset

>>> esc (FG Red) "red"
Many [FG Red,Plain "red",Reset]

render :: Escaped -> Text Source #

Render an Escaped to actually-escaped Text

Examples:

>>> render "Some text via OverloadedStrings."
"Some text via OverloadedStrings."
>>> render $ Plain "Some text."
"Some text."
>>> render $ "Some " <> FG Red <> "red" <> Reset <> " text."
"Some \ESC[31mred\ESC[0m text."
>>> render $ "Some " <> blue "blue" <> " text."
"Some \ESC[34mblue\ESC[0m text."
>>> render $ "Some " <> fg (Custom 212) "color 212" <> " text."
"Some \ESC[38;5;212mcolor 212\ESC[0m text."

plain :: Escaped -> Text Source #

Render only the Text parts

Examples

>>> plain $ Plain "Some text."
"Some text."
>>> plain $ "Some " <> FG Red <> "red" <> Reset <> " text."
"Some red text."

visibleLength :: Escaped -> Int Source #

Calculate the visible length of an Escaped

terminalRenderer :: IO (Escaped -> Text) Source #

An IO action to produce the appropriate renderer for a terminal

Returns render if stdout is a terminal, otherwise plain

>>> r <- terminalRenderer
>>> print $ r $ red "red text"
"red text"