Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Generics.Diff.Render
Description
Synopsis
- renderDiffResult :: DiffResult a -> Builder
- renderDiffResultWith :: RenderOpts -> DiffResult a -> Builder
- printDiffResult :: DiffResult a -> IO ()
- printDiffResultWith :: RenderOpts -> DiffResult a -> IO ()
- data RenderOpts
- defaultRenderOpts :: RenderOpts
- indentSize :: RenderOpts -> Natural
- numberedLevels :: RenderOpts -> Bool
- renderDiffError :: DiffError a -> Builder
- renderDiffErrorWith :: RenderOpts -> DiffError a -> Builder
- renderDiffErrorNested :: DiffErrorNested xss -> Builder
- renderDiffErrorNestedWith :: RenderOpts -> DiffErrorNested xss -> Builder
- data Doc = Doc {}
- diffErrorDoc :: forall a. DiffError a -> Doc
- renderDoc :: RenderOpts -> Int -> Doc -> Builder
- listDiffErrorDoc :: Builder -> ListDiffError a -> Doc
- diffErrorNestedDoc :: DiffErrorNested xss -> Doc
- showB :: Show a => a -> Builder
- linesDoc :: NonEmpty Builder -> Doc
- makeDoc :: NonEmpty Builder -> DiffError a -> Doc
Rendering
renderDiffResult :: DiffResult a -> Builder Source #
Render a DiffResult
using a lazy Builder
.
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
Show RenderOpts Source # | |
Defined in Generics.Diff.Type Methods showsPrec :: Int -> RenderOpts -> ShowS # show :: RenderOpts -> String # showList :: [RenderOpts] -> ShowS # |
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
renderDiffErrorWith :: RenderOpts -> DiffError a -> Builder Source #
Render a DiffError
using a lazy Builder
, using custom RenderOpts
.
renderDiffErrorNested :: DiffErrorNested xss -> Builder Source #
Render a DiffErrorNested
using a lazy Builder
.
renderDiffErrorNestedWith :: RenderOpts -> DiffErrorNested xss -> Builder Source #
Render a DiffErrorNested
using a lazy Builder
, using custom RenderOpts
.
Intermediate representation
An intermediate representation for diff output.
We constrain output to follow a very simple pattern:
docLines
is a non-empty series of preliminary lines describing the error.docSubDoc
is an optionalDoc
representing a nested error, e.g. inFieldMismatch
.
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
3TopLevelNotEqual
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.