Porytiles
Loading...
Searching...
No Matches
porytiles::StderrStyledUserDiagnostics Class Referencefinal

Concrete implementation of UserDiagnostics that outputs structured messages to stderr, optionally with colored formatting. More...

#include <stderr_styled_user_diagnostics.hpp>

Inheritance diagram for porytiles::StderrStyledUserDiagnostics:
[legend]
Collaboration diagram for porytiles::StderrStyledUserDiagnostics:
[legend]

Public Member Functions

 StderrStyledUserDiagnostics (const gsl::not_null< TextFormatter * > format, const std::size_t wrap_width=0)
 Constructs the printer, optionally enabling auto-wrap at wrap_width columns.
 
void remark (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged informational remark to stderr.
 
void warning (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged warning to stderr.
 
void error (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged error message to stderr.
 
void emit_fatal_proximate (const Error &err) const override
 Emit the proximate (immediate) error in a fatal error chain to stderr.
 
void emit_fatal_step (const Error &err) const override
 Emit an intermediate step error in a fatal error chain to stderr.
 
void emit_fatal_root (const Error &err) const override
 Emit the root cause error in a fatal error chain to stderr.
 
void remark_note (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged note associated with a remark to stderr.
 
void warning_note (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged note associated with a warning to stderr.
 
void error_note (const std::string &tag, const std::vector< std::string > &lines) const override
 Display a multi-line tagged note associated with an error to stderr.
 
- Public Member Functions inherited from porytiles::UserDiagnostics
virtual ~UserDiagnostics ()=default
 
 UserDiagnostics (gsl::not_null< const TextFormatter * > format)
 
void remark (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void remark (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted remark messages.
 
void warning (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void warning (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted warning messages.
 
void error (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void error (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted error messages.
 
void remark_note (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void remark_note (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted remark note messages.
 
void warning_note (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void warning_note (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted warning note messages.
 
void error_note (const std::string &tag, const std::string &msg) const
 Convenience overload for single line messages.
 
template<typename FirstParam , typename... RestParams>
requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_constructible_v<FormatParam, FirstParam> && (std::is_constructible_v<FormatParam, RestParams> && ...))
void error_note (const std::string &tag, const std::string &format_str, FirstParam &&first, RestParams &&...rest) const
 Variadic template overload for formatted error note messages.
 
template<typename T , typename E >
void fatal (const ChainableResult< T, E > &result) const
 Display a fatal error with complete error chain visualization.
 
const TextFormatterformatter () const
 

Detailed Description

Concrete implementation of UserDiagnostics that outputs structured messages to stderr, optionally with colored formatting.

StderrStyledUserDiagnostics provides a terminal-based implementation of the UserDiagnostics interface. It outputs all diagnostic messages to stderr with some additional pretty-print structuring. If provided with an AnsiStyledTextFormatter, it will additionally use canonical diagnostic coloring and styling (canonical, i.e. magenta for warnings, red for errors, bolding where appropriate, etc.) via ANSI terminal codes. The implementation includes:

  • Colored Output: Uses ANSI codes for terminal colors (cyan for notes, magenta for warnings, red for errors)
  • Multi-line Support: First line gets the appropriate prefix, subsequent lines are indented with visual guidelines to aid reading
  • Error Chain Visualization: Fatal errors are displayed with tree-like formatting using Unicode box-drawing characters to show error hierarchy
  • Auto-Wrap: Message bodies are wrapped to a configured column width so long lines fit the user's terminal, while any explicit line breaks the caller supplied (each element of the lines vector) are still honored

Definition at line 31 of file stderr_styled_user_diagnostics.hpp.

Constructor & Destructor Documentation

◆ StderrStyledUserDiagnostics()

porytiles::StderrStyledUserDiagnostics::StderrStyledUserDiagnostics ( const gsl::not_null< TextFormatter * >  format,
const std::size_t  wrap_width = 0 
)
inlineexplicit

Constructs the printer, optionally enabling auto-wrap at wrap_width columns.

Parameters
formatThe text formatter used to style output
wrap_widthThe terminal column width to wrap message bodies to; 0 disables wrapping

Definition at line 37 of file stderr_styled_user_diagnostics.hpp.

Member Function Documentation

◆ emit_fatal_proximate()

void porytiles::StderrStyledUserDiagnostics::emit_fatal_proximate ( const Error err) const
overridevirtual

Emit the proximate (immediate) error in a fatal error chain to stderr.

Displays the most immediate error in a fatal error chain with red "fatal:" prefix and the highest visual prominence. This represents the direct cause of the failure.

Parameters
errThe proximate error to display

Implements porytiles::UserDiagnostics.

Definition at line 82 of file stderr_styled_user_diagnostics.cpp.

◆ emit_fatal_root()

void porytiles::StderrStyledUserDiagnostics::emit_fatal_root ( const Error err) const
overridevirtual

Emit the root cause error in a fatal error chain to stderr.

Displays the root cause error in a fatal error chain using tree-like formatting with Unicode box-drawing characters (└ symbols). This represents the original underlying cause of the failure and appears as the final item in the error hierarchy visualization.

Parameters
errThe root cause error to display

Implements porytiles::UserDiagnostics.

Definition at line 105 of file stderr_styled_user_diagnostics.cpp.

◆ emit_fatal_step()

void porytiles::StderrStyledUserDiagnostics::emit_fatal_step ( const Error err) const
overridevirtual

Emit an intermediate step error in a fatal error chain to stderr.

Displays intermediate errors in a fatal error chain using tree-like formatting with Unicode box-drawing characters (├ symbols). These represent the intermediate causes between the proximate and root errors in the failure chain.

Parameters
errThe step error to display

Implements porytiles::UserDiagnostics.

Definition at line 93 of file stderr_styled_user_diagnostics.cpp.

◆ error()

void porytiles::StderrStyledUserDiagnostics::error ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged error message to stderr.

Outputs error messages with red "error:" prefix and tag suffix on the first line, formatted as "error: <message> [<tag>]" with appropriate indentation for subsequent lines.

Parameters
tagCategorization tag for the error
linesVector of strings representing each line of the error

Implements porytiles::UserDiagnostics.

Definition at line 69 of file stderr_styled_user_diagnostics.cpp.

◆ error_note()

void porytiles::StderrStyledUserDiagnostics::error_note ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged note associated with an error to stderr.

Outputs informational messages with cyan "note:" prefix and tag suffix on the first line, formatted as "note: <message> [<tag>]" with appropriate indentation for subsequent lines. Uses identical styling to remark_note and warning_note since notes are informational regardless of parent diagnostic type.

Parameters
tagCategorization tag for the note (should match the parent error's tag)
linesVector of strings representing each line of the note

Implements porytiles::UserDiagnostics.

Definition at line 127 of file stderr_styled_user_diagnostics.cpp.

◆ remark()

void porytiles::StderrStyledUserDiagnostics::remark ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged informational remark to stderr.

Outputs informational messages with blue "remark:" prefix and tag suffix on the first line, formatted as "remark: <message> [<tag>]" with appropriate indentation for subsequent lines.

Parameters
tagCategorization tag for the remark
linesVector of strings representing each line of the remark

Implements porytiles::UserDiagnostics.

Definition at line 42 of file stderr_styled_user_diagnostics.cpp.

◆ remark_note()

void porytiles::StderrStyledUserDiagnostics::remark_note ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged note associated with a remark to stderr.

Outputs informational messages with cyan "note:" prefix and tag suffix on the first line, formatted as "note: <message> [<tag>]" with appropriate indentation for subsequent lines. Uses identical styling to warning_note and error_note since notes are informational regardless of parent diagnostic type.

Parameters
tagCategorization tag for the note (should match the parent remark's tag)
linesVector of strings representing each line of the note

Implements porytiles::UserDiagnostics.

Definition at line 117 of file stderr_styled_user_diagnostics.cpp.

◆ warning()

void porytiles::StderrStyledUserDiagnostics::warning ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged warning to stderr.

Outputs warnings with magenta "warning:" prefix and tag suffix on the first line, formatted as "warning: <message> [<tag>]" with appropriate indentation for subsequent lines.

Parameters
tagCategorization tag for the warning
linesVector of strings representing each line of the warning

Implements porytiles::UserDiagnostics.

Definition at line 55 of file stderr_styled_user_diagnostics.cpp.

◆ warning_note()

void porytiles::StderrStyledUserDiagnostics::warning_note ( const std::string &  tag,
const std::vector< std::string > &  lines 
) const
overridevirtual

Display a multi-line tagged note associated with a warning to stderr.

Outputs informational messages with cyan "note:" prefix and tag suffix on the first line, formatted as "note: <message> [<tag>]" with appropriate indentation for subsequent lines. Uses identical styling to remark_note and error_note since notes are informational regardless of parent diagnostic type.

Parameters
tagCategorization tag for the note (should match the parent warning's tag)
linesVector of strings representing each line of the note

Implements porytiles::UserDiagnostics.

Definition at line 122 of file stderr_styled_user_diagnostics.cpp.


The documentation for this class was generated from the following files: