Safe Haskell | None |
---|---|
Language | Haskell2010 |
Safe Coloured Text
This module is responsible for defining, building, and rendering coloured text.
The text to be coloured is Text
, but the rendered text, while technically still (probably) valid Utf8, will be a ByteString
builder.
Synopsis
- chunk :: Text -> Chunk
- data Chunk = Chunk {
- chunkText :: !Text
- chunkItalic :: !(Maybe Bool)
- chunkConsoleIntensity :: !(Maybe ConsoleIntensity)
- chunkUnderlining :: !(Maybe Underlining)
- chunkForeground :: !(Maybe Colour)
- chunkBackground :: !(Maybe Colour)
- fore :: Colour -> Chunk -> Chunk
- back :: Colour -> Chunk -> Chunk
- bold :: Chunk -> Chunk
- faint :: Chunk -> Chunk
- italic :: Chunk -> Chunk
- underline :: Chunk -> Chunk
- doubleUnderline :: Chunk -> Chunk
- data Colour
- black :: Colour
- red :: Colour
- green :: Colour
- yellow :: Colour
- blue :: Colour
- magenta :: Colour
- cyan :: Colour
- white :: Colour
- brightBlack :: Colour
- brightRed :: Colour
- brightGreen :: Colour
- brightYellow :: Colour
- brightBlue :: Colour
- brightMagenta :: Colour
- brightCyan :: Colour
- brightWhite :: Colour
- color256 :: Word8 -> Colour
- colour256 :: Word8 -> Colour
- colorRGB :: Word8 -> Word8 -> Word8 -> Colour
- colourRGB :: Word8 -> Word8 -> Word8 -> Colour
- renderChunks :: Foldable f => TerminalCapabilities -> f Chunk -> Builder
- renderChunk :: TerminalCapabilities -> Chunk -> Builder
- renderChunksBS :: Foldable f => TerminalCapabilities -> f Chunk -> ByteString
- renderChunkBS :: TerminalCapabilities -> Chunk -> ByteString
- data TerminalCapabilities
- getTerminalCapabilitiesFromEnv :: IO TerminalCapabilities
- getTerminalCapabilitiesFromHandle :: Handle -> IO TerminalCapabilities
- putChunks :: [Chunk] -> IO ()
- hPutChunks :: Handle -> [Chunk] -> IO ()
- putChunksWith :: TerminalCapabilities -> [Chunk] -> IO ()
- hPutChunksWith :: TerminalCapabilities -> Handle -> [Chunk] -> IO ()
Building chunks
Chunk | |
|
Instances
Styling
Setting colour
Setting non-colour attributes
doubleUnderline :: Chunk -> Chunk Source #
Colours
Instances
8-colour
Dull
Bright
brightBlack :: Colour Source #
brightGreen :: Colour Source #
brightBlue :: Colour Source #
brightCyan :: Colour Source #
brightWhite :: Colour Source #
8-bit
colour256 :: Word8 -> Colour Source #
Bulid an 8-bit RGB Colour
This will not be rendered unless With8BitColours
is used.
24-bit
colourRGB :: Word8 -> Word8 -> Word8 -> Colour Source #
Bulid a 24-bit RGB Colour
This will not be rendered unless With24BitColours
is used.
Rendering
Rendering chunks to bytestring builders
renderChunks :: Foldable f => TerminalCapabilities -> f Chunk -> Builder Source #
Render chunks to a bytestring builder
renderChunk :: TerminalCapabilities -> Chunk -> Builder Source #
Render a chunk to a bytestring builder
Rendering chunks to strict bytestring
renderChunksBS :: Foldable f => TerminalCapabilities -> f Chunk -> ByteString Source #
Render a chunk directly to bytestring.
renderChunkBS :: TerminalCapabilities -> Chunk -> ByteString Source #
Render a chunk directly to bytestring.
IO
data TerminalCapabilities Source #
WithoutColours | No colours |
With8Colours | Only 8 colours |
With8BitColours | Only 8-bit colours |
With24BitColours | All 24-bit colours |
Instances
getTerminalCapabilitiesFromEnv :: IO TerminalCapabilities Source #
Try to detect how many colours the terminal can handle.
This is based on the colors
capability of the terminfo detected based on the TERM
environment variable.
If the terminal can handle 8-bit colours and also has the COLORTERM
environment variable set to 24bit
or truecolor
, then this function will return With24BitColours
.
getTerminalCapabilitiesFromHandle :: Handle -> IO TerminalCapabilities Source #
Try to detect how many colours a given handle can handle.
This function does the same as getTerminalCapabilitiesFromEnv
but returns WithoutColours
is not a terminal device.
Outputting chunks directly
putChunks :: [Chunk] -> IO () Source #
Print a list of chunks to stdout
.
This function will use getTerminalCapabilitiesHandle
on stdout
.
If you intend to use this function more than once, it is more efficient to use getTerminalCapabilitiesFromEnv
first and then use putChunksWith
.
hPutChunks :: Handle -> [Chunk] -> IO () Source #
Print a list of chunks to the given Handle
This function will use getTerminalCapabilitiesHandle
on the given handle.
If you intend to use this function more than once, it is more efficient to use getTerminalCapabilitiesHandle
first and then use hPutChunksWith
.
putChunksWith :: TerminalCapabilities -> [Chunk] -> IO () Source #
Print a list of chunks to stdout with given TerminalCapabilities
.
hPutChunksWith :: TerminalCapabilities -> Handle -> [Chunk] -> IO () Source #
Print a list of chunks to the given Handle
with given TerminalCapabilities
.