diagnose-2.3.0: Beautiful error reporting done easily
Copyright(c) Mesabloo 2021-2022
LicenseBSD3
Stabilityexperimental
PortabilityPortable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Error.Diagnose.Style

Description

 
Synopsis

Defining new style

data Annotation Source #

Some annotations as placeholders for colors in a Doc.

Constructors

ThisColor Bool

The color of This markers, depending on whether the report is an error report or a warning report.

MaybeColor

The color of Maybe markers.

WhereColor

The color of Where markers.

HintColor

The color for hints.

Note that the beginning Hint: text will always be in bold.

FileColor

The color for file names.

RuleColor

The color of the rule separating the code/markers from the line numbers.

KindColor Bool

The color of the [error]/[warning] at the top, depending on whether this is an error or warning report.

NoLineColor

The color in which to output the line information when the file was not found.

MarkerStyle Annotation

Additional style to apply to marker rules (e.g. bold) on top of some already processed color annotation.

CodeStyle

The color of the code when no marker is present.

type Style = Doc Annotation -> Doc AnsiStyle Source #

A style is a function which can be applied using reAnnotate.

It transforms a Document containing Annotations into a Document containing color information.

Defining new color styles (one may call them "themes") is actually rather easy.

A Style is a function from an annotated Document to another annotated Document. Note that only the annotation type changes, hence the need of only providing a unidirectional mapping between those.

Annotations are used when creating a Document and are simply placeholders to specify custom colors. AnsiStyle is the concrete annotation to specify custom colors when rendering a Document.

One may define additional styles as follows:

myNewCustomStyle :: Style
myNewCustomStyle = reAnnotate \case
  -- all cases for all annotations

For simplicity's sake, a default style is given as defaultStyle.

Default style specification

defaultStyle :: Style Source #

The default style for diagnostics, where:

  • This markers are colored in red for errors and yellow for warnings
  • Where markers are colored in dull blue
  • Maybe markers are colored in magenta
  • Marker rules are of the same color of the marker, but also in bold
  • Hints are output in cyan
  • The left rules are colored in bold black
  • File names are output in dull green
  • The [error]/[warning] at the top is colored in red for errors and yellow for warnings
  • The code is output in normal white

Re-exports

reAnnotate :: (ann -> ann') -> Doc ann -> Doc ann' #

Change the annotation of a Document.

Useful in particular to embed documents with one form of annotation in a more generally annotated document.

Since this traverses the entire Doc tree, including parts that are not rendered due to other layouts fitting better, it is preferrable to reannotate after producing the layout by using reAnnotateS.

Since reAnnotate has the right type and satisfies 'reAnnotate id = id', it is used to define the Functor instance of Doc.