| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Rainbow.Translate
Description
This module contains functions that convert a Chunk into
ByteStrings. Ordinarily everything you need from this module is
exported from Rainbow.
Synopsis
- single :: Char -> [ByteString] -> [ByteString]
- escape :: [ByteString] -> [ByteString]
- csi :: [ByteString] -> [ByteString]
- sgr :: ([ByteString] -> [ByteString]) -> [ByteString] -> [ByteString]
- params :: Show a => [a] -> [ByteString] -> [ByteString]
- sgrSingle :: Word -> [ByteString] -> [ByteString]
- sgrDouble :: Word -> Word -> [ByteString] -> [ByteString]
- normalDefault :: [ByteString] -> [ByteString]
- bold :: [ByteString] -> [ByteString]
- faint :: [ByteString] -> [ByteString]
- italic :: [ByteString] -> [ByteString]
- underline :: [ByteString] -> [ByteString]
- blink :: [ByteString] -> [ByteString]
- inverse :: [ByteString] -> [ByteString]
- invisible :: [ByteString] -> [ByteString]
- strikeout :: [ByteString] -> [ByteString]
- foreBlack :: [ByteString] -> [ByteString]
- foreRed :: [ByteString] -> [ByteString]
- foreGreen :: [ByteString] -> [ByteString]
- foreYellow :: [ByteString] -> [ByteString]
- foreBlue :: [ByteString] -> [ByteString]
- foreMagenta :: [ByteString] -> [ByteString]
- foreCyan :: [ByteString] -> [ByteString]
- foreWhite :: [ByteString] -> [ByteString]
- foreDefault :: [ByteString] -> [ByteString]
- backBlack :: [ByteString] -> [ByteString]
- backRed :: [ByteString] -> [ByteString]
- backGreen :: [ByteString] -> [ByteString]
- backYellow :: [ByteString] -> [ByteString]
- backBlue :: [ByteString] -> [ByteString]
- backMagenta :: [ByteString] -> [ByteString]
- backCyan :: [ByteString] -> [ByteString]
- backWhite :: [ByteString] -> [ByteString]
- backDefault :: [ByteString] -> [ByteString]
- fore256 :: Word8 -> [ByteString] -> [ByteString]
- back256 :: Word8 -> [ByteString] -> [ByteString]
- foreColor8 :: Enum8 -> [ByteString] -> [ByteString]
- backColor8 :: Enum8 -> [ByteString] -> [ByteString]
- renderFormat :: Format -> [ByteString] -> [ByteString]
- renderStyle8 :: Style Enum8 -> [ByteString] -> [ByteString]
- renderStyle256 :: Style Word8 -> [ByteString] -> [ByteString]
- render :: Text -> [ByteString] -> [ByteString]
- toByteStringsColors0 :: Chunk -> [ByteString] -> [ByteString]
- toByteStringsColors8 :: Chunk -> [ByteString] -> [ByteString]
- toByteStringsColors256 :: Chunk -> [ByteString] -> [ByteString]
- byteStringMakerFromEnvironment :: IO (Chunk -> [ByteString] -> [ByteString])
- byteStringMakerFromHandle :: Handle -> IO (Chunk -> [ByteString] -> [ByteString])
- chunksToByteStrings :: (Chunk -> [ByteString] -> [ByteString]) -> [Chunk] -> [ByteString]
- hPutChunks :: Handle -> [Chunk] -> IO ()
- hPutChunksLn :: Handle -> [Chunk] -> IO ()
- putChunks :: [Chunk] -> IO ()
- putChunksLn :: [Chunk] -> IO ()
- putChunk :: Chunk -> IO ()
- putChunkLn :: Chunk -> IO ()
Documentation
single :: Char -> [ByteString] -> [ByteString] Source #
escape :: [ByteString] -> [ByteString] Source #
csi :: [ByteString] -> [ByteString] Source #
sgr :: ([ByteString] -> [ByteString]) -> [ByteString] -> [ByteString] Source #
params :: Show a => [a] -> [ByteString] -> [ByteString] Source #
sgrSingle :: Word -> [ByteString] -> [ByteString] Source #
sgrDouble :: Word -> Word -> [ByteString] -> [ByteString] Source #
normalDefault :: [ByteString] -> [ByteString] Source #
bold :: [ByteString] -> [ByteString] Source #
faint :: [ByteString] -> [ByteString] Source #
italic :: [ByteString] -> [ByteString] Source #
underline :: [ByteString] -> [ByteString] Source #
blink :: [ByteString] -> [ByteString] Source #
inverse :: [ByteString] -> [ByteString] Source #
invisible :: [ByteString] -> [ByteString] Source #
strikeout :: [ByteString] -> [ByteString] Source #
foreBlack :: [ByteString] -> [ByteString] Source #
foreRed :: [ByteString] -> [ByteString] Source #
foreGreen :: [ByteString] -> [ByteString] Source #
foreYellow :: [ByteString] -> [ByteString] Source #
foreBlue :: [ByteString] -> [ByteString] Source #
foreMagenta :: [ByteString] -> [ByteString] Source #
foreCyan :: [ByteString] -> [ByteString] Source #
foreWhite :: [ByteString] -> [ByteString] Source #
foreDefault :: [ByteString] -> [ByteString] Source #
backBlack :: [ByteString] -> [ByteString] Source #
backRed :: [ByteString] -> [ByteString] Source #
backGreen :: [ByteString] -> [ByteString] Source #
backYellow :: [ByteString] -> [ByteString] Source #
backBlue :: [ByteString] -> [ByteString] Source #
backMagenta :: [ByteString] -> [ByteString] Source #
backCyan :: [ByteString] -> [ByteString] Source #
backWhite :: [ByteString] -> [ByteString] Source #
backDefault :: [ByteString] -> [ByteString] Source #
fore256 :: Word8 -> [ByteString] -> [ByteString] Source #
back256 :: Word8 -> [ByteString] -> [ByteString] Source #
foreColor8 :: Enum8 -> [ByteString] -> [ByteString] Source #
backColor8 :: Enum8 -> [ByteString] -> [ByteString] Source #
renderFormat :: Format -> [ByteString] -> [ByteString] Source #
renderStyle8 :: Style Enum8 -> [ByteString] -> [ByteString] Source #
renderStyle256 :: Style Word8 -> [ByteString] -> [ByteString] Source #
render :: Text -> [ByteString] -> [ByteString] Source #
toByteStringsColors0 :: Chunk -> [ByteString] -> [ByteString] Source #
toByteStringsColors8 :: Chunk -> [ByteString] -> [ByteString] Source #
toByteStringsColors256 :: Chunk -> [ByteString] -> [ByteString] Source #
byteStringMakerFromEnvironment :: IO (Chunk -> [ByteString] -> [ByteString]) Source #
Uses setupTermFromEnv to obtain the terminal's color
capability. If this says there are at least 256 colors are
available, returns toByteStringsColors256. Otherwise, if there
are at least 8 colors available, returns toByteStringsColors8.
Otherwise, returns toByteStringsColors0.
If the terminfo database could not be read (that is, if
SetupTermError is returned), then return
toByteStringsColors0.
byteStringMakerFromHandle :: Handle -> IO (Chunk -> [ByteString] -> [ByteString]) Source #
Like byteStringMakerFromEnvironment but also consults a
provided Handle. If the Handle is not a terminal,
toByteStringsColors0 is returned. Otherwise, the value of
byteStringMakerFromEnvironment is returned.
Arguments
| :: (Chunk -> [ByteString] -> [ByteString]) | Function that converts |
| -> [Chunk] | |
| -> [ByteString] |
Convert a list of Chunk to a list of ByteString. The
length of the returned list may be longer than the length of the
input list.
So, for example, to print a bunch of chunks to standard output using 256 colors:
module PrintMyChunks where
import qualified Data.ByteString as BS
import Rainbow
myChunks :: [Chunk String]
myChunks = [ chunk "Roses" & fore red, chunk "\n",
chunk "Violets" & fore blue, chunk "\n" ]
myPrintedChunks :: IO ()
myPrintedChunks = mapM_ BS.putStr
. chunksToByteStrings toByteStringsColors256
$ myChunksTo use the highest number of colors that this terminal supports:
myPrintedChunks' :: IO ()
myPrintedChunks' = do
printer <- byteStringMakerFromEnvironment
mapM_ BS.putStr
. chunksToByteStrings printer
$ myChunkshPutChunks :: Handle -> [Chunk] -> IO () Source #
Writes a list of chunks to the given Handle.
First uses byteStringMakerFromEnvironment to determine how many
colors to use. Then creates a list of ByteString using
chunksToByteStrings and then writes them to the given Handle.
hPutChunksLn :: Handle -> [Chunk] -> IO () Source #
Writes a list of chunks to the given Handle, followed by a
newline character.
First uses byteStringMakerFromEnvironment to determine how many
colors to use. Then creates a list of ByteString using
chunksToByteStrings and then writes them to the given Handle.
putChunks :: [Chunk] -> IO () Source #
Writes a list of chunks to standard output.
First uses byteStringMakerFromEnvironment to determine how many
colors to use. Then creates a list of ByteString using
chunksToByteStrings and then writes them to standard output.
putChunksLn :: [Chunk] -> IO () Source #
Writes a list of chunks to standard output, followed by a newline.
First uses byteStringMakerFromEnvironment to determine how many
colors to use. Then creates a list of ByteString using
chunksToByteStrings and then writes them to standard output.
putChunk :: Chunk -> IO () Source #
Writes a Chunk to standard output. Uses
byteStringMakerFromEnvironment each time you apply it, so this
might be inefficient. You are better off using
chunksToByteStrings and the functions in Data.ByteString to
print your Chunks if you are printing a lot of them.
putChunkLn :: Chunk -> IO () Source #
Writes a Chunk to standard output, and appends a newline.
Uses byteStringMakerFromEnvironment each time you apply it, so
this might be inefficient. You are better off using
chunksToByteStrings and the functions in Data.ByteString to
print your Chunks if you are printing a lot of them.