futhark-0.25.27: An optimising compiler for a functional, array-oriented language.

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.Util.Pretty

Contents

- Rendering to texts
- Rendering to terminal
- Building blocks
- Operators
- Orphan instances

Description

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

Synopsis

- prettyTuple :: Pretty a => [a] -> Text
- prettyTupleLines :: Pretty a => [a] -> Text
- prettyString :: Pretty a => a -> String
- prettyStringOneLine :: Pretty a => a -> String
- prettyText :: Pretty a => a -> Text
- prettyTextOneLine :: Pretty a => a -> Text
- docText :: Doc a -> Text
- docTextForHandle :: Handle -> Doc AnsiStyle -> IO Text
- docString :: Doc a -> String
- putDoc :: Doc AnsiStyle -> IO ()
- hPutDoc :: Handle -> Doc AnsiStyle -> IO ()
- putDocLn :: Doc AnsiStyle -> IO ()
- hPutDocLn :: Handle -> Doc AnsiStyle -> IO ()
- module Prettyprinter
- module Prettyprinter.Symbols.Ascii
- data Color
  - = Black
  - | Red
  - | Green
  - | Yellow
  - | Blue
  - | Magenta
  - | Cyan
  - | White
- data AnsiStyle
- bold :: AnsiStyle
- color :: Color -> AnsiStyle
- bgColor :: Color -> AnsiStyle
- colorDull :: Color -> AnsiStyle
- bgColorDull :: Color -> AnsiStyle
- italicized :: AnsiStyle
- underlined :: AnsiStyle
- apply :: [Doc a] -> Doc a
- oneLine :: Doc a -> Doc a
- annot :: [Doc a] -> Doc a -> Doc a
- nestedBlock :: Doc a -> Doc a -> Doc a -> Doc a
- textwrap :: Text -> Doc a
- shorten :: Doc a -> Doc b
- commastack :: [Doc a] -> Doc a
- commasep :: [Doc a] -> Doc a
- semistack :: [Doc a] -> Doc a
- stack :: [Doc a] -> Doc a
- parensIf :: Bool -> Doc a -> Doc a
- ppTuple' :: [Doc a] -> Doc a
- ppTupleLines' :: [Doc a] -> Doc a
- (</>) :: Doc a -> Doc a -> Doc a

# 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

module Prettyprinter

module Prettyprinter.Symbols.Ascii

data Color Source #

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 Source # show :: Color -> String Source # showList :: [Color] -> ShowS Source #
Eq Color |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods (==) :: Color -> Color -> Bool Source # (/=) :: Color -> Color -> Bool Source #
Ord Color |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods compare :: Color -> Color -> Ordering Source # (<) :: Color -> Color -> Bool Source # (<=) :: Color -> Color -> Bool Source # (>) :: Color -> Color -> Bool Source # (>=) :: Color -> Color -> Bool Source # max :: Color -> Color -> Color Source # min :: Color -> Color -> Color Source #

data AnsiStyle Source #

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

IsString Fmt Source # |
Instance details Defined in Futhark.Fmt.Monad Methods fromString :: String -> Fmt Source #
Monoid Fmt Source # |
Instance details Defined in Futhark.Fmt.Monad Methods mempty :: Fmt Source # mappend :: Fmt -> Fmt -> Fmt Source # mconcat :: [Fmt] -> Fmt Source #
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 Methods mempty :: AnsiStyle Source # mappend :: AnsiStyle -> AnsiStyle -> AnsiStyle Source # mconcat :: [AnsiStyle] -> AnsiStyle Source #
Semigroup Fmt Source # |
Instance details Defined in Futhark.Fmt.Monad Methods (<>) :: Fmt -> Fmt -> Fmt Source # sconcat :: NonEmpty Fmt -> Fmt Source # stimes :: Integral b => b -> Fmt -> Fmt Source #

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 Methods (<>) :: AnsiStyle -> AnsiStyle -> AnsiStyle Source # sconcat :: NonEmpty AnsiStyle -> AnsiStyle Source # stimes :: Integral b => b -> AnsiStyle -> AnsiStyle Source #
Show AnsiStyle |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods showsPrec :: Int -> AnsiStyle -> ShowS Source # show :: AnsiStyle -> String Source # showList :: [AnsiStyle] -> ShowS Source #
Eq AnsiStyle |
Instance details Defined in Prettyprinter.Render.Terminal.Internal Methods (==) :: AnsiStyle -> AnsiStyle -> Bool Source # (/=) :: AnsiStyle -> AnsiStyle -> Bool Source #
Ord AnsiStyle |

Instance details

Defined in Prettyprinter.Render.Terminal.Internal

Methods

compare :: AnsiStyle -> AnsiStyle -> Ordering Source #

(<) :: AnsiStyle -> AnsiStyle -> Bool Source #

(<=) :: AnsiStyle -> AnsiStyle -> Bool Source #

(>) :: AnsiStyle -> AnsiStyle -> Bool Source #

(>=) :: AnsiStyle -> AnsiStyle -> Bool Source #

max :: AnsiStyle -> AnsiStyle -> AnsiStyle Source #

min :: AnsiStyle -> AnsiStyle -> AnsiStyle Source #

bold :: AnsiStyle Source #

Render in bold.

color :: Color -> AnsiStyle Source #

Style the foreground with a vivid color.

bgColor :: Color -> AnsiStyle Source #

Style the background with a vivid color.

colorDull :: Color -> AnsiStyle Source #

Style the foreground with a dull color.

bgColorDull :: Color -> AnsiStyle Source #

Style the background with a dull color.

italicized :: AnsiStyle Source #

Render in italics.

underlined :: AnsiStyle Source #

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 `Doc`s 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 #

ppTupleLines' :: [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 Source # prettyList :: [Half] -> Doc ann Source #