Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
pretty_diagnostics::TextRenderer Class Referencefinal

A plain-text renderer for diagnostic Reports. More...

#include <renderer.hpp>

Inheritance diagram for pretty_diagnostics::TextRenderer:
[legend]

Public Member Functions

 TextRenderer (const Report &report)
 Initializes the renderer with a reference layout taken from a Report More...
 
void render (const Severity &severity, std::ostream &stream) override
 Renders just the severity label to the stream. More...
 
void render (const Report &report, std::ostream &stream) override
 Renders an entire report to the stream. More...
 
void render (const FileGroup &file_group, std::ostream &stream) override
 Renders a single file group to the stream. More...
 
void render (const LineGroup &line_group, std::ostream &stream) override
 Renders a single line group to the stream. More...
 
- Public Member Functions inherited from pretty_diagnostics::IReporterRenderer
virtual ~IReporterRenderer ()=default
 
virtual void render (const Severity &severity, std::ostream &stream)=0
 Renders just the severity label (e.g. "error", "warning") More...
 
virtual void render (const Report &report, std::ostream &stream)=0
 Renders an entire report. More...
 
virtual void render (const FileGroup &file_group, std::ostream &stream)=0
 Renders a single file group. More...
 
virtual void render (const LineGroup &line_group, std::ostream &stream)=0
 Renders a single line group. More...
 

Static Public Member Functions

static size_t render (const Label &label, std::ostream &stream, const std::vector< std::string > &text_lines, size_t text_index, bool active_render, size_t column_start=0)
 Renders an individual label, optionally in active mode to draw the actual span arrows. More...
 
static size_t widest_line_number (const Report::MappedFileGroups &groups, size_t padding)
 Computes the width of the widest line number across groups, plus padding. More...
 
static std::vector< std::string > wrap_text (const std::string &text, size_t max_width)
 Wraps the given text to lines no longer than max_width characters. More...
 

Detailed Description

A plain-text renderer for diagnostic Reports.

Produces a clean, human-friendly multi-line output similar to compilers

Constructor & Destructor Documentation

◆ TextRenderer()

pretty_diagnostics::TextRenderer::TextRenderer ( const Report report)
explicit

Initializes the renderer with a reference layout taken from a Report

Parameters
reportReport instance used to derive initial layout parameters

Member Function Documentation

◆ render() [1/5]

void pretty_diagnostics::TextRenderer::render ( const FileGroup file_group,
std::ostream &  stream 
)
overridevirtual

Renders a single file group to the stream.

Parameters
file_groupFile group to render
streamOutput stream to write to

Implements pretty_diagnostics::IReporterRenderer.

◆ render() [2/5]

static size_t pretty_diagnostics::TextRenderer::render ( const Label label,
std::ostream &  stream,
const std::vector< std::string > &  text_lines,
size_t  text_index,
bool  active_render,
size_t  column_start = 0 
)
static

Renders an individual label, optionally in active mode to draw the actual span arrows.

Parameters
labelLabel to render
streamOutput stream to write to
text_linesPre-wrapped lines of the label text
text_indexIndex into text_lines to start rendering from
active_renderWhether to draw guides/arrows for the label
column_startOptional starting column for rendering (0-based)
Returns
Next text index to continue rendering wrapped text

◆ render() [3/5]

void pretty_diagnostics::TextRenderer::render ( const LineGroup line_group,
std::ostream &  stream 
)
overridevirtual

Renders a single line group to the stream.

Parameters
line_groupLine group to render
streamOutput stream to write to

Implements pretty_diagnostics::IReporterRenderer.

◆ render() [4/5]

void pretty_diagnostics::TextRenderer::render ( const Report report,
std::ostream &  stream 
)
overridevirtual

Renders an entire report to the stream.

Parameters
reportReport to be rendered
streamOutput stream to write to

Implements pretty_diagnostics::IReporterRenderer.

◆ render() [5/5]

void pretty_diagnostics::TextRenderer::render ( const Severity severity,
std::ostream &  stream 
)
overridevirtual

Renders just the severity label to the stream.

Parameters
severitySeverity to render (e.g., error, warning)
streamOutput stream to write to

Implements pretty_diagnostics::IReporterRenderer.

◆ widest_line_number()

static size_t pretty_diagnostics::TextRenderer::widest_line_number ( const Report::MappedFileGroups groups,
size_t  padding 
)
static

Computes the width of the widest line number across groups, plus padding.

Parameters
groupsMapped file groups used for rendering
paddingExtra characters to add to the computed width
Returns
Total width for the line-number column

◆ wrap_text()

static std::vector< std::string > pretty_diagnostics::TextRenderer::wrap_text ( const std::string &  text,
size_t  max_width 
)
static

Wraps the given text to lines no longer than max_width characters.

Parameters
textText to wrap
max_widthMaximum line width
Returns
Wrapped text as a vector of lines

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