mirror of https://github.com/zkat/miette.git
Add tags.
This commit is contained in:
parent
597458ff9c
commit
fb045a2d9c
|
|
@ -25,9 +25,6 @@ impl Default for RgbColors {
|
|||
}
|
||||
}
|
||||
|
||||
/// Function to format a message before rendering.
|
||||
pub type MessageFormatter = dyn Fn(String) -> String;
|
||||
|
||||
/**
|
||||
Create a custom [`MietteHandler`] from options.
|
||||
|
||||
|
|
@ -58,7 +55,6 @@ pub struct MietteHandlerOpts {
|
|||
pub(crate) context_lines: Option<usize>,
|
||||
pub(crate) tab_width: Option<usize>,
|
||||
pub(crate) with_cause_chain: Option<bool>,
|
||||
pub(crate) message_formatter: Option<Box<MessageFormatter>>,
|
||||
}
|
||||
|
||||
impl MietteHandlerOpts {
|
||||
|
|
@ -168,11 +164,6 @@ impl MietteHandlerOpts {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn message_formatter<F: MessageFormatter>(mut self, formatter: F) -> Self {
|
||||
self.message_formatter = Some(Box::new(formatter));
|
||||
self
|
||||
}
|
||||
|
||||
/// Builds a [`MietteHandler`] from this builder.
|
||||
pub fn build(self) -> MietteHandler {
|
||||
let graphical = self.is_graphical();
|
||||
|
|
@ -221,7 +212,11 @@ impl MietteHandlerOpts {
|
|||
} else {
|
||||
ThemeStyles::none()
|
||||
};
|
||||
let theme = self.theme.unwrap_or(GraphicalTheme { characters, styles });
|
||||
let theme = self.theme.unwrap_or(GraphicalTheme {
|
||||
characters,
|
||||
styles,
|
||||
tags: std::collections::HashMap::new(),
|
||||
});
|
||||
let mut handler = GraphicalReportHandler::new()
|
||||
.with_width(width)
|
||||
.with_links(linkify)
|
||||
|
|
@ -242,9 +237,6 @@ impl MietteHandlerOpts {
|
|||
if let Some(w) = self.tab_width {
|
||||
handler = handler.tab_width(w);
|
||||
}
|
||||
if let Some(formatter) = self.message_formatter {
|
||||
handler = handler.with_message_formatter(formatter);
|
||||
}
|
||||
MietteHandler {
|
||||
inner: Box::new(handler),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,7 @@ use unicode_width::UnicodeWidthChar;
|
|||
use crate::diagnostic_chain::DiagnosticChain;
|
||||
use crate::handlers::theme::*;
|
||||
use crate::protocol::{Diagnostic, Severity};
|
||||
use crate::{
|
||||
LabeledSpan, MessageFormatter, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents,
|
||||
};
|
||||
use crate::{LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents};
|
||||
|
||||
/**
|
||||
A [`ReportHandler`] that displays a given [`Report`](crate::Report) in a
|
||||
|
|
@ -32,7 +30,6 @@ pub struct GraphicalReportHandler {
|
|||
pub(crate) context_lines: usize,
|
||||
pub(crate) tab_width: usize,
|
||||
pub(crate) with_cause_chain: bool,
|
||||
pub(crate) message_formatter: Option<Box<MessageFormatter>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
|
@ -54,7 +51,6 @@ impl GraphicalReportHandler {
|
|||
context_lines: 1,
|
||||
tab_width: 4,
|
||||
with_cause_chain: true,
|
||||
message_formatter: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +64,6 @@ impl GraphicalReportHandler {
|
|||
context_lines: 1,
|
||||
tab_width: 4,
|
||||
with_cause_chain: true,
|
||||
message_formatter: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,11 +133,6 @@ impl GraphicalReportHandler {
|
|||
self.context_lines = lines;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_message_formatter<F: MessageFormatter>(mut self, formatter: F) -> Self {
|
||||
self.message_formatter = Some(Box::new(formatter));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GraphicalReportHandler {
|
||||
|
|
@ -226,9 +216,6 @@ impl GraphicalReportHandler {
|
|||
.subsequent_indent(&rest_indent);
|
||||
let mut message = diagnostic.to_string();
|
||||
|
||||
if let Some(formatter) = self.message_formatter {
|
||||
message = formatter(message);
|
||||
}
|
||||
|
||||
writeln!(f, "{}", textwrap::fill(&message, opts))?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use is_terminal::IsTerminal;
|
||||
use owo_colors::Style;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/**
|
||||
Theme used by [`GraphicalReportHandler`](crate::GraphicalReportHandler) to
|
||||
|
|
@ -18,6 +19,8 @@ pub struct GraphicalTheme {
|
|||
pub characters: ThemeCharacters,
|
||||
/// Styles to be used for painting.
|
||||
pub styles: ThemeStyles,
|
||||
/// Tags to be used for styling.
|
||||
pub tags: HashMap<String, Style>,
|
||||
}
|
||||
|
||||
impl GraphicalTheme {
|
||||
|
|
@ -26,6 +29,7 @@ impl GraphicalTheme {
|
|||
Self {
|
||||
characters: ThemeCharacters::ascii(),
|
||||
styles: ThemeStyles::ansi(),
|
||||
tags: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +45,7 @@ impl GraphicalTheme {
|
|||
Self {
|
||||
characters: ThemeCharacters::unicode(),
|
||||
styles: ThemeStyles::ansi(),
|
||||
tags: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +55,7 @@ impl GraphicalTheme {
|
|||
Self {
|
||||
characters: ThemeCharacters::unicode(),
|
||||
styles: ThemeStyles::none(),
|
||||
tags: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,6 +68,7 @@ impl GraphicalTheme {
|
|||
Self {
|
||||
characters: ThemeCharacters::ascii(),
|
||||
styles: ThemeStyles::none(),
|
||||
tags: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue