Copyright | (c) Mesabloo 2021-2022 |
---|---|
License | BSD3 |
Stability | experimental |
Portability | Portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Annotation
- type Style = Doc Annotation -> Doc AnsiStyle
- defaultStyle :: Style
- reAnnotate :: (ann -> ann') -> Doc ann -> Doc ann'
Defining new style
data Annotation Source #
Some annotations as placeholders for colors in a Doc
.
ThisColor Bool | The color of |
MaybeColor | The color of |
WhereColor | The color of |
HintColor | The color for hints. Note that the beginning |
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 |
NoLineColor | The color in which to output the |
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 Doc
ument containing Annotation
s into a Doc
ument containing
color information.
Defining new color styles (one may call them "themes") is actually rather easy.
A Style
is a function from an annotated Doc
ument to another annotated Doc
ument.
Note that only the annotation type changes, hence the need of only providing a unidirectional mapping between those.
Annotation
s are used when creating a Doc
ument and are simply placeholders to specify custom colors.
AnsiStyle
is the concrete annotation to specify custom colors when rendering a Doc
ument.
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 warningsWhere
markers are colored in dull blueMaybe
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 Doc
ument.
Useful in particular to embed documents with one form of annotation in a more generally annotated document.
Since this traverses the entire
tree, including parts that are not
rendered due to other layouts fitting better, it is preferrable to reannotate
after producing the layout by using Doc
.reAnnotateS
Since
has the right type and satisfies reAnnotate
'reAnnotate id = id'
,
it is used to define the
instance of Functor
.Doc