Portability | to be determined. |
---|---|
Stability | highly unstable |
Maintainer | Stephen Tetley <stephen.tetley@gmail.com> |
Printing with join-strings.
Note - JoinPrint is just a formatter and not a 'pretty printer'. No line fitting takes place - lines are printed exactly as they are specified.
- data Doc
- data VDoc
- empty :: Doc
- null :: Doc -> Bool
- length :: Doc -> Int
- (<>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- hcat :: [Doc] -> Doc
- hsep :: [Doc] -> Doc
- vcat :: [Doc] -> VDoc
- vsep :: [Doc] -> VDoc
- vcons :: Doc -> VDoc -> VDoc
- vsnoc :: VDoc -> Doc -> VDoc
- vconcat :: [VDoc] -> VDoc
- vconcatSep :: [VDoc] -> VDoc
- text :: String -> Doc
- char :: Char -> Doc
- int :: Int -> Doc
- integer :: Integer -> Doc
- integral :: Integral a => a -> Doc
- float :: Double -> Doc
- double :: Double -> Doc
- sglspace :: Doc
- dblspace :: Doc
- comma :: Doc
- semicolon :: Doc
- punctuate :: Doc -> [Doc] -> Doc
- enclose :: Doc -> Doc -> Doc -> Doc
- squotes :: Doc -> Doc
- dquotes :: Doc -> Doc
- parens :: Doc -> Doc
- brackets :: Doc -> Doc
- braces :: Doc -> Doc
- angles :: Doc -> Doc
- lparen :: Doc
- rparen :: Doc
- lbracket :: Doc
- rbracket :: Doc
- lbrace :: Doc
- rbrace :: Doc
- langle :: Doc
- rangle :: Doc
- replicateChar :: Int -> Char -> Doc
- spacer :: Int -> Doc
- padl :: Int -> Char -> Doc -> Doc
- padr :: Int -> Char -> Doc -> Doc
- truncl :: Int -> Doc -> Doc
- truncr :: Int -> Doc -> Doc
- render :: Doc -> String
- renderIO :: Doc -> IO ()
- hex :: Integral a => a -> Doc
- hex2 :: Word8 -> Doc
- hex4 :: Word16 -> Doc
- hex8 :: Word32 -> Doc
- oxhex :: Integral a => Int -> a -> Doc
- oxhex2 :: Word8 -> Doc
- oxhex4 :: Word16 -> Doc
- oxhex8 :: Word32 -> Doc
- hexdump :: Int -> Int -> [Word8] -> VDoc
- hexdumpA :: Int -> Int -> IOUArray Int Word8 -> IO VDoc
Documentation
VDoc is the abstract data type respresenting multi-line documents.
Multi-line documents have a limited set of operations (basically concatenation with or without a blank line inbetween) compared to single line docs which support e.g. padding and truncating.
Get the length of the Doc.
Length is cached in the document's data type so this operation is O(1).
Compose Docs
(<+>) :: Doc -> Doc -> DocSource
Horizontally concatenate two documents with a single space between them.
Compose VDocs
vconcatSep :: [VDoc] -> VDocSource
Concatenate a list of VDoc
with a blank line separating
them.
Primitive Docs
Create a document from a literal string.
The string should not contain tabs or newlines (though this
is not enforced). To allow padding and truncating the
horizontal width of a Doc
is cached in the datatype,
building a Doc containing tabs or newlines leads to
unspecified behaviour.
Create a document from a literal character.
The char should not be a tab or newline. See text
for the
rational.
integral :: Integral a => a -> DocSource
Show an "integral value" as a Doc via fromIntegral
.
enclose :: Doc -> Doc -> Doc -> DocSource
Enclose the final Doc within the first two.
There are no spaces between the documents:
enclose l r d = l <> d <> r
replicateChar :: Int -> Char -> DocSource
replicateChar
: n * ch -> Doc
Repeat the supplied char (ch
), n
times.
Padding and truncation
padl :: Int -> Char -> Doc -> DocSource
padl
: width * ch * doc -> Doc
Pad the supplied Doc to fit width
using the char ch
.
Padding is performed at the left, right-justifying the Doc.
If the doc is already wider than supplied width it is returned as-is (no truncation takes place).
padr :: Int -> Char -> Doc -> DocSource
padr
: width * ch * doc -> Doc
Pad the supplied Doc to fit width
using the char ch
.
Padding is performed at the right, left-justifying the Doc.
If the doc is already wider than supplied width it is returned as-is (no truncation takes place).
truncl :: Int -> Doc -> DocSource
truncl
: width * doc -> Doc
Truncate a doc to the supplied width
. Characters are dropped
from the left until the document fits. If the document is
shorter than the supplied width it is returned as is (no
padding takes place).
truncr :: Int -> Doc -> DocSource
truncr
: width * doc -> Doc
Truncate a doc to the supplied width
. Characters are dropped
from the right until the document fits. If the document is
shorter than the supplied width it is returned as is (no
padding takes place).
Output
hex :: Integral a => a -> DocSource
hex
: i -> Doc
Print i
as hexadecimal, no zero padding.
Negative numbers are printed as a string of asterisks.