generic-diff
Safe HaskellSafe-Inferred
LanguageHaskell2010

Generics.Diff.Render

Description

The types in Diff have derived Show instances that don't help at all in one of the goals for the library, which is readability. This module lets us render those types in a friendly way.

Synopsis

Rendering

renderDiffResultWith :: RenderOpts -> DiffResult a -> Builder Source #

Render a DiffResult using a lazy Builder, using custom RenderOpts.

Printing

printDiffResult :: DiffResult a -> IO () Source #

Print a DiffResult to the terminal.

printDiffResultWith :: RenderOpts -> DiffResult a -> IO () Source #

Print a DiffResult to the terminal, using custom RenderOpts.

Options

data RenderOpts Source #

Configuration type used to tweak the output of renderDiffResultWith.

Use defaultRenderOpts and the field accessors below to construct.

Instances

Instances details
Show RenderOpts Source # 
Instance details

Defined in Generics.Diff.Type

defaultRenderOpts :: RenderOpts Source #

Sensible rendering defaults. No numbers, 2-space indentation.

indentSize :: RenderOpts -> Natural Source #

How many spaces to indent each new "level" of comparison.

numberedLevels :: RenderOpts -> Bool Source #

Whether or not to include level numbers in the output.

Helper rendering functions

renderDiffError :: DiffError a -> Builder Source #

Render a DiffError using a lazy Builder.

renderDiffErrorWith :: RenderOpts -> DiffError a -> Builder Source #

Render a DiffError using a lazy Builder, using custom RenderOpts.

Intermediate representation

data Doc Source #

An intermediate representation for diff output.

We constrain output to follow a very simple pattern:

Constructors

Doc 

Instances

Instances details
Show Doc Source # 
Instance details

Defined in Generics.Diff.Type

Methods

showsPrec :: Int -> Doc -> ShowS #

show :: Doc -> String #

showList :: [Doc] -> ShowS #

diffErrorDoc :: forall a. DiffError a -> Doc Source #

Convert a DiffError to a Doc.

renderDoc :: RenderOpts -> Int -> Doc -> Builder Source #

Render a Doc as a text Builder. This should be the only way we escape a Doc.

The output can be configured using RenderOpts.

listDiffErrorDoc :: Builder -> ListDiffError a -> Doc Source #

Convert a ListDiffError to a Doc.

The first argument gives us a name for the type of list, for clearer output. For example:

ghci> putStrLn . toLazyText . renderDoc defaultRenderOpts 0 . listDiffErrorDoc "list" $ DiffAtIndex 3 TopLevelNotEqual
Diff at list index 3 (0-indexed)
  Not equal

ghci> TL.putStrLn . TB.toLazyText . renderDoc defaultRenderOpts 0 . listDiffErrorDoc "non-empty list" $ WrongLengths 3 5
non-empty lists are wrong lengths
Length of left list: 3
Length of right list: 5

diffErrorNestedDoc :: DiffErrorNested xss -> Doc Source #

Convert a DiffErrorNested to a Doc.

This is exported in the case that we want to implement an instance of Diff for an existing type (e.g. from a 3rd-party library) that does not have a Generic instance.

showB :: Show a => a -> Builder Source #

show a value as a Builder.

linesDoc :: NonEmpty Builder -> Doc Source #

Create a simple Doc without a nested error.

makeDoc :: NonEmpty Builder -> DiffError a -> Doc Source #

Create a Doc with a non-empty list of lines and a nested error.