pub struct Renderer { /* private fields */ }Expand description
The caller is expected to detect any relevant terminal features and configure the renderer, including
- ANSI Escape code support (always outputted with
Renderer::styled) - Terminal width (
Renderer::term_width) - Unicode support (
Renderer::decor_style)
§Example
let report = // ...
let renderer = Renderer::styled();
let output = renderer.render(report);
anstream::println!("{output}");Implementations§
Source§impl Renderer
impl Renderer
Sourcepub const fn styled() -> Self
pub const fn styled() -> Self
Default terminal styling
If ANSI escape codes are not supported, either
- Call
Renderer::plaininstead - Strip them after the fact, like with
anstream
§Note
When testing styled terminal output, see the testing-colors feature
Sourcepub const fn no_graphics(self, no_graphics: bool) -> Self
pub const fn no_graphics(self, no_graphics: bool) -> Self
Render a Report without source snippets or graphical decorations
The output is primarily designed for Text-To-Speech and Braille
displays. It also provides a more detailed alternative to
Renderer::short_message.
We recommend that applications enable this format when NO_GRAPHICS=1
is set in the environment.
This format supports colors and hyperlinks.
Renderer::plain can be used to disable colors and hyperlinks.
§Example output
error E0308: mismatched types
at $DIR/bad-hex-float-lit.rs:2:19: expected `f32`, found integer
on line 2, column 13: expected due to this
help: rewrite this as a decimal floating point literal, or use `as` to turn a hex literal into a float
option 1
on line 2, column 19 to column 27 replace with: 0xAB as f32
option 2
on line 2, column 19 to column 27 replace with: 171_f32Sourcepub const fn short_message(self, short_message: bool) -> Self
pub const fn short_message(self, short_message: bool) -> Self
Abbreviate the message
Sourcepub const fn term_width(self, term_width: usize) -> Self
pub const fn term_width(self, term_width: usize) -> Self
Set the width to render within
Affects the rendering of Snippets
Sourcepub const fn decor_style(self, decor_style: DecorStyle) -> Self
pub const fn decor_style(self, decor_style: DecorStyle) -> Self
Set the character set used for rendering decor
Sourcepub const fn anonymized_snippet_line_numbers(self, yes: bool) -> Self
pub const fn anonymized_snippet_line_numbers(self, yes: bool) -> Self
Anonymize snippet line numbers
When enabled, line numbers are replaced with LL which is useful for tests.
§Example
--> $DIR/whitespace-trimming.rs:4:193
|
LL | ... let _: () = 42;
| ^^ expected (), found integer
|Sourcepub const fn anonymized_line_numbers(self, yes: bool) -> Self
👎Deprecated since 0.12.17: replaced with Renderer::anonymized_snippet_line_numbers
pub const fn anonymized_line_numbers(self, yes: bool) -> Self
replaced with Renderer::anonymized_snippet_line_numbers
Deprecated, replaced with Self::anonymized_snippet_line_numbers
Sourcepub const fn anonymized_origin_line_numbers(self, yes: bool) -> Self
pub const fn anonymized_origin_line_numbers(self, yes: bool) -> Self
Anonymize origin line numbers
When enabled, line numbers are replaced with LL which is useful for tests.
§Example
--> $DIR/whitespace-trimming.rs:LL:193
|
4 | ... let _: () = 42;
| ^^ expected (), found integer
|Source§impl Renderer
Customize Renderer::styled
impl Renderer
Customize Renderer::styled
Sourcepub const fn line_num(self, style: Style) -> Self
pub const fn line_num(self, style: Style) -> Self
Override the output style for line numbers in the Snippet gutter
Sourcepub const fn emphasis(self, style: Style) -> Self
pub const fn emphasis(self, style: Style) -> Self
Override the output style for emphasis for the
primary_title
Sourcepub const fn context(self, style: Style) -> Self
pub const fn context(self, style: Style) -> Self
Override the output style for AnnotationKind::Context