Hook implementation that colours the message elements produced by
print_message_lines/3. Handled elements are:
- ansi(Class, Fmt, Args)
- ansi(Class, Fmt, Args, Ctx)
- Write Fmt/Args using the attributes of Class. As the element
ends with a full reset, the 4th argument version re-installs
the decoration of the message as a whole afterwards.
- url(Location)
- url(URL, Label)
- Write a hyperlink. See ansi_hyperlink/2,3. Label is an atom or
string, a Format-Args pair or an ansi/3 or ansi/4 term. The
latter combines a hyperlink with a style class.
- begin(Class, Ctx)
- end(Ctx)
- Decorate the message as a whole. See below.
- nl(Ctx),flush(Ctx)
- End a line. If the message has a background colour, the
remainder of the line is painted using `\e[K` (Erase in Line)
such that the coloured block extends to the right margin.
- eol(Ctx)
- As above, but also reset the attributes: this ends the decorated
part of the line. A message uses this for its last line if that
line is not ended using
nl. Resetting matters because a
terminal that scrolls while a background colour is in effect
paints the newly exposed line with it.
Ctx is the message context. It is created by the handler for
begin/2 as a term
ansi(Reset, ReInstall, EraseEol)
where Reset is the sequence written by end/1, ReInstall is a
Format-Args pair that re-installs the attributes of the message and
EraseEol is the sequence that paints the remainder of the line or
the empty atom. Callers must treat Ctx as opaque. It is left
unbound if Stream is not a terminal, if the color_term flag is
false or if the message has no attributes. All handlers that use
Ctx therefore fail if it is unbound, which makes
print_message_lines/3 fall back to writing plain text.