futhark-0.25.19: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageGHC2021

Futhark.Util.Pretty

Description

A re-export of the prettyprinting library, along with some convenience functions.

Synopsis

Rendering to texts

prettyTuple :: Pretty a => [a] -> Text Source #

Prettyprint a list enclosed in curly braces.

prettyTupleLines :: Pretty a => [a] -> Text Source #

Like prettyTuple, but put a linebreak after every element.

prettyString :: Pretty a => a -> String Source #

Prettyprint a value to a String, appropriately wrapped.

prettyStringOneLine :: Pretty a => a -> String Source #

Prettyprint a value to a String on a single line.

prettyText :: Pretty a => a -> Text Source #

Prettyprint a value to a Text, appropriately wrapped.

prettyTextOneLine :: Pretty a => a -> Text Source #

Prettyprint a value to a Text on a single line.

docText :: Doc a -> Text Source #

Convert a Doc to text. This ignores any annotations (i.e. it will be non-coloured output).

docTextForHandle :: Handle -> Doc AnsiStyle -> IO Text Source #

Produce text suitable for printing on the given handle. This mostly means stripping any control characters if the handle is not a terminal.

docString :: Doc a -> String Source #

Convert a Doc to a String, through docText. Intended for debugging.

Rendering to terminal

putDoc :: Doc AnsiStyle -> IO () Source #

Like hPutDoc, but to stdout.

hPutDoc :: Handle -> Doc AnsiStyle -> IO () Source #

Print a doc with styling to the given file; stripping colors if the file does not seem to support such things.

putDocLn :: Doc AnsiStyle -> IO () Source #

Like putDoc, but with a final newline.

hPutDocLn :: Handle -> Doc AnsiStyle -> IO () Source #

Like hPutDoc, but with a final newline.

Building blocks

data Color #

The 8 ANSI terminal colors.

Constructors

Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Instances

Instances details
Show Color 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

Ord Color 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Methods

compare :: Color -> Color -> Ordering #

(<) :: Color -> Color -> Bool #

(<=) :: Color -> Color -> Bool #

(>) :: Color -> Color -> Bool #

(>=) :: Color -> Color -> Bool #

max :: Color -> Color -> Color #

min :: Color -> Color -> Color #

data AnsiStyle #

Render the annotated document in a certain style. Styles not set in the annotation will use the style of the surrounding document, or the terminal’s default if none has been set yet.

style = color Green <> bold
styledDoc = annotate style "hello world"

Instances

Instances details
Monoid AnsiStyle

mempty does nothing, which is equivalent to inheriting the style of the surrounding doc, or the terminal’s default if no style has been set yet.

Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Semigroup AnsiStyle

Keep the first decision for each of foreground color, background color, boldness, italication, and underlining. If a certain style is not set, the terminal’s default will be used.

Example:

color Red <> color Green

is red because the first color wins, and not bold because (or if) that’s the terminal’s default.

Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Show AnsiStyle 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Eq AnsiStyle 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Ord AnsiStyle 
Instance details

Defined in Prettyprinter.Render.Terminal.Internal

bold :: AnsiStyle #

Render in bold.

color :: Color -> AnsiStyle #

Style the foreground with a vivid color.

bgColor :: Color -> AnsiStyle #

Style the background with a vivid color.

colorDull :: Color -> AnsiStyle #

Style the foreground with a dull color.

bgColorDull :: Color -> AnsiStyle #

Style the background with a dull color.

italicized :: AnsiStyle #

Render in italics.

underlined :: AnsiStyle #

Render underlined.

apply :: [Doc a] -> Doc a Source #

The document apply ds separates ds with commas and encloses them with parentheses.

oneLine :: Doc a -> Doc a Source #

Make sure that the given document is printed on just a single line.

annot :: [Doc a] -> Doc a -> Doc a Source #

Stack and prepend a list of Docs to another Doc, separated by a linebreak. If the list is empty, the second Doc will be returned without a preceding linebreak.

nestedBlock :: Doc a -> Doc a -> Doc a -> Doc a Source #

Surround the given document with enclosers and add linebreaks and indents.

textwrap :: Text -> Doc a Source #

Splits the string into words and permits line breaks between all of them.

shorten :: Doc a -> Doc b Source #

Prettyprint on a single line up to at most some appropriate number of characters, with trailing ... if necessary. Used for error messages.

commastack :: [Doc a] -> Doc a Source #

Like commasep, but a newline after every comma.

commasep :: [Doc a] -> Doc a Source #

Separate with commas.

semistack :: [Doc a] -> Doc a Source #

Separate with semicolons and newlines.

stack :: [Doc a] -> Doc a Source #

Separate with linebreaks.

parensIf :: Bool -> Doc a -> Doc a Source #

The document parensIf p d encloses the document d in parenthesis if p is True, and otherwise yields just d.

ppTuple' :: [Doc a] -> Doc a Source #

Operators

(</>) :: Doc a -> Doc a -> Doc a Source #

Orphan instances

Pretty Half Source # 
Instance details

Methods

pretty :: Half -> Doc ann #

prettyList :: [Half] -> Doc ann #