| 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.
- class Renderable a where
- render :: a -> [ByteString] -> [ByteString]
- 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]
- toByteStringsColors0 :: Renderable a => Chunk a -> [ByteString] -> [ByteString]
- toByteStringsColors8 :: Renderable a => Chunk a -> [ByteString] -> [ByteString]
- toByteStringsColors256 :: Renderable a => Chunk a -> [ByteString] -> [ByteString]
- byteStringMakerFromEnvironment :: Renderable a => IO (Chunk a -> [ByteString] -> [ByteString])
- byteStringMakerFromHandle :: Renderable a => Handle -> IO (Chunk a -> [ByteString] -> [ByteString])
- chunksToByteStrings :: (Chunk a -> [ByteString] -> [ByteString]) -> [Chunk a] -> [ByteString]
- putChunk :: Renderable a => Chunk a -> IO ()
- putChunkLn :: Renderable a => Chunk a -> IO ()
Documentation
class Renderable a where Source
Items that can be rendered. render returns a difference list.
Methods
render :: a -> [ByteString] -> [ByteString] Source
Instances
| Renderable String | Strings are converted first to a strict Text and then to a strict ByteString. |
| Renderable ByteString | Lazy ByteString is converted to strict chunks. |
| Renderable ByteString | Strict ByteString is left as-is. |
| Renderable Text | Converts a lazy Text to UTF-8 ByteStrings. |
| Renderable Text | Converts a strict Text to a UTF-8 ByteString. |
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
toByteStringsColors0 :: Renderable a => Chunk a -> [ByteString] -> [ByteString] Source
toByteStringsColors8 :: Renderable a => Chunk a -> [ByteString] -> [ByteString] Source
toByteStringsColors256 :: Renderable a => Chunk a -> [ByteString] -> [ByteString] Source
byteStringMakerFromEnvironment :: Renderable a => IO (Chunk a -> [ByteString] -> [ByteString]) Source
Spawns a subprocess to read the output of tput colors. 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 any IO exceptions arise during this process, they are discarded
and toByteStringsColors0 is returned.
byteStringMakerFromHandle :: Renderable a => Handle -> IO (Chunk a -> [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 a -> [ByteString] -> [ByteString]) | Function that converts |
| -> [Chunk a] | |
| -> [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
$ myChunksputChunk :: Renderable a => Chunk a -> IO () Source
Writes a Chunk to standard output. Spawns a child process to
read the output of tput colors to determine how many colors to
use, for every single chunk. Therefore, this is not going to win
any speed awards. 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 :: Renderable a => Chunk a -> IO () Source
Writes a Chunk to standard output, and appends a newline.
Spawns a child process to read the output of tput colors to
determine how many colors to use, for every single chunk.
Therefore, this is not going to win any speed awards. You are
better off using chunksToByteStrings and the functions in
Data.ByteString to print your Chunks if you are printing a lot
of them.