darcs-2.8.4: a distributed, interactive, smart revision control system

Safe Haskell | None

Printer

Synopsis

- data Printable
  - = S !String
  - | PS !ByteString
  - | Both !String !ByteString
- newtype Doc = Doc {
  - unDoc :: St -> Document
  }
- type Printers = Handle -> Printers'
- data Printers' = Printers {
  - colorP :: !(Color -> Printer)
  - invisibleP :: !Printer
  - hiddenP :: !Printer
  - userchunkP :: !Printer
  - defP :: !Printer
  - lineColorT :: !(Color -> Doc -> Doc)
  - lineColorS :: !([Printable] -> [Printable])
  }
- type Printer = Printable -> St -> Document
- data Color
  - = Blue
  - | Red
  - | Green
  - | Cyan
  - | Magenta
- hPutDoc :: Handle -> Doc -> IO ()
- hPutDocLn :: Handle -> Doc -> IO ()
- putDoc :: Doc -> IO ()
- putDocLn :: Doc -> IO ()
- hPutDocWith :: Printers -> Handle -> Doc -> IO ()
- hPutDocLnWith :: Printers -> Handle -> Doc -> IO ()
- putDocWith :: Printers -> Doc -> IO ()
- putDocLnWith :: Printers -> Doc -> IO ()
- renderString :: Doc -> String
- renderStringWith :: Printers' -> Doc -> String
- renderPS :: Doc -> ByteString
- renderPSWith :: Printers' -> Doc -> ByteString
- renderPSs :: Doc -> [ByteString]
- renderPSsWith :: Printers' -> Doc -> [ByteString]
- lineColor :: Color -> Doc -> Doc
- prefix :: String -> Doc -> Doc
- insertBeforeLastline :: Doc -> Doc -> Doc
- colorText :: Color -> String -> Doc
- invisibleText :: String -> Doc
- hiddenText :: String -> Doc
- hiddenPrefix :: String -> Doc -> Doc
- userchunk :: String -> Doc
- text :: String -> Doc
- printable :: Printable -> Doc
- wrapText :: Int -> String -> Doc
- blueText :: String -> Doc
- redText :: String -> Doc
- greenText :: String -> Doc
- magentaText :: String -> Doc
- cyanText :: String -> Doc
- unsafeText :: String -> Doc
- unsafeBoth :: String -> ByteString -> Doc
- unsafeBothText :: String -> Doc
- unsafeChar :: Char -> Doc
- invisiblePS :: ByteString -> Doc
- packedString :: ByteString -> Doc
- unsafePackedString :: ByteString -> Doc
- userchunkPS :: ByteString -> Doc
- simplePrinters :: Printers
- invisiblePrinter :: Printer
- simplePrinter :: Printer
- doc :: ([Printable] -> [Printable]) -> Doc
- empty :: Doc
- (<>) :: Doc -> Doc -> Doc
- (<?>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- ($$) :: Doc -> Doc -> Doc
- vcat :: [Doc] -> Doc
- vsep :: [Doc] -> Doc
- hcat :: [Doc] -> Doc
- minus :: Doc
- newline :: Doc
- plus :: Doc
- space :: Doc
- backslash :: Doc
- lparen :: Doc
- rparen :: Doc
- parens :: Doc -> Doc
- errorDoc :: Doc -> a

# Documentation

data Printable

A `Printable` is either a String, a packed string, or a chunk of text with both representations.

Constructors

S !String |
PS !ByteString |
Both !String !ByteString |

newtype Doc

a `Doc` is a bit of enriched text. `Doc`s get concatanated using `<>`, which is right-associative.

Constructors

Doc |

Fields

unDoc :: St -> Document

Instances

Show Doc |

type Printers = Handle -> Printers'

data Printers'

A set of printers to print different types of text to a handle.

Constructors

Printers |

Fields

colorP :: !(Color -> Printer)
invisibleP :: !Printer
hiddenP :: !Printer
userchunkP :: !Printer
defP :: !Printer
lineColorT :: !(Color -> Doc -> Doc)
lineColorS :: !([Printable] -> [Printable])

type Printer = Printable -> St -> Document

data Color

Constructors

Blue |
Red |
Green |
Cyan |
Magenta |

hPutDoc :: Handle -> Doc -> IO ()

`hputDoc` puts a doc on the given handle using `simplePrinters`

hPutDocLn :: Handle -> Doc -> IO ()

putDoc :: Doc -> IO ()

`putDoc` puts a doc on stdout using the simple printer `simplePrinters`.

putDocLn :: Doc -> IO ()

`putDocLn` puts a doc, followed by a newline on stdout using `simplePrinters`

hPutDocWith :: Printers -> Handle -> Doc -> IO ()

`hputDocWith` puts a doc on the given handle using the given printer.

hPutDocLnWith :: Printers -> Handle -> Doc -> IO ()

`hputDocLnWith` puts a doc, followed by a newline on the given handle using the given printer.

putDocWith :: Printers -> Doc -> IO ()

`putDocWith` puts a doc on stdout using the given printer.

putDocLnWith :: Printers -> Doc -> IO ()

`putDocLnWith` puts a doc, followed by a newline on stdout using the given printer.

renderString :: Doc -> String

renders a `Doc` into a `String` with control codes for the special features of the doc.

renderStringWith :: Printers' -> Doc -> String

renders a `Doc` into a `String` using a given set of printers.

renderPS :: Doc -> ByteString

renders a `Doc` into `ByteString` with control codes for the special features of the Doc. See also `readerString`.

renderPSWith :: Printers' -> Doc -> ByteString

renders a doc into a `ByteString` using a given set of printers.

renderPSs :: Doc -> [ByteString]

renders a `Doc` into a list of `PackedStrings`, one for each line.

renderPSsWith :: Printers' -> Doc -> [ByteString]

renders a `Doc` into a list of `PackedStrings`, one for each chunk of text that was added to the doc, using the given set of printers.

lineColor :: Color -> Doc -> Doc

prefix :: String -> Doc -> Doc

insertBeforeLastline :: Doc -> Doc -> Doc

colorText :: Color -> String -> Doc

`colorText` creates a `Doc` containing colored text from a `String`

invisibleText :: String -> Doc

`invisibleText` creates a `Doc` containing invisible text from a `String`

hiddenText :: String -> Doc

`hiddenText` creates a `Doc` containing hidden text from a `String`

hiddenPrefix :: String -> Doc -> Doc

userchunk :: String -> Doc

`userchunk` creates a `Doc` containing a user chunk from a `String`

text :: String -> Doc

`text` creates a `Doc` from a `String`, using `printable`.

printable :: Printable -> Doc

'printable x' creates a `Doc` from any `Printable`.

wrapText :: Int -> String -> Doc

``wrapText` n s` is a `Doc` representing `s` line-wrapped at `n` characters

blueText :: String -> Doc

`blueText` creates a `Doc` containing blue text from a `String`

redText :: String -> Doc

`blueText` creates a `Doc` containing blue text from a `String`

greenText :: String -> Doc

`blueText` creates a `Doc` containing blue text from a `String`

magentaText :: String -> Doc

`blueText` creates a `Doc` containing blue text from a `String`

cyanText :: String -> Doc

`blueText` creates a `Doc` containing blue text from a `String`

unsafeText :: String -> Doc

`unsafeText` creates a `Doc` from a `String`, using `simplePrinter` directly

unsafeBoth :: String -> ByteString -> Doc

`unsafeBoth` builds a Doc from a `String` and a `ByteString` representing the same text, but does not check that they do.

unsafeBothText :: String -> Doc

`unsafeBothText` builds a `Doc` from a `String`. The string is stored in the Doc as both a String and a `ByteString`.

unsafeChar :: Char -> Doc

`unsafeChar` creates a Doc containing just one character.

invisiblePS :: ByteString -> Doc

`invisiblePS` creates a `Doc` with invisible text from a `ByteString`

packedString :: ByteString -> Doc

`packedString` builds a `Doc` from a `ByteString` using `printable`

unsafePackedString :: ByteString -> Doc

`unsafePackedString` builds a `Doc` from a `ByteString` using `simplePrinter`

userchunkPS :: ByteString -> Doc

`userchunkPS` creates a `Doc` representing a user chunk from a `ByteString`.

simplePrinters :: Printers

`simplePrinters` is a `Printers` which uses the set 'simplePriners\'' on any handle.

invisiblePrinter :: Printer

`invisiblePrinter` is the `Printer` for hidden text. It just replaces the document with `empty`. It's useful to have a printer that doesn't actually do anything because this allows you to have tunable policies, for example, only printing some text if it's to the terminal, but not if it's to a file or vice-versa.

simplePrinter :: Printer

`simplePrinter` is the simplest `Printer`: it just concatenates together the pieces of the `Doc`

doc :: ([Printable] -> [Printable]) -> Doc

empty :: Doc

The empty `Doc`.

(<>) :: Doc -> Doc -> Doc

'()' is the concatenation operator for `Doc`s

(<?>) :: Doc -> Doc -> Doc

`a `<?>` b` is `a b` if `a` is not empty, else empty.

(<+>) :: Doc -> Doc -> Doc

`a `<+>` b` is `a` followed by a space, then `b`.

($$) :: Doc -> Doc -> Doc

`a `$$` b` is `a` above `b`.

vcat :: [Doc] -> Doc

`vcat` piles vertically a list of `Doc`s.

vsep :: [Doc] -> Doc

`vsep` piles vertically a list of `Doc`s leaving a blank line between each.

hcat :: [Doc] -> Doc

`hcat` concatenates (horizontally) a list of `Doc`s

minus :: Doc

Minimal `Doc`s representing the common characters `space`, `newline` `minus`, `plus`, and `backslash`.

newline :: Doc

Minimal `Doc`s representing the common characters `space`, `newline` `minus`, `plus`, and `backslash`.

plus :: Doc

Minimal `Doc`s representing the common characters `space`, `newline` `minus`, `plus`, and `backslash`.

space :: Doc

Minimal `Doc`s representing the common characters `space`, `newline` `minus`, `plus`, and `backslash`.

backslash :: Doc

Minimal `Doc`s representing the common characters `space`, `newline` `minus`, `plus`, and `backslash`.

lparen :: Doc

`lparen` is the `Doc` that represents `"("`

rparen :: Doc

`rparen` is the `Doc` that represents `")"`

parens :: Doc -> Doc

``parens` doc` returns a `Doc` with the content of `doc` put within a pair of parenthesis.

errorDoc :: Doc -> a