Struct Renderer
pub struct Renderer { /* private fields */ }Expand description
The Renderer for a [Report]
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§
§impl Renderer
impl Renderer
pub const fn styled() -> Renderer
pub const fn styled() -> Renderer
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
pub const fn short_message(self, short_message: bool) -> Renderer
pub const fn short_message(self, short_message: bool) -> Renderer
Abbreviate the message
pub const fn term_width(self, term_width: usize) -> Renderer
pub const fn term_width(self, term_width: usize) -> Renderer
Set the width to render within
Affects the rendering of [Snippet][crate::Snippet]s
pub const fn decor_style(self, decor_style: DecorStyle) -> Renderer
pub const fn decor_style(self, decor_style: DecorStyle) -> Renderer
Set the character set used for rendering decor
pub const fn anonymized_line_numbers(
self,
anonymized_line_numbers: bool,
) -> Renderer
pub const fn anonymized_line_numbers( self, anonymized_line_numbers: bool, ) -> Renderer
Anonymize 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
|§impl Renderer
Customize Renderer::styled
impl Renderer
Customize Renderer::styled
pub const fn error(self, style: Style) -> Renderer
pub const fn error(self, style: Style) -> Renderer
Override the output style for [error][crate::Level::ERROR]
pub const fn warning(self, style: Style) -> Renderer
pub const fn warning(self, style: Style) -> Renderer
Override the output style for [warnings][crate::Level::WARNING]
pub const fn info(self, style: Style) -> Renderer
pub const fn info(self, style: Style) -> Renderer
Override the output style for [info][crate::Level::INFO]
pub const fn note(self, style: Style) -> Renderer
pub const fn note(self, style: Style) -> Renderer
Override the output style for [notes][crate::Level::NOTE]
pub const fn help(self, style: Style) -> Renderer
pub const fn help(self, style: Style) -> Renderer
Override the output style for [help][crate::Level::HELP]
pub const fn line_num(self, style: Style) -> Renderer
pub const fn line_num(self, style: Style) -> Renderer
Override the output style for line numbers in the [Snippet][crate::Snippet] gutter
pub const fn emphasis(self, style: Style) -> Renderer
pub const fn emphasis(self, style: Style) -> Renderer
Override the output style for emphasis for the
[primary_title][crate::Level::primary_title]
pub const fn context(self, style: Style) -> Renderer
pub const fn context(self, style: Style) -> Renderer
Override the output style for [AnnotationKind::Context][crate::AnnotationKind::Context]
pub const fn addition(self, style: Style) -> Renderer
pub const fn addition(self, style: Style) -> Renderer
Override the output style for [Patch][crate::Patch] additions